Thread: windows api functions, not working. requirements?

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    12

    windows api functions, not working. requirements?

    hello
    i just startet to learn programming in c.i like c, ithink its a very good language, however i have a situation now.i hope you nerds can help me out..


    i need to code a windows api function. reading some binary files, store the data in a buffer and then build a tree whit it. this is not really a problem, i already implemented it (with some help), and it worked, but only on the workstation.not on some other machines.i have access to the api structures but all the handles goes to crap or -1(file not found) even if the files exist or some wildcard is used. i have visual studio 2005 on the workstation and visual studio 2008 on the other machines, full-install.this makes me insane, i started to go crazy. what is the solution for this one? also how can i check if any library file is damaged, if this is the case?

    example
    ...
    HANDLE fHandle; //HANDLE = 0xcccccc
    WIN32_FIND_DATA fData;
    ...
    fHandle = FindFirstFile("C:\*", &fData); //HANDLE = 0xffffff
    ...




    ok:my english is crap, i already know that.you dont need to tell me.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Perhaps you need "C:\\*"?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    12
    Thanks for your help matsp, but this is not the solution. I just used "C:\*" as an example, cause this is the MSDN example to show any file in a root directory. But i tried many different ways. Beginning with "C:\*" , "C:\\*" , "C:\\path\\*.dat" to the full path of the file. But none of them seems to work.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Hmm - is it possible that you need a unicode string, e.g. _T("your path") instead of the plain string literal. Or you could try with FindFirstFileA(), which is the "narrow char" version.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Try with

    Code:
    fHandle = FindFirstFile("\\\\.\\C:\\*.*", &fData);
    That works for me. Of course, be sure that your system have a C: root

    Niara

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    You may want to display the extended error information. This may give you a better understanding of the problem.

    Code:
    fHandle = FindFirstFile("C:\\*", &fData); 
      if (fHandle == INVALID_HANDLE_VALUE) 
      {
        ShowError();
      } 
      
      
    void ShowError(void) 
    { 
     char *lpMsgBuf; 
     FormatMessage( 
        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 
        NULL, 
        GetLastError(), 
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 
        (LPTSTR) &lpMsgBuf, 
        0, 
        NULL 
     ); 
     printf("Error: %s\n", lpMsgBuf);
     LocalFree( lpMsgBuf ); 
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetDiskFreeSpace Windows API fails on windows 2000
    By dnyampawar in forum Windows Programming
    Replies: 7
    Last Post: 07-09-2009, 03:39 AM
  2. Calling raw windows API using borland
    By TiMBuS in forum C++ Programming
    Replies: 3
    Last Post: 06-16-2005, 08:46 AM
  3. Programming Windows API in C++
    By JoshR in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2005, 05:40 AM
  4. Help with editor windows with win api
    By NightStalker in forum Windows Programming
    Replies: 1
    Last Post: 03-13-2003, 03:53 AM