WCHAR fileName[1]; - an array of 1 character, therefore, if zero is completed, it will contain only the zero delimiter L'\0' .
What API function are you calling?
Edited
The fileName element in FbwfCacheDetail is only 1 character, which is the common method used when the length of the array is unknown and the member is the last member in the structure. Since you probably already noticed that the allocated allocated buffer is sizeof (FbwfCacheDetail) length, then FbwfFindFirst returns ERROR_NOT_ENOUGH_MEMORY .
So, if I understand, what you want to do is return a NULL name with a completed name using fprintf. This can be done as follows:
fprintf (outputfile, L"%.*ls", cacheDetail.fileNameLength, cacheDetail.fileName);
This will print only the first fileNameLength characters of fileName .
An alternative approach is to add a NULL terminator to the end of fileName. First you need to make sure the buffer is long enough, which can be done by subtracting sizeof (WCHAR) from the size argument, which you pass to FbwfFindFirst. Therefore, if you allocate a buffer of size 1000 bytes, you will pass 998 to FbwfFindFirst, having reserved the last two bytes in the buffer for your own use. Then, to add the NULL terminator and display the file name, use
cacheDetail.fileName[cacheDetail.fileNameLength] = L'\0'; fprintf (outputfile, L"%ls", cacheDetail.fileName);
Stephen nutt
source share