Results 1 to 14 of 14

Thread: API problems

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183

    API problems

    Just getting learning about API calls- any idea how to fix the problems in this code? I am trying the count the number of files in a directory....
    #include <windows.h>

    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
    LPWIN32_FIND_DATA Found;
    HANDLE hFile;
    BOOL Retval;
    int fileCount = 0;
    const unsigned char path [] = {"C:\\Documents and Settings\\Administrator\\My Documents\\*.*"};

    hFile = FindFirstFile(path, Found);

    //Check for an NVALID_HANDLE_VALUE
    if (hFile == 0)
    MessageBox (NULL, TEXT ("Error File Non Existent"), TEXT ("HelloMsg"), 0) ;

    do{
    //increment the count of files present
    if(Found->dwFileAttributes == 16 || Found->dwFileAttributes == 32)
    fileCount ++;

    Retval = FindNextFile(hFile, Found);
    }while (Retval != 0);

    FindClose (hFile);

    //Don't think I can do this can I?
    MessageBox (NULL, TEXT ("Files Present In Directory" && fileCount), TEXT ("HelloMsg"), 0) ;

    return (0);
    }

  2. #2
    Do you get 15 errors like me?

    Attached Images Attached Images  

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Use WIN32_FIND_DATA and &Found

    LPWIN32_FIND_DATA is merely a pointer. You should never use the LP* types because they just confuse.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by filburt1
    Do you get 15 errors like me?

    As I said, Borland C++ compiler sucks
    Baaaaaaaaah

  5. #5
    It is a 16-bit compiler.

    Attached Images Attached Images  

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    If it's 16-bit then ***** it and get a REAL compiler

    Good luck trying to use windows with it
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    I like the IDE though.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183
    ok I think I understand what you mean, but by switching that O have a problem with the FindNextFile call (incompatible types):

    altered code:

    #include <windows.h>

    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
    WIN32_FIND_DATA Found;
    HANDLE hFile;
    BOOL Retval;
    int fileCount = 0;
    const unsigned char path [] = {"C:\\Documents and Settings\\Administrator\\My Documents\\*.*"};

    hFile = FindFirstFile(path, &Found);

    //Check for an NVALID_HANDLE_VALUE
    if (hFile == 0)
    MessageBox (NULL, TEXT ("Error File Non Existent"), TEXT ("HelloMsg"), 0) ;

    do{
    //increment the count of files present
    if(Found.dwFileAttributes == 16 || Found.dwFileAttributes == 32)
    fileCount ++;

    Retval = FindNextFile(hFile, Found);

    }while (Retval != 0);

    FindClose (hFile);

    //Don't think I can do this can I?
    MessageBox (NULL, TEXT ("Files Present In Directory"), TEXT ("HelloMsg"), 0) ;

    return (0);
    }

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It always wants a pointer:

    Retval = FindNextFile(hFile, Found);

    ...changes to...

    Retval = FindNextFile(hFile, &Found);
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by filburt1
    It is a 16-bit compiler.
    I have you a link to the 32 bit version a longgg time ago
    Baaaaaaaaah

  11. #11
    But I like the IDE. I can get the BC++ compiler free, but I am stuck with the built-in compiler for the TC++4.52 IDE.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183
    humm.. now I am getting an error: unresolved exernal symbol _main

    alternation:
    #include <windows.h>

    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
    WIN32_FIND_DATA Found;
    HANDLE hFile;
    BOOL Retval;
    int fileCount = 0;
    char path [] = {"C:\\Documents and Settings\\Administrator\\My Documents\\*.*"};

    hFile = FindFirstFile(path, &Found);

    //Check for an NVALID_HANDLE_VALUE
    if (hFile == 0)
    MessageBox (NULL, TEXT ("Error File Non Existent"), TEXT ("HelloMsg"), 0) ;

    do{
    //increment the count of files present
    if(Found.dwFileAttributes == 16 || Found.dwFileAttributes == 32)
    fileCount ++;

    Retval = FindNextFile(hFile, &Found);
    }while (Retval != 0);

    FindClose (hFile);

    MessageBox (NULL, TEXT ("Files Present In Directory"), TEXT ("HelloMsg"), 0) ;

    return (0);
    }

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    That's linker settings, not code errors. You need to make sure you selected the correct project type (Win32 Application or similar).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183
    ooops, yup that was it, thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width