title: P/Invoke call just stops
body: <p>I'm trying to write data to a serial port via P/Invoke (explicitly not with the SerialPort-class). Here's what I have so far:</p>
  
  <pre><code>[DllImport("kernel32", SetLastError = true)]
  static extern IntPtr CreateFile(string filename,       // file name
                                  uint desiredAccess,    // read? write?
                                  uint shareMode,        // sharing
                                  uint attributes,       // SecurityAttributes pointer
                                  uint creationDisposition,
                                  uint flagsAndAttributes,
                                  uint templateFile);
  
  [DllImport("kernel32", SetLastError = true)]
  static extern bool WriteFile(IntPtr hFile,               // handle to file
                               byte[] lpBuffer,            // data buffer
                               uint nBytesToWrite,         // number of bytes to write
                               out uint nBytesWritten,     // number of bytes written
                               [In] ref NativeOverlapped overlapped); // overlapped buffer
  
  const uint OPEN_EXISTING = 3;
  
  _portHandle = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
  uint bytesWritten;
  var buffer = Encoding.ASCII.GetBytes("foo\r");
  var overlapped = new NativeOverlapped();
  WriteFile(_portHandle, buffer, (uint)buffer.Length, out bytesWritten, ref overlapped);
  </code></pre>
  
  <p>I get a _portHandle != -1 and can call WriteFile. But after the call, it does nothing. I can wait forever in VS-debug mode and wait for the call to return. Also, no exception is thrown.</p>
  
  <p>Any kernel32.dll-masters out there who can help me?</p>