<?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[WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt;]]></title><description><![CDATA[<p>Hallo,<br />
ich habe eine Frage bezüglich des Schreibens in eine Datei mit der WriteFile-Methode aus der windows.h.<br />
Ich muss mit einem eigenen Buffer in eine Textdateischreiben, dies wäre kein Problem wenn ich bei CreateFile nicht denn System-Cache/Buffer abstellen müsste. Da ich das nun aber muss, kann ich nur ein vielfaches der Sektorgröße(512 Bytes) auf einmal schreiben. Wenn ich jetzt aber nur einen String wie &quot;Hallo Test&quot; in eine Textdateischreiben möchte habe ich ein Problem. Da der Rest mit [NULL] beschrieben wird. Genau das möchte ich aber nicht. Bisher sieht mein Test-Code so aus:</p>
<pre><code>DWORD dwBytesWritten = 0;
char DataBuffer[] = &quot;This is a test string.&quot;;
char filename[] = &quot;C:\\out.txt&quot;;
hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING,	NULL);

if (hFile == INVALID_HANDLE_VALUE) {
 cout &lt;&lt; &quot;Could not open file (error &quot; &lt;&lt; GetLastError() &lt;&lt; &quot;)&quot; &lt;&lt; endl;
 return;
}

cout &lt;&lt; WriteFile(hFile, DataBuffer, 512, &amp;dwBytesWritten, NULL) &lt;&lt; endl;
</code></pre>
<p>Sobald ich nun die 512 in zum Beispiel die Länge des Strings ändere kann schlägt die WriteFile-Funktion fehl.</p>
<p>Hat jemand einen Tipp oder eine Idee?</p>
<p>Mit freundlichen Grüßen<br />
Najjannaj</p>
<p>P.S. Ich muss sowohl die Windows.h benutztn und die WriteFile Methode, leider keine andere Wahl.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/224085/writefile-file_flag_no_buffering-lt-windows-h-gt</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 20:05:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/224085.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 05 Oct 2008 13:40:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Sun, 05 Oct 2008 13:52:51 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe eine Frage bezüglich des Schreibens in eine Datei mit der WriteFile-Methode aus der windows.h.<br />
Ich muss mit einem eigenen Buffer in eine Textdateischreiben, dies wäre kein Problem wenn ich bei CreateFile nicht denn System-Cache/Buffer abstellen müsste. Da ich das nun aber muss, kann ich nur ein vielfaches der Sektorgröße(512 Bytes) auf einmal schreiben. Wenn ich jetzt aber nur einen String wie &quot;Hallo Test&quot; in eine Textdateischreiben möchte habe ich ein Problem. Da der Rest mit [NULL] beschrieben wird. Genau das möchte ich aber nicht. Bisher sieht mein Test-Code so aus:</p>
<pre><code>DWORD dwBytesWritten = 0;
char DataBuffer[] = &quot;This is a test string.&quot;;
char filename[] = &quot;C:\\out.txt&quot;;
hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING,	NULL);

if (hFile == INVALID_HANDLE_VALUE) {
 cout &lt;&lt; &quot;Could not open file (error &quot; &lt;&lt; GetLastError() &lt;&lt; &quot;)&quot; &lt;&lt; endl;
 return;
}

cout &lt;&lt; WriteFile(hFile, DataBuffer, 512, &amp;dwBytesWritten, NULL) &lt;&lt; endl;
</code></pre>
<p>Sobald ich nun die 512 in zum Beispiel die Länge des Strings ändere kann schlägt die WriteFile-Funktion fehl.</p>
<p>Hat jemand einen Tipp oder eine Idee?</p>
<p>Mit freundlichen Grüßen<br />
Najjannaj</p>
<p>P.S. Ich muss sowohl die Windows.h benutztn und die WriteFile Methode, leider keine andere Wahl.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1593709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1593709</guid><dc:creator><![CDATA[najjannaj]]></dc:creator><pubDate>Sun, 05 Oct 2008 13:52:51 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Sun, 05 Oct 2008 19:05:07 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-14199.html" rel="nofollow">Phoemuex</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-4.html" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1593847</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1593847</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Sun, 05 Oct 2008 19:05:07 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Sun, 05 Oct 2008 22:18:24 GMT]]></title><description><![CDATA[<p>Mit SetEndOfFile kannst du die Datei kürzen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1593918</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1593918</guid><dc:creator><![CDATA[oq]]></dc:creator><pubDate>Sun, 05 Oct 2008 22:18:24 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Mon, 06 Oct 2008 00:30:56 GMT]]></title><description><![CDATA[<p>Wieso willst du unbedingt FILE_FLAG_NO_BUFFERING nutzen? Windows buffered doch selber gar nicht so schlecht?</p>
<p>Oder willst du eigentlich das hier: FILE_FLAG_WRITE_THROUGH (&quot;Write operations will not go through any intermediate cache, they will go directly to disk.&quot;)?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1593941</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1593941</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Mon, 06 Oct 2008 00:30:56 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Mon, 06 Oct 2008 08:31:23 GMT]]></title><description><![CDATA[<p>Ich muss laut Vorgabe &quot;FILE_FLAG_NO_BUFFERING&quot; benutzen, daher komme ich da nicht drum herum. Gibt es noch eine andere Möglichkeit?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1594050</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1594050</guid><dc:creator><![CDATA[najjannaj]]></dc:creator><pubDate>Mon, 06 Oct 2008 08:31:23 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Mon, 06 Oct 2008 09:21:28 GMT]]></title><description><![CDATA[<blockquote>
<p>Ich muss laut Vorgabe</p>
</blockquote>
<p>Warum so eine Vorgabe?<br />
Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1594062</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1594062</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Mon, 06 Oct 2008 09:21:28 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Mon, 06 Oct 2008 09:32:05 GMT]]></title><description><![CDATA[<p>Studiums-Vorgabe des Professors mit Notenabzug für mit internem Buffering...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1594072</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1594072</guid><dc:creator><![CDATA[najjannaj]]></dc:creator><pubDate>Mon, 06 Oct 2008 09:32:05 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Mon, 06 Oct 2008 17:48:19 GMT]]></title><description><![CDATA[<p>Dann musst du wohl wie schon vorgeschlagen wurde mehr schreiben als nötig und dann mit SetEndOfFile() die Datei auf die richtige Länge kürzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1594399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1594399</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Mon, 06 Oct 2008 17:48:19 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Mon, 06 Oct 2008 17:55:47 GMT]]></title><description><![CDATA[<p>Hallo,<br />
SetEndOfFile() hat ja keine Parameter, daher verstehe ich noch nicht so ganz wie cih dann zum beispiel nach 50Zeichen abschneiden soll, da ich ja immer 512Byte auf einmal schreibe. Kann mir das jemand näher erklären?<br />
Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1594403</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1594403</guid><dc:creator><![CDATA[najjannaj]]></dc:creator><pubDate>Mon, 06 Oct 2008 17:55:47 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Mon, 06 Oct 2008 18:34:24 GMT]]></title><description><![CDATA[<p>Du setzt vorher den Filepointer auf die entsprechende Stelle:<br />
<a href="http://msdn.microsoft.com/en-us/library/aa365541(VS.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa365541(VS.85).aspx</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1594423</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1594423</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Mon, 06 Oct 2008 18:34:24 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Wed, 08 Oct 2008 10:23:07 GMT]]></title><description><![CDATA[<p>Leider kann ich mit SetFilePointer auch immer nur 512(oder ein vielfaches davon) nach vorne oder nach hinten springen.. daher bringt mir das leider nichts <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> Noch andere Ideen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1595391</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1595391</guid><dc:creator><![CDATA[najjannaj]]></dc:creator><pubDate>Wed, 08 Oct 2008 10:23:07 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Wed, 08 Oct 2008 11:21:56 GMT]]></title><description><![CDATA[<p>Hier beisst sich die Katze in den Schwanz. Wenn Du kein Buffering verwendest dann kanst Du eben nur auf den Boundaries navigieren.</p>
<p>Lesen bildet <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="😉"
    /><br />
<a href="http://msdn.microsoft.com/en-us/library/aa365541(VS.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa365541(VS.85).aspx</a></p>
<blockquote>
<p>If an application calls SetFilePointer with distance to move values that result in a position not sector-aligned and a handle that is opened with FILE_FLAG_NO_BUFFERING, the function fails, and GetLastError returns ERROR_INVALID_PARAMETER.</p>
</blockquote>
<p>Es macht auch NULL-Sinn FILE_FLAG_NO_BUFFERING zu verwenden und dann eine nicht alignierte Dateigröße zu nutzen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1595457</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1595457</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Wed, 08 Oct 2008 11:21:56 GMT</pubDate></item><item><title><![CDATA[Reply to WriteFile + [FILE_FLAG_NO_BUFFERING] + &amp;lt;windows.h&amp;gt; on Wed, 08 Oct 2008 15:50:28 GMT]]></title><description><![CDATA[<p>Okay, hat sich erledigt, habe mit dem Prof. gesprochen und ich soll die restliche Datei einfach mit Whitspaces füllen.. es wäre einfach nur um denn Umgang mit Buffern zu verstehen. Danke an alle!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1595673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1595673</guid><dc:creator><![CDATA[najjannaj]]></dc:creator><pubDate>Wed, 08 Oct 2008 15:50:28 GMT</pubDate></item></channel></rss>