Can someone tell me what's wrong with his code?
This is a direct modification of the sample code from msdn. It's a simple directory listing.
I'm using Visual Studio 2005
Code:#include "stdafx.h" #include <windows.h> #include <stdio.h> #define _WIN32_WINNT 0x0501 WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; DWORD dwError; char DirSpec[] = "C:\*"; DWORD dwBufferLenght; printf ("Target directory is %s.\n",DirSpec); printf ("Size of name dir %d\n",dwBufferLenght); /*########################### PROBLEM: type mismatch with *DirSpec* variable*/ /*IF TYPECAST, IT COMILES BUT DOESN'T WORK*/ // Find the first file in the directory. hFind = FindFirstFile((LPCWSTR)DirSpec, &FindFileData); /*###########################*/ if (hFind == INVALID_HANDLE_VALUE) { printf ("Invalid file handle. Error is %u.\n", GetLastError()); return (-1); } else { 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(); FindClose(hFind); if (dwError != ERROR_NO_MORE_FILES) { printf ("FindNextFile error. Error is %u.\n", dwError); return (-1); } }



LinkBack URL
About LinkBacks



, I did like you suggested and it worked, FindFirstFile() returns a valid handle, but when it printf the filename for some reason it printf only the first character.