|
-
Sep 3rd, 2001, 04:12 PM
#1
Thread Starter
Addicted Member
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);
}
-
Sep 3rd, 2001, 04:14 PM
#2
Member
-
Sep 3rd, 2001, 04:16 PM
#3
Monday Morning Lunatic
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
-
Sep 3rd, 2001, 04:16 PM
#4
PowerPoster
-
Sep 3rd, 2001, 04:18 PM
#5
Member
-
Sep 3rd, 2001, 04:21 PM
#6
Monday Morning Lunatic
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
-
Sep 3rd, 2001, 04:22 PM
#7
Member
I like the IDE though.
-
Sep 3rd, 2001, 04:29 PM
#8
Thread Starter
Addicted Member
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);
}
-
Sep 3rd, 2001, 04:31 PM
#9
Monday Morning Lunatic
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
-
Sep 3rd, 2001, 04:37 PM
#10
PowerPoster
Originally posted by filburt1
It is a 16-bit compiler.
I have you a link to the 32 bit version a longgg time ago
-
Sep 3rd, 2001, 04:46 PM
#11
Member
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.
-
Sep 3rd, 2001, 04:54 PM
#12
Thread Starter
Addicted Member
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);
}
-
Sep 3rd, 2001, 04:56 PM
#13
Monday Morning Lunatic
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
-
Sep 3rd, 2001, 04:59 PM
#14
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|