problem with wide chars (urgent :( )
-
I am using NtQueryDirectoryFile function to enumerate all files in a certain folder instead of FindFirstFile and FindNextFile. I just want to see their names so I use this structure typedef struct _FILE_NAMES_INFORMATION { ULONG NextEntryOffset; ULONG Unknown; ULONG FileNameLength; WCHAR FileName[1]; } FILE_NAMES_INFORMATION, *PFILE_NAMES_INFORMATION; how do I translate the "FileName" parameter to an multibyte char or a readble char. I use WideCharToMultiByte(CP_ACP,0,n->FileName,n->FileNameLength,name,sizeof(name),NULL,NULL); but the name is not totally translated but only the first 4 or 5 characters. variable "name" being defined like this char *nume=(char *)malloc(n->FileNameLength); Can someone please help me with this. it is verry urgent thanks gabby -- modified at 21:20 Tuesday 7th March, 2006
-
I am using NtQueryDirectoryFile function to enumerate all files in a certain folder instead of FindFirstFile and FindNextFile. I just want to see their names so I use this structure typedef struct _FILE_NAMES_INFORMATION { ULONG NextEntryOffset; ULONG Unknown; ULONG FileNameLength; WCHAR FileName[1]; } FILE_NAMES_INFORMATION, *PFILE_NAMES_INFORMATION; how do I translate the "FileName" parameter to an multibyte char or a readble char. I use WideCharToMultiByte(CP_ACP,0,n->FileName,n->FileNameLength,name,sizeof(name),NULL,NULL); but the name is not totally translated but only the first 4 or 5 characters. variable "name" being defined like this char *nume=(char *)malloc(n->FileNameLength); Can someone please help me with this. it is verry urgent thanks gabby -- modified at 21:20 Tuesday 7th March, 2006
Use
W2A
Nibu thomas Software Developer
-
Use
W2A
Nibu thomas Software Developer
I get thiese 3 errors : error C2065: '_lpw' : undeclared identifier '_convert' : undeclared dentifier error C2065: '_acp' : undeclared dentifier the headers i included (from what I ve read about w2a) are AtlBase.h, AtlConv.h; I am doing a win 32 aplication not mfc by the way :( how should I not get the 3 errors ? gabby -- modified at 4:43 Wednesday 8th March, 2006
-
I get thiese 3 errors : error C2065: '_lpw' : undeclared identifier '_convert' : undeclared dentifier error C2065: '_acp' : undeclared dentifier the headers i included (from what I ve read about w2a) are AtlBase.h, AtlConv.h; I am doing a win 32 aplication not mfc by the way :( how should I not get the 3 errors ? gabby -- modified at 4:43 Wednesday 8th March, 2006
When using an
ATL
string conversion macro, specify theUSES_CONVERSION
macro at the beginning of your function in order to avoid compiler errors.
Nibu thomas Software Developer
-
I am using NtQueryDirectoryFile function to enumerate all files in a certain folder instead of FindFirstFile and FindNextFile. I just want to see their names so I use this structure typedef struct _FILE_NAMES_INFORMATION { ULONG NextEntryOffset; ULONG Unknown; ULONG FileNameLength; WCHAR FileName[1]; } FILE_NAMES_INFORMATION, *PFILE_NAMES_INFORMATION; how do I translate the "FileName" parameter to an multibyte char or a readble char. I use WideCharToMultiByte(CP_ACP,0,n->FileName,n->FileNameLength,name,sizeof(name),NULL,NULL); but the name is not totally translated but only the first 4 or 5 characters. variable "name" being defined like this char *nume=(char *)malloc(n->FileNameLength); Can someone please help me with this. it is verry urgent thanks gabby -- modified at 21:20 Tuesday 7th March, 2006
You have the right idea here - if you are going to be looping, you might want to stay away from the ATL conversion macros if you are using VC++ 6.0 - those macros dynamically allocate from the stack and you can quickly blow the stack if looping over a good amount of files.
euacela wrote:
WideCharToMultiByte(CP_ACP,0,n->FileName,n->FileNameLength,name,sizeof(name),NULL,NULL);
If
name
is a pointer (and it looks like it is), you cannot usesizeof(...)
on it to determine the size of what it points to. Try:ULONG ulFNLen = n -> FileNameLength;
char *pcFileName = new char[ ulFNLen+ 1
];//
// Handle Error If pcFileName Is NULL...
//
::WideCharToMultiByte( CP_THREAD_ACP, WC_SEPCHARS, n -> FileName,
ulFNLen, pcFileName, ulFNLen, NULL, NULL );
pcFileName[ ulFNLen ] = '\0'; // Paranoid Terminate The FileName
//
// Use pcFileName...
//
delete [] pcFileName;Your
malloc(...)
example is incorrect, because it does not include space for a terminatingNUL
character. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!)