title: Which ReadFile parameter in this code is incorrect? (Error code 87)
body: <p>(<strong>Edit:</strong> I didn't exclude any code except the headers and the main() function's brackets. Nothing is written between lines of code listed here.)</p>
  
  <p>.</p>
  
  <p>I used the ReadFile function to read this COM3 port (which returned no INVALID_HANDLE_VALUE or ERROR_FILE_NOT_FOUND):</p>
  
  <pre><code>LPCTSTR portName = "COM3" ;
  
  HANDLE hSerial;
  hSerial = CreateFile(portName,
                       GENERIC_READ | GENERIC_WRITE,
                       0,    // exclusive access
                       NULL, // default security attributes
                       OPEN_EXISTING,
                       FILE_FLAG_OVERLAPPED,
                       NULL);
  </code></pre>
  
  <p>And the ReadFile function in question uses following parameters:</p>
  
  <pre><code>DWORD n = 512 ;
  char szBuff[n] = {0};
  DWORD dwBytesRead = 0;
  
  if(!ReadFile(hSerial, szBuff, n, &amp;dwBytesRead, NULL))
  {
      cout &lt;&lt; "ReadFile error. Error code: " &lt;&lt; GetLastError() &lt;&lt; endl ;
      cin.get() ;
      return 0 ;
  }
  </code></pre>
  
  <p>What changes should I introduce to cause the read to succeed?</p>
  
  <p>(I searched through the function's documentation and other StackOverflow questions, tested lots of things, but couldn't find an answer.)</p>