You have many errors in your code.
First, you do not use FindNextFile correctly, the prototype :
BOOL WINAPI FindNextFile( _In_ HANDLE hFindFile, _Out_ LPWIN32_FIND_DATA lpFindFileData );
After, you do not use
GetLastError()
correctly, who fire an Exception.GetLastError
return aDWORD
, you can print it as a string. (http://msdn.microsoft.com/en-us/library/ms679360(v=vs.85).aspx)
Here is an example of what your code should look like :
#include<stdio.h>
#include<tchar.h>
#include<windows.h>
int _tmain(int argc, TCHAR *argv[])
{
HANDLE hNextFile;
WIN32_FIND_DATA findFileData;
LPCTSTR fileName = argv[1]; //input argument "C:\test\file*.txt"
hNextFile = FindFirstFile(fileName, &findFileData);
BOOL res = TRUE;
//^^^^^^^^^^^^^^^^
while(hNextFile != INVALID_HANDLE_VALUE && res)
// ^^^^^^
{
printf("long name: %s\t8dot3 name: %s\n", findFileData.cFileName, findFileData.cAlternateFileName);
res = FindNextFile(hNextFile, &findFileData); //Unhandled exception here!
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
printf("%d", GetLastError());
// ^^ // You can also use FormatMessage as it is said in the documentation
return 0;
}