Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WM5 dev, Problem with C++ FindFirstFile returning 0xffffffff

WM5 dev, Problem with C++ FindFirstFile returning 0xffffffff

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiohelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    uzziah0
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • U uzziah0

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      U 1 Reply Last reply
      0
      • L Lost User

        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

        U Offline
        U Offline
        uzziah0
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups