Click here to Skip to main content
15,919,423 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCAD plotting Pin
eddymohd3-Jul-03 23:06
eddymohd3-Jul-03 23:06 
QuestionBold text in Listcontrol? Pin
whofmans3-Jul-03 22:37
whofmans3-Jul-03 22:37 
AnswerRe: Bold text in Listcontrol? Pin
Rage4-Jul-03 0:38
professionalRage4-Jul-03 0:38 
AnswerRe: Bold text in Listcontrol? Pin
Ryan Binns4-Jul-03 0:47
Ryan Binns4-Jul-03 0:47 
AnswerThanks for your help! Bold looks good. Pin
whofmans4-Jul-03 5:20
whofmans4-Jul-03 5:20 
GeneralGet file name from file handel Pin
Naveen_mah3-Jul-03 22:07
Naveen_mah3-Jul-03 22:07 
GeneralRe: Get file name from file handel Pin
Magnus Westin3-Jul-03 22:54
Magnus Westin3-Jul-03 22:54 
GeneralRe: Get file name from file handel (solution found) Pin
Magnus Westin4-Jul-03 0:50
Magnus Westin4-Jul-03 0:50 
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 Smile | :)
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->FilName is UNICODE and fni->FileNameLength is bytes not characters.
	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 {
// end_wdm
    FileDirectoryInformation       = 1,
    FileFullDirectoryInformation, // 2
    FileBothDirectoryInformation, // 3
    FileBasicInformation,         // 4  wdm
    FileStandardInformation,      // 5  wdm
    FileInternalInformation,      // 6
    FileEaInformation,            // 7
    FileAccessInformation,        // 8
    FileNameInformation,          // 9
    FileRenameInformation,        // 10
    FileLinkInformation,          // 11
    FileNamesInformation,         // 12
    FileDispositionInformation,   // 13
    FilePositionInformation,      // 14 wdm
    FileFullEaInformation,        // 15
    FileModeInformation,          // 16
    FileAlignmentInformation,     // 17
    FileAllInformation,           // 18
    FileAllocationInformation,    // 19
    FileEndOfFileInformation,     // 20 wdm
    FileAlternateNameInformation, // 21
    FileStreamInformation,        // 22
    FilePipeInformation,          // 23
    FilePipeLocalInformation,     // 24
    FilePipeRemoteInformation,    // 25
    FileMailslotQueryInformation, // 26
    FileMailslotSetInformation,   // 27
    FileCompressionInformation,   // 28
    FileObjectIdInformation,      // 29
    FileCompletionInformation,    // 30
    FileMoveClusterInformation,   // 31
    FileQuotaInformation,         // 32
    FileReparsePointInformation,  // 33
    FileNetworkOpenInformation,   // 34
    FileAttributeTagInformation,  // 35
    FileTrackingInformation,      // 36
    FileMaximumInformation
// begin_wdm
} 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
	);

GeneralRe: Get file name from file handel (solution found) Pin
Ryan Binns4-Jul-03 1:04
Ryan Binns4-Jul-03 1:04 
GeneralRe: Get file name from file handel (solution found) Pin
Magnus Westin4-Jul-03 1:13
Magnus Westin4-Jul-03 1:13 
GeneralRe: Get file name from file handel (solution found) Pin
Ryan Binns4-Jul-03 1:25
Ryan Binns4-Jul-03 1:25 
GeneralRe: Get file name from file handel (solution found) Pin
Naveen_mah4-Jul-03 1:14
Naveen_mah4-Jul-03 1:14 
GeneralAbout OnClose Pin
FlyingDancer3-Jul-03 21:52
FlyingDancer3-Jul-03 21:52 
GeneralRe: About OnClose Pin
Ryan Binns3-Jul-03 22:08
Ryan Binns3-Jul-03 22:08 
GeneralRe: About OnClose Pin
FlyingDancer3-Jul-03 22:17
FlyingDancer3-Jul-03 22:17 
GeneralRegexp Pin
Rage3-Jul-03 21:44
professionalRage3-Jul-03 21:44 
GeneralRe: Regexp Pin
Ryan Binns3-Jul-03 22:03
Ryan Binns3-Jul-03 22:03 
GeneralRe: Regexp Pin
Rage4-Jul-03 0:37
professionalRage4-Jul-03 0:37 
GeneralRe: Regexp Pin
Ryan Binns4-Jul-03 0:41
Ryan Binns4-Jul-03 0:41 
GeneralRe: Regexp Pin
Rage4-Jul-03 2:40
professionalRage4-Jul-03 2:40 
GeneralRe: Regexp Pin
Ryan Binns4-Jul-03 2:45
Ryan Binns4-Jul-03 2:45 
GeneralSetting up a slider control. Pin
blackmesa3-Jul-03 20:50
blackmesa3-Jul-03 20:50 
Questionhow to get the current window system language name? Pin
benben3-Jul-03 17:36
benben3-Jul-03 17:36 
AnswerRe: how to get the current window system language name? Pin
Ryan Binns3-Jul-03 20:27
Ryan Binns3-Jul-03 20:27 
GeneralThanks Pin
benben4-Jul-03 21:37
benben4-Jul-03 21:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.