title: GetLastError() return value 2
body: <p>A very basic question, I cannot understand why I get error 2 with the simplest example of windows system programming book.
  I post the source:</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;stdio.h&gt;
  #define BUF_SIZE 65536
  
  int main(int argc, LPTSTR argv[]){
  
  HANDLE fileIN, fileOUT;
  DWORD nIn, nOut;        //numero di byte LETTI/SCRITTI
  CHAR buffer[BUF_SIZE];
  
  if(argc!=3){
      printf("Usage: %s file1 file2\n", argv[0]);
      return 1;
  }
  //printf("%s\n",argv[0]);
  //printf("%s\n",argv[1]);
  //printf("%s\n",argv[2]);
  
  fileIN = CreateFileW(argv[1],GENERIC_READ,FILE_SHARE_READ,NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  if(fileIN == INVALID_HANDLE_VALUE){
      printf("Invalid handle value, error %x\n", GetLastError());
      return 2;
  }
  fileOUT = CreateFileW(argv[2], GENERIC_WRITE,0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL);
  if(fileOUT == INVALID_HANDLE_VALUE){
      printf("Invalid handle value, error %x\n", GetLastError());
      return 3;
  }
  
  while(ReadFile(fileIN, buffer, BUF_SIZE, &amp;nIn, NULL) &amp;&amp; nIn &gt; 0){
      WriteFile(fileOUT, buffer, nIn, &amp;nOut, NULL);
      if(nIn != nOut){
          printf("During copy, error %x\n", GetLastError());
      return 4;
      }
  }
  CloseHandle(fileIN);
  CloseHandle(fileOUT);
  return 0;
  }
  </code></pre>
  
  <p>Can you help me please? I'm using MS VSc++ 2010 SP 1
  Thank you all in advange
  N.</p>