title: Reading binary file using Win32 API
body: <p>I am trying to read a binary file and write to a different place. </p>
  
  <p>But the code displays only the first bit - "MZ".  According to MSDN, "CreateFile and ReadFile
   do not use parameters to differentiate between text and binary file types." But my code works fine with txt files. </p>
  
  <pre><code>                HANDLE hFile = CreateFile( L"C:\\in.exe", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); 
                  if (hFile != INVALID_HANDLE_VALUE) 
                  { 
                      char lpBuffer[2000] = "";
                      DWORD dwBytesRead = 0;
                      DWORD dwBytesWritten = 0;
  
                      HANDLE hTest = CreateFile(L"D:\\out.exe", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, NULL, NULL);  
                      ReadFile(hFile, lpBuffer, sizeof(lpBuffer), &amp;dwBytesRead, NULL); 
                      WriteFile(hTest, &amp;lpBuffer[0], dwBytesRead, &amp;dwBytesWritten, NULL);
  
                      CloseHandle(hFile); 
                      CloseHandle(hTest);
                  }   
  </code></pre>