Question : Trouble with using FindFirstFile in MFC app

I have a dialog based application. From the OnInitDialog() I want to build a list of a specific kind of files and update my combo box on the dialog. To get a listing of those kind of files from the hard disk, I call the Win32 functions FindFirstFile and FindNextFile. I had successfully tested these functions from a console app and they seemed to be fine, but my dialog app cannot execute the FindFirstFile and I get an unhandeled exception in NTDLL.DLL for an access violation. Another information that might be helpful is the prototype of FindFirstFile is as:
HANDLE FindFirstFile (LPCTSTR, LPWIN32_FIND_DATA);
My calling sequence is as follows:
char myFile="C:\\*.ppp";  // for example
LPWIN32_FIND_DATA lpFindFileData;
HANDLE myHandle;

myHandle = FindFirstFile (myFile, lpFindFileData);

       Another question I have is if I can use normal C based char string pointers in place of LPCTSTRS?

Answer : Trouble with using FindFirstFile in MFC app

Here's an example of how I've done this in an MFC application.

WIN32_FIND_DATA findData;                                      
HANDLE hFile;
CString strFileMask = "CommSvr*.DLL";

char szCurrentDirectory[CHAR_MAX];
GetCurrentDirectory(sizeof(szCurrentDirectory), szCurrentDirectory);

ZeroMemory(&findData, sizeof(findData));
hFile = FindFirstFile(strFileMask, &findData);
if (INVALID_HANDLE_VALUE != hFile)
{
 do
 {
  if ((findData.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) ||
  (findData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE))
  {
   TRACE1("*** Found '%s'\n", findData.cFileName);
  }
 } while (FindNextFile(hFile, &findData));
}
FindClose(hFile);

HTH,
Tom

Random Solutions  
 
programming4us programming4us