<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem mit ReadFile - Finde den Fehler nicht...]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>Der folgende Code lässt sich problemlos compilieren und ausführen. Aber ReadFile funktioniert nicht. Ich hab keine Ahnung worans liegen könnte. Ich benutze Dev-C++.</p>
<pre><code class="language-cpp">dat = CreateFile(filename,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

    SetFilePointer(&amp;dat,0,0,FILE_BEGIN);    // Brauch ich das überhaupt??

    if (dat == INVALID_HANDLE_VALUE)
    {
        GetWindowText(prothwnd,prot,1024000);
        sprintf (prot,&quot;%s   -   Datei nicht vorhanden!&quot;,prot);
        SetWindowText(prothwnd,prot);
    }

    else
    {
        filesize = GetFileSize(dat, NULL);
        infile = new char[filesize+1];
        memset(infile,0,sizeof(infile));

        GetWindowText(prothwnd,prot,1024000);
        sprintf (prot,&quot;%s   -   Dateigröße: %ld Bytes&quot;,prot,filesize);
        SetWindowText(prothwnd,prot);

        if (ReadFile(&amp;dat,&amp;infile,filesize,b_read,NULL) == 0)
             MessageBox(NULL,&quot;Feehler!!&quot;,&quot;Hm..&quot;,MB_OK);  // Genau diese Fehlermeldung wird immer ausgegeben.
        MessageBox(NULL,infile,&quot;Geht net!&quot;,MB_OK);  // Und in infile steht das nichts drinnen.

        delete[] infile;

        CloseHandle(dat);
    }
</code></pre>
<p>Ich hab schon alles Mögliche probiert. Aber nie bekomm ich das was in der Datei steht. Obwohl die Datei &quot;erfolgreich&quot; geöffnet wird... Wisst ihr worans liegt?</p>
<p>Vielen Dank schon mal im voraus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>LG,<br />
Dago</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/141111/problem-mit-readfile-finde-den-fehler-nicht</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Jul 2026 08:40:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/141111.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 19 Mar 2006 12:26:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit ReadFile - Finde den Fehler nicht... on Sun, 19 Mar 2006 12:26:46 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>Der folgende Code lässt sich problemlos compilieren und ausführen. Aber ReadFile funktioniert nicht. Ich hab keine Ahnung worans liegen könnte. Ich benutze Dev-C++.</p>
<pre><code class="language-cpp">dat = CreateFile(filename,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

    SetFilePointer(&amp;dat,0,0,FILE_BEGIN);    // Brauch ich das überhaupt??

    if (dat == INVALID_HANDLE_VALUE)
    {
        GetWindowText(prothwnd,prot,1024000);
        sprintf (prot,&quot;%s   -   Datei nicht vorhanden!&quot;,prot);
        SetWindowText(prothwnd,prot);
    }

    else
    {
        filesize = GetFileSize(dat, NULL);
        infile = new char[filesize+1];
        memset(infile,0,sizeof(infile));

        GetWindowText(prothwnd,prot,1024000);
        sprintf (prot,&quot;%s   -   Dateigröße: %ld Bytes&quot;,prot,filesize);
        SetWindowText(prothwnd,prot);

        if (ReadFile(&amp;dat,&amp;infile,filesize,b_read,NULL) == 0)
             MessageBox(NULL,&quot;Feehler!!&quot;,&quot;Hm..&quot;,MB_OK);  // Genau diese Fehlermeldung wird immer ausgegeben.
        MessageBox(NULL,infile,&quot;Geht net!&quot;,MB_OK);  // Und in infile steht das nichts drinnen.

        delete[] infile;

        CloseHandle(dat);
    }
</code></pre>
<p>Ich hab schon alles Mögliche probiert. Aber nie bekomm ich das was in der Datei steht. Obwohl die Datei &quot;erfolgreich&quot; geöffnet wird... Wisst ihr worans liegt?</p>
<p>Vielen Dank schon mal im voraus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>LG,<br />
Dago</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1019590</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1019590</guid><dc:creator><![CDATA[Dago]]></dc:creator><pubDate>Sun, 19 Mar 2006 12:26:46 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit ReadFile - Finde den Fehler nicht... on Sun, 19 Mar 2006 12:42:31 GMT]]></title><description><![CDATA[<p>Du üebrgibst bei ReadFile die Addresse von dem HANDLE dat. Das ist schonmal falsch, das sollte ReadFile(dat,&amp;infile,filesize,b_read,NULL) sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1019601</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1019601</guid><dc:creator><![CDATA[vxcv]]></dc:creator><pubDate>Sun, 19 Mar 2006 12:42:31 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit ReadFile - Finde den Fehler nicht... on Sun, 19 Mar 2006 13:18:24 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">struct DateiFeld
 {
 unsigned long ulRetourZahl;      /*Gibt die Anzahl der wirklich geschriebenen oder gelesenen Bytes retour */ 

 char cLeseText[1001]; /* speicher für 1000 Bytes ..ich gebe immer eins mehr */
 HANDLE hDatei;
 }DF;

DateiBearbeitenOderNeu(char cPfad[300])  
 {
 SetLastError(0);
 DF.hDatei=CreateFile(cPfad,GENERIC_READ | GENERIC_WRITE,
                      FILE_SHARE_READ | FILE_SHARE_WRITE, 
                      NULL,
                      OPEN_ALWAYS, 
                      FILE_ATTRIBUTE_HIDDEN,  /*muss nicht versteckt sein :clown: */
                      NULL);

 return(GetLastError());
 }

DateiLesen()
 {
 ReadFile(DF.hDatei,DF.cLeseText,1000,&amp;DF.ulRetourZahl,NULL); /* Lesen von 1000 Bytes*/
 }

DateiSchliessen() 
 {
 SetLastError(0);
 if(DF.hDatei != INVALID_HANDLE_VALUE) {CloseHandle(DF.hDatei);} /* nur schließen wenns geöffnet ist */
 return(GetLastError());
 }
</code></pre>
<p>Beim auslesen gibst natürlich mehrere Möglichkeiten<br />
Hoffe es hilft wenns prob gibt posten <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1019616</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1019616</guid><dc:creator><![CDATA[Aragonx]]></dc:creator><pubDate>Sun, 19 Mar 2006 13:18:24 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit ReadFile - Finde den Fehler nicht... on Sun, 19 Mar 2006 15:39:41 GMT]]></title><description><![CDATA[<p>Danke für die schnellen Antworten. Hab das Problem gefunden.</p>
<p>So funktionierts:</p>
<pre><code class="language-cpp">ReadFile(dat,infile,filesize,&amp;b_read,NULL)
</code></pre>
<p>Gruß,<br />
Dago</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1019723</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1019723</guid><dc:creator><![CDATA[Dago]]></dc:creator><pubDate>Sun, 19 Mar 2006 15:39:41 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit ReadFile - Finde den Fehler nicht... on Sun, 19 Mar 2006 15:46:46 GMT]]></title><description><![CDATA[<p>Sorry, hab jetzt noch n anderes Problem...<br />
Und zwar, wie kann ich die Datei in einem &quot;BINARY-MODE&quot; öffnen.</p>
<p>Als Beispiel will ich eine Bild-Datei öffnen und den ganzen Inhalt in eine andere Datei schreiben. (Ist nur ein Beispiel, damit ihr wisst was ich mein, natürlich ist diese Methode zum Kopieren schwachsinnig!)</p>
<p>Danke nochmal...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1019728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1019728</guid><dc:creator><![CDATA[Dago]]></dc:creator><pubDate>Sun, 19 Mar 2006 15:46:46 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit ReadFile - Finde den Fehler nicht... on Sun, 19 Mar 2006 16:19:47 GMT]]></title><description><![CDATA[<p>Wieso sollte das da oben nicht binärmodus sein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1019740</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1019740</guid><dc:creator><![CDATA[TGRFED]]></dc:creator><pubDate>Sun, 19 Mar 2006 16:19:47 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit ReadFile - Finde den Fehler nicht... on Sun, 19 Mar 2006 16:24:23 GMT]]></title><description><![CDATA[<p>Diese Binär/Textdatei Unterscheidung gibt es bei den WinAPI Funktionen nicht. Das ist ne Sache der Standardbibliothek von C und C++.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1019743</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1019743</guid><dc:creator><![CDATA[300]]></dc:creator><pubDate>Sun, 19 Mar 2006 16:24:23 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit ReadFile - Finde den Fehler nicht... on Sun, 19 Mar 2006 16:31:02 GMT]]></title><description><![CDATA[<p>Ok, danke.... lag nicht an ReadFile sondern an strlen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1019754</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1019754</guid><dc:creator><![CDATA[Dago]]></dc:creator><pubDate>Sun, 19 Mar 2006 16:31:02 GMT</pubDate></item></channel></rss>