title: Invalid handle error from ReadFileEx using valid handle from CreateFile
body: <p>The problem I'm having: CreateFile returns a handle of 0x194.  ReadFileEx is saying that this handle is invalid.  (Error 6.)  Any ideas?  The argument passed in is "C:\testfile.txt", which is a valid text file I made in Notepad.  Despite being a C++ programmer for the last 12 years, this is my first time writing anything with "windows.h" or threads.</p>
  
  <pre><code>#include "stdafx.h"
  #include "stdio.h"
  #include "windows.h"
  
  using namespace System;
  
  int main(int argc, char **argv)
  {
      if (argc != 2)
      {
          printf("To display a file, you must enter the filename as the only command argument.");
          scanf("\n");
          return 0;
      }
      HANDLE file;
      int nameLen = (strlen(argv[1]) + 1);
      wchar_t *filename = new wchar_t[nameLen];
      if (filename == 0)
      {
          printf("To display a file, you must enter the filename as the only command argument.");
          scanf("\n");
          return 0;
      }
      memset(filename, 0, nameLen);
      ::MultiByteToWideChar(CP_ACP, NULL, argv[1], -1, filename, nameLen);
      file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
      if (file == NULL)
      {
          printf("A valid filename is required.");
          scanf("\n");
          return 0;
      }
      char *buffer;
      buffer = new char[1024];
      OVERLAPPED overlapped;
      overlapped.Offset = overlapped.OffsetHigh = 0;
      ReadFileEx(file, &amp;buffer, 1024, &amp;overlapped, NULL);
      WaitForSingleObject(&amp;file, 0);
      if (GetLastError() != ERROR_SUCCESS)
      {
          printf("A valid file is required., Error: %d", GetLastError());
          scanf("\n");
          return 0;
      }
      printf("%s", buffer);
      scanf("\n");
      delete buffer;
      return 0;
  }
  </code></pre>