WM5 dev, Problem with C++ FindFirstFile returning 0xffffffff
-
I am having a problem with FindFirstFile, I am writing for WM5 with Visual Studio 2008 90 day trial. Here is a chunk of code:
int GetTheFile(LPWSTR ddir)
{
LPWIN32_FIND_DATAW ac_file;
HANDLE fileHandle;
int ret=1;wsprintf(ddir, TEXT("\\*.*"));
fileHandle = FindFirstFile(ddir, ac_file);
if (fileHandle != INVALID_HANDLE_VALUE)After the FindFirstFile executes, ac_file is unchanged (all 0s), fileHandle is 0xffffffff (-1 which is invalid handle), I have tried several different things for ddir ("\\", "\\*.*", "\\Windows",...). Any ideas? Thanks
-
I am having a problem with FindFirstFile, I am writing for WM5 with Visual Studio 2008 90 day trial. Here is a chunk of code:
int GetTheFile(LPWSTR ddir)
{
LPWIN32_FIND_DATAW ac_file;
HANDLE fileHandle;
int ret=1;wsprintf(ddir, TEXT("\\*.*"));
fileHandle = FindFirstFile(ddir, ac_file);
if (fileHandle != INVALID_HANDLE_VALUE)After the FindFirstFile executes, ac_file is unchanged (all 0s), fileHandle is 0xffffffff (-1 which is invalid handle), I have tried several different things for ddir ("\\", "\\*.*", "\\Windows",...). Any ideas? Thanks
There are several problems with your code: This is a pointer to a WIN32_FIND_DATAW struct in which you never initialize and point to a valid location.
LPWIN32_FIND_DATAW ac_file;
It would be better to be more precise about what drive you wish to access such as "C:\\*.*"
wsprintf(ddir, TEXT("\\*.*"));
See if this works for you:
WIN32_FIND_DATAW ac_file = {0}; HANDLE fileHandle =0; wsprintf(ddir, TEXT("C:\\*.*")); fileHandle = FindFirstFile(ddir, &ac_file); if (fileHandle != INVALID_HANDLE_VALUE) { //... }
Best Wishes, -David Delaune
-
There are several problems with your code: This is a pointer to a WIN32_FIND_DATAW struct in which you never initialize and point to a valid location.
LPWIN32_FIND_DATAW ac_file;
It would be better to be more precise about what drive you wish to access such as "C:\\*.*"
wsprintf(ddir, TEXT("\\*.*"));
See if this works for you:
WIN32_FIND_DATAW ac_file = {0}; HANDLE fileHandle =0; wsprintf(ddir, TEXT("C:\\*.*")); fileHandle = FindFirstFile(ddir, &ac_file); if (fileHandle != INVALID_HANDLE_VALUE) { //... }
Best Wishes, -David Delaune
I guess I didn't notice that LPWIN32_FIND_DATAW is just a pointer. I was getting a warning that I looked at and just thought "of course its not initialized, it will get a value from FindFirstFile". So, I'll change that! This is for a Window Mobile device, so there is no C: drive, it is just \\. Then if you want a memory card, you would enter \\<<i>name of card> like mine is \\SD Card. I was searching for a file in a particular directory, but the file can have some parts slightly different, here is what I got working to find my file:
int GetTheFile(LPWSTR lpszDir)
{
LPWIN32_FIND_DATAW ac_file;
_WIN32_FIND_DATAW the_dir[MAX_PATH];
HANDLE fileHandle;
int ret=1;ac\_file = the\_dir; wsprintf(lpszDir, TEXT("\\\\My Documents\\\\first\*.txt")); fileHandle = FindFirstFileW(lpszDir, ac\_file); if (fileHandle != INVALID\_HANDLE\_VALUE)
For some reason I could not get the types to work correctly for making ac_file like you suggested, but I got it to work like this, and I can tinker with it now. This will look for a file in \My Documents named first.txt, like \My Document\first-1209.txt Thanks for helping me figure this out Dave :) . Ken