<?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[[Datei] fopen ()]]></title><description><![CDATA[<p>Hi<br />
Ich habe in meiner WinSock-Klasse versucht, Dateien zu versenden. Hier mal die beiden Funktionen:<br />
SENDEN</p>
<pre><code class="language-cpp">int WAXSOCKET::SendData (SOCKET sSocket, const char FAR * tyData, int iBytesToSend = 0, int iSendMode = SEND_DATA)
{
    FILE *pFile;
    DWORD dwData;
    unsigned int iData;

    if (iBytesToSend == 0)
        iBytesToSend = 500;

    if (iSendMode == SEND_FILE)
    {
        pFile = fopen (tyData, &quot;rb&quot;);
        if (pFile != 0)
        {
            fclose (pFile);
            OutputDebugString (&quot;(ERROR) WAXSOCKET::RecvData () -&gt; fopen () fehlgeschlagen!\n&quot;);
            return WSERROR_FILE;
        }

        fseek (pFile, 0, SEEK_END);
        iData = ftell (pFile);
        fseek (pFile, 0, SEEK_SET);

        wsh.iFileSize = iData;

        lstrcpy (wsh.lpFile, ::FormatFileString ((char*) tyData));
        wsh.iSendMode = SEND_FILE;
        wsh.iBlockSize = SEND_BLOCKSIZE;
    }

    lWaxBytes = send (sSocket, TYPE_STRUCT (wsh), sizeof (WAXSEND_HEADER), 0);
    if (lWaxBytes == SOCKET_ERROR)
    {
        OutputDebugString (&quot;(ERROR) WAXSOCKET::SendData () -&gt; send () fehlgeschlagen!\n&quot;);
        return WSERROR_SEND;
    }

    if (iSendMode == SEND_FILE)
    {
        char file[4096];

        while (iData &gt;= 4096)
        {
            fread (file, 4096, 1, pFile);
            send (sSocket, file, 4096, 0);

            iData -= 4096;
        }

        if (iData != 0)
        {
            fread (file, iData, 0, pFile);
            send (sSocket, file, iData, 0);
        }

        fclose (pFile);
        return 0;
    }

    lWaxBytes = send (sSocket, tyData, iBytesToSend, 0);
    if (lWaxBytes == SOCKET_ERROR)
    {
        OutputDebugString (&quot;(ERROR) WAXSOCKET::SendData () -&gt; send () fehlgeschlagen!\n&quot;);
        return WSERROR_SEND;
    }

    return lWaxBytes;
}
</code></pre>
<p>EMPFANGEN</p>
<pre><code class="language-cpp">int WAXSOCKET::RecvData (SOCKET sSocket, char FAR * tyData, int iBytesToRecv = 0)
{
    FILE *pFile;
    DWORD dwData;
    unsigned int iData;

    if (iBytesToRecv == 0)
        iBytesToRecv = 500;

    recv (sSocket, TYPE_STRUCT (wsh), sizeof (WAXSEND_HEADER), 0);
    if (wsh.iSendMode == SEND_FILE)
    {
        char buffer[MAX_PATH];
        wsprintf (buffer, &quot;%s%s&quot;, lpWaxSaveFolder, wsh.lpFile);

        pFile = fopen (buffer, &quot;wb&quot;);
        if (pFile != 0)
        {
            fclose (pFile);
            OutputDebugString (&quot;(ERROR) WAXSOCKET::RecvData () -&gt; fopen () fehlgeschlagen!\n&quot;);
            return WSERROR_FILE;
        }

        iData = wsh.iFileSize;

        char file[4096];

        while(iData &gt; 0)
        {
            dwData = recv (sSocket, file, 4096, 0);
            fwrite (file, dwData, 1, pFile);

            iData -= dwData;
        }

        fclose (pFile);

        return 0;
    }

    lWaxBytes = recv (sSocket, tyData, iBytesToRecv, 0);
    if (lWaxBytes == 0)
    {
        DetachSocket (sSocket);
        return WSERROR_SOCKETCLOSED;
    }
    else if (lWaxBytes == SOCKET_ERROR)
    {
        return WSERROR_RECIEVE;
    }

    return lWaxBytes;
}
</code></pre>
<p>Also ich weiß nicht, wo fopen () ein Problem hat, jedenfalls immer wenn ich eine Datei senden möchte, sagt er mir Datei nicht gefunden. So sieht zum Beispiel eine Pfadangabe aus:</p>
<pre><code>K:\\WinSock\\test.exe
</code></pre>
<p>DIV Ominion</p>
<p>EDIT: Die cpp-Tags funzen nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/194451/datei-fopen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 30 Jun 2026 06:39:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/194451.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 07 Oct 2007 10:09:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Datei] fopen () on Sun, 07 Oct 2007 10:58:53 GMT]]></title><description><![CDATA[<p>Hi<br />
Ich habe in meiner WinSock-Klasse versucht, Dateien zu versenden. Hier mal die beiden Funktionen:<br />
SENDEN</p>
<pre><code class="language-cpp">int WAXSOCKET::SendData (SOCKET sSocket, const char FAR * tyData, int iBytesToSend = 0, int iSendMode = SEND_DATA)
{
    FILE *pFile;
    DWORD dwData;
    unsigned int iData;

    if (iBytesToSend == 0)
        iBytesToSend = 500;

    if (iSendMode == SEND_FILE)
    {
        pFile = fopen (tyData, &quot;rb&quot;);
        if (pFile != 0)
        {
            fclose (pFile);
            OutputDebugString (&quot;(ERROR) WAXSOCKET::RecvData () -&gt; fopen () fehlgeschlagen!\n&quot;);
            return WSERROR_FILE;
        }

        fseek (pFile, 0, SEEK_END);
        iData = ftell (pFile);
        fseek (pFile, 0, SEEK_SET);

        wsh.iFileSize = iData;

        lstrcpy (wsh.lpFile, ::FormatFileString ((char*) tyData));
        wsh.iSendMode = SEND_FILE;
        wsh.iBlockSize = SEND_BLOCKSIZE;
    }

    lWaxBytes = send (sSocket, TYPE_STRUCT (wsh), sizeof (WAXSEND_HEADER), 0);
    if (lWaxBytes == SOCKET_ERROR)
    {
        OutputDebugString (&quot;(ERROR) WAXSOCKET::SendData () -&gt; send () fehlgeschlagen!\n&quot;);
        return WSERROR_SEND;
    }

    if (iSendMode == SEND_FILE)
    {
        char file[4096];

        while (iData &gt;= 4096)
        {
            fread (file, 4096, 1, pFile);
            send (sSocket, file, 4096, 0);

            iData -= 4096;
        }

        if (iData != 0)
        {
            fread (file, iData, 0, pFile);
            send (sSocket, file, iData, 0);
        }

        fclose (pFile);
        return 0;
    }

    lWaxBytes = send (sSocket, tyData, iBytesToSend, 0);
    if (lWaxBytes == SOCKET_ERROR)
    {
        OutputDebugString (&quot;(ERROR) WAXSOCKET::SendData () -&gt; send () fehlgeschlagen!\n&quot;);
        return WSERROR_SEND;
    }

    return lWaxBytes;
}
</code></pre>
<p>EMPFANGEN</p>
<pre><code class="language-cpp">int WAXSOCKET::RecvData (SOCKET sSocket, char FAR * tyData, int iBytesToRecv = 0)
{
    FILE *pFile;
    DWORD dwData;
    unsigned int iData;

    if (iBytesToRecv == 0)
        iBytesToRecv = 500;

    recv (sSocket, TYPE_STRUCT (wsh), sizeof (WAXSEND_HEADER), 0);
    if (wsh.iSendMode == SEND_FILE)
    {
        char buffer[MAX_PATH];
        wsprintf (buffer, &quot;%s%s&quot;, lpWaxSaveFolder, wsh.lpFile);

        pFile = fopen (buffer, &quot;wb&quot;);
        if (pFile != 0)
        {
            fclose (pFile);
            OutputDebugString (&quot;(ERROR) WAXSOCKET::RecvData () -&gt; fopen () fehlgeschlagen!\n&quot;);
            return WSERROR_FILE;
        }

        iData = wsh.iFileSize;

        char file[4096];

        while(iData &gt; 0)
        {
            dwData = recv (sSocket, file, 4096, 0);
            fwrite (file, dwData, 1, pFile);

            iData -= dwData;
        }

        fclose (pFile);

        return 0;
    }

    lWaxBytes = recv (sSocket, tyData, iBytesToRecv, 0);
    if (lWaxBytes == 0)
    {
        DetachSocket (sSocket);
        return WSERROR_SOCKETCLOSED;
    }
    else if (lWaxBytes == SOCKET_ERROR)
    {
        return WSERROR_RECIEVE;
    }

    return lWaxBytes;
}
</code></pre>
<p>Also ich weiß nicht, wo fopen () ein Problem hat, jedenfalls immer wenn ich eine Datei senden möchte, sagt er mir Datei nicht gefunden. So sieht zum Beispiel eine Pfadangabe aus:</p>
<pre><code>K:\\WinSock\\test.exe
</code></pre>
<p>DIV Ominion</p>
<p>EDIT: Die cpp-Tags funzen nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1379572</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379572</guid><dc:creator><![CDATA[Ominion]]></dc:creator><pubDate>Sun, 07 Oct 2007 10:58:53 GMT</pubDate></item><item><title><![CDATA[Reply to [Datei] fopen () on Sun, 07 Oct 2007 10:50:53 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;stdio.h&gt;
void main()
{
  printf(&quot;CPP-Tags funzen...\n&quot;);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1379589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379589</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Sun, 07 Oct 2007 10:50:53 GMT</pubDate></item><item><title><![CDATA[Reply to [Datei] fopen () on Sun, 07 Oct 2007 10:52:40 GMT]]></title><description><![CDATA[<p>Bei rec, verwendest Du &quot;wsprintf&quot; und &quot;fopen&quot;... da passt was nicht...<br />
Kommen da nicht diverse Compiler-Warnungen???</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1379590</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379590</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Sun, 07 Oct 2007 10:52:40 GMT</pubDate></item><item><title><![CDATA[Reply to [Datei] fopen () on Sun, 07 Oct 2007 10:59:41 GMT]]></title><description><![CDATA[<p>nein, es wird alles ohne warnung oder error compiliert. Aber er hat ja das Problem schon bei Send...</p>
<p>Mfg Ominion</p>
<p>PS: naja, vorhin haben die tags nicht gefunzt...</p>
<p>EDIT: mit den Tags: das lag daran, dass ich einen Teil fett gemacht habe, da streikt er...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1379594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379594</guid><dc:creator><![CDATA[Ominion]]></dc:creator><pubDate>Sun, 07 Oct 2007 10:59:41 GMT</pubDate></item><item><title><![CDATA[Reply to [Datei] fopen () on Sun, 07 Oct 2007 11:01:07 GMT]]></title><description><![CDATA[<p>Vielelicht solltest Du Deine Abfrage rummdrehen?</p>
<pre><code class="language-cpp">if (pFile != 0)
</code></pre>
<p>=&gt;</p>
<pre><code class="language-cpp">if (pFile == 0)
</code></pre>
<p>und dann in dem Block das &quot;fclose&quot; rausmachen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1379599</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379599</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Sun, 07 Oct 2007 11:01:07 GMT</pubDate></item><item><title><![CDATA[Reply to [Datei] fopen () on Sun, 07 Oct 2007 11:05:40 GMT]]></title><description><![CDATA[<p>Hmm, na wehe das ist es^^</p>
<p>Mfg Ominion</p>
<p>EDIT: bringt nichts...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1379601</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379601</guid><dc:creator><![CDATA[Ominion]]></dc:creator><pubDate>Sun, 07 Oct 2007 11:05:40 GMT</pubDate></item><item><title><![CDATA[Reply to [Datei] fopen () on Sun, 07 Oct 2007 11:06:49 GMT]]></title><description><![CDATA[<p>Na, dann wirst Du ums debuggen nicht drum rum kommen <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/1379605</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379605</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Sun, 07 Oct 2007 11:06:49 GMT</pubDate></item><item><title><![CDATA[Reply to [Datei] fopen () on Sun, 07 Oct 2007 11:09:09 GMT]]></title><description><![CDATA[<p>na klasse...dann mus ich denn rotz erstmal wieder ins VS packen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1379607</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379607</guid><dc:creator><![CDATA[Fake oder Echt]]></dc:creator><pubDate>Sun, 07 Oct 2007 11:09:09 GMT</pubDate></item><item><title><![CDATA[Reply to [Datei] fopen () on Sun, 07 Oct 2007 11:12:58 GMT]]></title><description><![CDATA[<p>Maybe ein \r\n?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1379610</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379610</guid><dc:creator><![CDATA[..]]></dc:creator><pubDate>Sun, 07 Oct 2007 11:12:58 GMT</pubDate></item><item><title><![CDATA[Reply to [Datei] fopen () on Sun, 07 Oct 2007 11:13:31 GMT]]></title><description><![CDATA[<p>??? habe ich was verpasst?</p>
<p>Mfg Ominion</p>
<p>EDIT: @....: was soll das nüten bzw wo hin damit?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1379611</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1379611</guid><dc:creator><![CDATA[Ominion]]></dc:creator><pubDate>Sun, 07 Oct 2007 11:13:31 GMT</pubDate></item></channel></rss>