title: Why do I get an access violation when using the ReadFile() function?
body: <p>I have been trying to read from a file and I am using the Windows API function <code>ReadFile()</code>. I have used the following code:</p>
  
  <pre><code>int main()
  {
      LPDWORD bytesRead = 0;
      HANDLE hFile = CreateFile("TestFile.txt", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_ALWAYS, 0, 0);
  
      char Data[600];
  
      ReadFile(hFile, Data, 10, bytesRead, 0);
  
      cout &lt;&lt; Data;
      cin.get();
  }
  </code></pre>
  
  <p>When I execute this code, it throws an access violation!</p>
  
  <p>Why is this? I feel that I am using <code>ReadFile()</code> correctly - but I am probably wrong. How can I fix this error (how to use <code>ReadFile()</code> properly)?</p>