title: Writing synchronously to a file opened with FILE_FLAG_OVERLAPPED
body: <p>I have opened a file using </p>
  
  <pre><code>HANDLE handle= 
      CreateFileW(
          fileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 
          FILE_FLAG_OVERLAPPED, NULL);
  </code></pre>
  
  <p>The file handle is then used for asynchronous read operations:</p>
  
  <pre><code>ReadFile(handle, buffer, 1, NULL, &amp;overlapped);
  </code></pre>
  
  <p>This works. However, I want to do a synchronous write now. <a href="http://msdn.microsoft.com/en-us/library/aa365747%28v=vs.85%29.aspx" rel="nofollow"><code>WriteFile</code></a> documentation states that </p>
  
  <blockquote>
    <p>If hFile was opened with FILE_FLAG_OVERLAPPED, the following conditions are in effect:<br>
    • The lpOverlapped parameter must point to a valid and unique OVERLAPPED structure, otherwise the function can incorrectly report that the write operation is complete.</p>
  </blockquote>
  
  <p>When the <code>lpOverlapepd</code> parameter is omitted, <code>ERROR_INVALID_PARAMETER</code> is returned by <code>GetLastError()</code>. Opening two handles, one for reading and one for writing does also not work since the second handle produces a <code>ERROR_ACCESS_DENIED</code> error.</p>
  
  <p>How can I open the file for asynchronous reads and synchronous writes? I don't want to increase code complexity unnecessarily. </p>