Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your buffer is the size of 10 ints, which is 40 bytes on Windows. You are trying to write 100,000 bytes from that buffer. That is undefined behaviour, a buffer overrun. Hence the access violation.</p> <p>You must not pass a value greater than <code>sizeof(test_buffer)</code>, i.e. <code>40</code>, to the <code>nNumberOfBytesToWrite</code> parameter of <code>WriteFile</code>.</p> <p>You'll need to write this file in a loop, writing 40 bytes at a time, until you have written as much as you need. Perhaps something like this:</p> <pre><code>BOOL bSuccess = TRUE; DWORD bytesRemaining = 100000; while (bSuccess &amp;&amp; bytesRemaining&gt;0) { DWORD bytesToWrite = std::min(sizeof(test_buffer), bytesRemaining); DWORD bytesWritten; bSuccess = WriteFile(hFile, test_buffer, bytesToWrite, &amp;bytesWritten, NULL); bytesRemaining -= bytesToWrite; } if (!bSuccess) { //handle error; } </code></pre> <p>Writing 40 bytes at a time is pretty slow. You'll find it more efficient to write a few KB with each call to <code>WriteFile</code>.</p> <p>Note that you aren't allowed to pass <code>NULL</code> to the <code>lpNumberOfBytesWritten</code> parameter if you also pass <code>NULL</code> to <code>lpOverlapped</code>, as you do here. From the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365747.aspx" rel="nofollow">documentation</a>:</p> <blockquote> <p><em>lpNumberOfBytesWritten</em> [out, optional]</p> <p>......</p> <p>This parameter can be NULL only when the lpOverlapped parameter is not NULL.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload