title: WriteFile Fails with error code 87 when writing to USB
body: <p>I am trying to communicatate with a USB device on Windows 7. After I find the device using the vendor and product ID I open it with the following command</p>
  
  <pre><code>dev-&gt;device_handle = CreateFile( path, (GENERIC_WRITE | GENERIC_READ), 
                      (FILE_SHARE_READ|FILE_SHARE_WRITE),
                      (LPSECURITY_ATTRIBUTES)NULL, 
                      OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
  </code></pre>
  
  <p>Then I do a write into the device using </p>
  
  <pre><code>res = WriteFile(dev-&gt;device_handle, buf, length, &amp;bytes_written, &amp;ol); 
  </code></pre>
  
  <p>where length is 64.</p>
  
  <p>My device can read and write 64 bytes of data in this interface and this has been tested on Linux and using another tool in windows (I dont have the source of the tool).</p>
  
  <p>The WriteFile function gives me an error code of 87. which is invalid parameters.</p>
  
  <p>Could anybody please point me out the mistake I am making.</p>
  
  <p>P.S. I have already analysed the question 
  <a href="https://stackoverflow.com/questions/9184439/writefile-returning-error-code-87">WriteFile returning error code 87</a> </p>
  
  <p>I have made some debug logs </p>
  
  <pre><code>--------------------------------------------------
  Before write call
  dev_handle:152
  buf:2293463
  length:65
  bytes_written:0
  overlap:0
  --------------------------------------------------
  --------------------------------------------------
  After write call
  dev_handle:152
  buf:2293463
  length:65
  bytes_written:0
  overlap:259
  --------------------------------------------------
  Last Error: 87
  </code></pre>