Re: Help with FindFirstFile
From: Maximus (maximator_at_videotron.ca)
Date: 01/04/04
- Next message: Elijah Bailey: "Re: Sorting records using sort()"
- Previous message: Jacques Labuschagne: "Re: Could anyone explain the code for me?"
- In reply to: Rich Strang: "Help with FindFirstFile"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 3 Jan 2004 22:56:06 -0800
"Rich Strang" <riky_rang@hotmail.com> wrote in message
news:uyeJb.4761$aY6.41392239@news-text.cableinet.net...
> Hi group
>
> I have just got the FindFirstFile function working in my small tutorial
app,
> the problem is that I can only seem to get it working when I hard code the
> search string. I have defined a string str1 but I get a conversion error
> when passing it to the function. Also when I attempt to print a string I
> get a memory error: "Memory could not be read".
>
> I have included the code below for you all to see, it is just a subset of
> the code I am using.
>
> I would be *very* grateful of any pointers you could provide me with to
> fixing this problem.
>
> Kind regards
>
> Rich Strang
>
> #define _WIN32_WINNT 0x0400
> #include <windows.h>
> #include <stdio.h>
> #include <string>
> using namespace std;
>
> int main(int argc, char *argv[])
> {
> WIN32_FIND_DATA FindFileData;
> HANDLE hFind;
>
> string str1 = "main.cpp";
>
> //printf ("Target file is %s.\n", str1);
> hFind = FindFirstFile(str1, &FindFileData);
Try this:
printf ("Target file is %s.\n", str1.c_str());
hFind = FindFirstFile(str1.c_str(), &FindFileData);
> if (hFind == INVALID_HANDLE_VALUE)
> {
> printf ("Invalid File Handle. GetLastError reports %d\n", GetLastError
> ());
> return (0);
> }
> else
> {
> printf ("The first file found is %s\n", FindFileData.cFileName);
> FindClose(hFind);
> return (1);
> }
> }
>
>
Max.
- Next message: Elijah Bailey: "Re: Sorting records using sort()"
- Previous message: Jacques Labuschagne: "Re: Could anyone explain the code for me?"
- In reply to: Rich Strang: "Help with FindFirstFile"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|