Re: Help with FindFirstFile

From: Maximus (maximator_at_videotron.ca)
Date: 01/04/04


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.



Relevant Pages

  • Re: Help with FindFirstFile
    ... Rich Strang wrote: ... > I have just got the FindFirstFile function working in my small tutorial ... Also when I attempt to print a string I ... pointer to the first element in a null-terminated array of char. ...
    (alt.comp.lang.learn.c-cpp)
  • Help with FindFirstFile
    ... I have just got the FindFirstFile function working in my small tutorial app, ... I have defined a string str1 but I get a conversion error ... get a memory error: ...
    (comp.lang.cpp)
  • Help with FindFirstFile
    ... I have just got the FindFirstFile function working in my small tutorial app, ... I have defined a string str1 but I get a conversion error ... get a memory error: ...
    (alt.comp.lang.learn.c-cpp)
  • Re: June 2005 EAL Question
    ... parameter to a string. ... > public class MyEventLogInstaller: Installer ... You have a web app, ... >>> at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean ...
    (microsoft.public.dotnet.general)
  • Re: Running other applications
    ... associated with a file type (extension). ... file and calling FindExecutable: ... ByVal lpDirectory As String, ByVal lpResult As String) As Long ... > The app is a program called Data Junction. ...
    (microsoft.public.vb.general.discussion)