Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As Martin says, first fix your error handling</p> <pre><code>const BOOL result = ReadFileEx(...); const DWORD lastError = GetLastError(); if (lastError != ERROR_SUCCESS) { fprintf(stderr, "err %d\n", lastError); } </code></pre> <p>Note that Martin is incorrect about his assumption that you shouldn't call <code>GetLastError()</code> for success returns from <code>ReadFileEx()</code>, though this is a bit of a special case... From the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365468%28v=vs.85%29.aspx" rel="nofollow noreferrer">MSDN docs</a>:</p> <blockquote> <p>When using ReadFileEx you should check GetLastError even when the function returns "success" to check for conditions that are "successes" but have some outcome you might want to know about. For example, a buffer overflow when calling ReadFileEx will return TRUE, but GetLastError will report the overflow with ERROR_MORE_DATA. If the function call is successful and there are no warning conditions, GetLastError will return ERROR_SUCCESS.</p> </blockquote> <p>But that doesn't solve your problem, it just makes your example code more correct...</p> <p>The problem is that <code>ReadFileEx()</code> does asynchronous file reading using a completion routine and you're trying to do asynchronous file reading using an I/O Completion Port. For that you should use <code>ReadFile()</code>. See <a href="https://stackoverflow.com/questions/754068/win32-overlapped-i-o-completion-routines-or-waitformultipleobjects">this answer</a> for why I feel that IOCP is the better route to take and why completion routines are a bit nasty...</p> <p>So, simply change your <code>ReadFileEx()</code> call to a <code>ReadFile()</code> call and your problem will go away and the code will post a completion to the IOCP when the read completes...</p> <pre><code>ReadFile(file_handle,(LPVOID)read_data,1024,&amp;overlapped); </code></pre> <p>and you're done.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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