Hi guys... im trying to understand some win32api functions and i saw this code in msdn page:
Well, this code is for return all files in a directory... but look at the output:
#define BUFSIZE MAX_PATH
int main(int argc, char *argv)
HANDLE hFind = INVALID_HANDLE_VALUE;
DirSpec = (LPSTR) malloc (BUFSIZE);
// Check for command-line parameter; otherwise, print usage.
if(argc != 2)
printf("Usage: Test <dir>\n");
// Check that the input is not larger than allowed.
StringCbLength(argv, BUFSIZE, &length_of_arg);
if (length_of_arg > (BUFSIZE - 2))
printf("Input directory is too large.\n");
printf ("Target directory is %s.\n", argv);
// Prepare string for use with FindFile functions. First,
// copy the string to a buffer, then append '\*' to the
// directory name.
StringCbCopyN (DirSpec, BUFSIZE, argv, length_of_arg+1);
StringCbCatN (DirSpec, BUFSIZE, "\\*", 3);
// Find the first file in the directory.
hFind = FindFirstFile(DirSpec, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
printf ("Invalid file handle. Error is %u.\n", GetLastError());
printf ("First file name is %s.\n", FindFileData.cFileName);
// List all the other files in the directory.
while (FindNextFile(hFind, &FindFileData) != 0)
printf ("Next file name is %s.\n", FindFileData.cFileName);
dwError = GetLastError();
if (dwError != ERROR_NO_MORE_FILES)
printf ("FindNextFile error. Error is %u.\n", dwError);
Why the 2nd and 3rd lines of the input goes like this?
Target directory is c:\test.
Fist file name is ..
Next file name is ...
Next file name is testdirectory1.
Next file name is tesfile1.bmp
Next file name is testfile2.bmp
How to fix it?