|
I have opened a file and have a handel . Now how can i get file name back from that handel?
API GetFileInformationByHandle() returns lot of things but not file name...is there any other API that can help me out ??
thanks
|
|
|
|
|
If I remember correctly you cant in user mode, only in kernel mode.
if someone knows how to do it in kernel mode, I would very much like to know.
But if you have opened the file, then you should already have the file name.
Magnus
|
|
|
|
|
I did some research and found a way of doing it with a kernel call from user mode. Code below.
I would like to thank Felix Kasza as its his code to enumerate NTFS streams that I adapted to get the file name instead.
This is the actual code, that I have tested and it works on Win2000 Pro with .NET 2003. The filename you recive is in UNICODE. And this code have no error handling or cleanup. Thats left as an exercise for the reader
void Test()
{
NQIF nqif = NULL;
HMODULE hNtdll = LoadLibrary( "ntdll.dll" );
if ( hNtdll < (HINSTANCE) 33 )
{
return;
}
nqif = (NQIF) GetProcAddress( hNtdll, "ZwQueryInformationFile" );
if ( nqif == NULL )
{
FreeLibrary( hNtdll );
return;
}
HANDLE h = ::CreateFile( "D:\\series.txt", GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
DWORD rc;
IO_STATUS_BLOCK iosb;
FILE_NAME_INFORMATION* fni;
void* pMem = new char[1024];
fni = (FILE_NAME_INFORMATION*)pMem;
fni->FileNameLength = 1000;
rc = nqif( h, &iosb, fni, 1024, FileNameInformation );
if ( rc != 0 )
{
return;
}
fni->FileName[ fni->FileNameLength / 2 ] = L'\0';
}
You also need the following defs if you dont have the DDK.
typedef LONG NTSTATUS;
typedef struct _IO_STATUS_BLOCK {
union {
NTSTATUS Status;
PVOID Pointer;
};
ULONG_PTR Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
typedef enum _FILE_INFORMATION_CLASS {
FileDirectoryInformation = 1,
FileFullDirectoryInformation,
FileBothDirectoryInformation,
FileBasicInformation,
FileStandardInformation,
FileInternalInformation,
FileEaInformation,
FileAccessInformation,
FileNameInformation,
FileRenameInformation,
FileLinkInformation,
FileNamesInformation,
FileDispositionInformation,
FilePositionInformation,
FileFullEaInformation,
FileModeInformation,
FileAlignmentInformation,
FileAllInformation,
FileAllocationInformation,
FileEndOfFileInformation,
FileAlternateNameInformation,
FileStreamInformation,
FilePipeInformation,
FilePipeLocalInformation,
FilePipeRemoteInformation,
FileMailslotQueryInformation,
FileMailslotSetInformation,
FileCompressionInformation,
FileObjectIdInformation,
FileCompletionInformation,
FileMoveClusterInformation,
FileQuotaInformation,
FileReparsePointInformation,
FileNetworkOpenInformation,
FileAttributeTagInformation,
FileTrackingInformation,
FileMaximumInformation
} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
NTSYSAPI
NTSTATUS
NTAPI
ZwQueryInformationFile(
IN HANDLE FileHandle,
OUT PIO_STATUS_BLOCK IoStatusBlock,
OUT PVOID FileInformation,
IN ULONG Length,
IN FILE_INFORMATION_CLASS FileInformationClass
);
typedef struct _FILE_NAME_INFORMATION {
ULONG FileNameLength;
WCHAR FileName[1];
} FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
typedef DWORD (__stdcall *NQIF)(
IN HANDLE FileHandle,
OUT PIO_STATUS_BLOCK IoStatusBlock,
OUT PVOID FileInformation,
IN ULONG Length,
IN FILE_INFORMATION_CLASS FileInformationClass
);
|
|
|
|
|
Well done! The only "problem" (as you probably realise) is that it only works on Win2k or later. FileNameInformation is not supported under NT4 or earlier (well, it's not in the NT4 DDK anyway )
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
No I didnt infact as I only have the 2000 pro ddk. Its to bad the DDK documentation isnt as good as the SDK one. Do you know of anyplace where you can easy find out os dependecy for kernel calls? I have looked in the MSDN docs but couldnt find any info.
And I also tried downloading an older DDK, but MS says its not needed any more, that you can use Win XP's DDK (which is bogus if you need to do drivers for NT4). So if any one know where I can get older DDK's (I have 2000 pro and XP and 2003 server).
Magnus
|
|
|
|
|
I've never actually done any DDK development. I just remembered that the docs for the NT4 DDK came with the copy of MSDN library I got with VS6. Anyway, I just looked up that function, and found no mention of getting the filename, so I assumed it wasn't supported.
Magnus Westin wrote:
And I also tried downloading an older DDK, but MS says its not needed any more, that you can use Win XP's DDK (which is bogus if you need to do drivers for NT4).
MS don't support NT4 any more, so they assume that nobody else should either
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Thanks alot ..it seems it will serve my purpose...
|
|
|
|
|
void CFDDDlg::OnClose() //A function to destroy the dialog
{
......
if(MessageBoxEx(NULL,"Are you sure to destroy the dialog?","Warning",
MB_YESNO,
0x0409 // language identifier:English
) ==IDNO )
Some Operations to Wait until a varible "m_bStop" is "true"
CDialog::OnClose();
}
What way can make the function to wait?
And that won't stop any other function from going on while waiting to execute CDialog::OnClose();
|
|
|
|
|
I'm not sure exactly what you want. Does your program have multiple threads? If not, then you can't just wait there. If you do, your entire program will stop executing - nothing will happen. If you're using multiple threads, you're better off using an event or a mutex and using WaitForSingleObject() /WaitForMultipleObjects() .
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Yeah,I am using multiple threads.
Thank you! I'll have a try.
|
|
|
|
|
What is the regexp to find (in VC++ 6.0) all occurencies of MyVariable = and not MyVariable == ? Seems like MyVariable* =\~= does not work.
~RaGE();
|
|
|
|
|
MyVariable =[^=] should do the trick.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
MyVariable =[^=] should do the trick.
Thanks, but nope, I had already tried that, and it's surprisingly not working...
~RaGE();
|
|
|
|
|
How doesn't it work? I tested it before I replied and it worked perfectly for me. If there's more than one space between MyVariable and the '=' then it won't work, but then you'll just need to use '\:b*' instead of ' ' in the rule.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
I know that, but it did not work either.
~RaGE();
|
|
|
|
|
How didn't it work? Did it match the 'MyVariable ==' like it's not meant to, or did it not match the 'MyVariable =' like it's supposed to
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
I'm writing a simple game in win32/gdi, and I want to allow the user to modify the frame rate with a horizontal slider control. How do I set it up? I've found information on how to do so in MFC, but don't want to use MFC in my application for performance purposes.
Any help much appreciated.
Blackmesa.
|
|
|
|
|
Hi:
How could I know if my windows is English version or the other language version(such as Chinese ,German ...)?
I use GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_IDEFAULTLANGUAGE ,szPath,6),
but when I test it in English version and Chinese version windows system,it both returns "0804",Why? How should I do?
Thanks
benben.
|
|
|
|
|
Use LOCALE_SLANGUAGE instead of LOCALE_IDEFAULTLANGUAGE . Your buffer will need to be a bit bigger too
[edit] I used LOCALE_USER_DEFAULT instead of LOCALE_SYSTEM_DEFAULT so that it works if different users have different languages [/edit]
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
|
You're welcome
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Hi all, please help me.
I am trying to load a bitmap using LoadImage . I have attach the code . Please create a bitmap of size 32*23 and save it to 256 colors.My Display pallette setting is in 16 million colors.
This is working fine in 256 color setting.
32*32 is the image width and image height.
OnDrawFunction()
{
typedef unsigned short UINT16;
UINT16 *MyDisplayBuffer = (UINT16*)GlobalAlloc(GPTR,32*32*2);
m_hBitmap = (HBITMAP)LoadImage(NULL,"C:\\Bitmap1.bmp", IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
CBitmap bmp;
bmp.Attach(m_hBitmap);
BYTE* DisplayBuffer=(BYTE*)GlobalAlloc(GPTR,32*32);
int Update = 0;
int color =0;
CDC memdc;
memdc.CreateCompatibleDC(pDC);
SelectObject( memdc,m_hBitmap);
bmp.GetBitmapBits(32*32,DisplayBuffer);
for(int y =0; y < 32; y++)
{
for(int x =0 ; x< 32; x++)
{
int index = x + y *32;
color= DisplayBuffer[Update];
MyDisplayBuffer[index] =color
Update++;
}
}
CDC dcDisplayMemory;
CBitmap bmp1;
dcDisplayMemory.CreateCompatibleDC(pDC);
bmp1.CreateCompatibleBitmap(pDC,32,32);
dcDisplayMemory.SelectObject(&bmp1);
bmp1.SetBitmapBits(32*32 *2,MyDisplayBuffer);
pDC->BitBlt(10,20,32,32,&dcDisplayMemory,0,0,SRCCOPY);
}
Thanks in Advance
|
|
|
|
|
This is a very long-winded way of doing it. Why don't you just do this:
HGDIOBJ hBitmap = LoadImage(NULL, _T("C:\\Bitmap1.bmp"), IMAGE_BITMAP,
0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
CDC memDC;
memDC.CreateCompatibleDC(pDC);
HGDIOBJ hbmOld = SelectObject(memDC.m_hDC, hBitmap);
pDC->BitBlt(10, 20, 32, 32, &memDC, 0, 0, SRCCOPY);
SelectObject(memDC.m_hDC, hbmOld);
memDC.DeleteDC(); This should work nicely
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
No i can use that function directly
Thanks
|
|
|
|
|
|