title: Serial Port WriteFile() fails with E_INVALIDARG
body: <p>I am trying to write a program to communicate to my device through USB connected to COM7, but I am having problems writing to it.</p>
  
  <p>Here is how I open the handle </p>
  
  <pre><code>hPort = CreateFile(
      "COM7",         // address of name of the communications device
      GENERIC_READ|GENERIC_WRITE, // access (read-write) mode
      0,                  // share mode
      NULL,                   // address of security descriptor
      OPEN_EXISTING,      // how to create
      FILE_FLAG_OVERLAPPED, // file attributes
      NULL                    // handle of file with attributes to copy
  );
  
  //Get COM Settings
  dcb.DCBlength = sizeof(DCB);
  //Baud Rate COMBO_BAUD
  i = SendDlgItemMessage(hWnd, COMBO_BAUD, LB_GETCURSEL, (WPARAM)0, (LPARAM)0);
  dcb.BaudRate = 9600; //BaudInt[i];
  //Byte Size COMBO_BITS
  i = SendDlgItemMessage(hWnd, COMBO_BITS, LB_GETCURSEL, (WPARAM)0, (LPARAM)0);
  dcb.ByteSize = 8; //BitsInt[i];
  //Parity COMBO_PARITY
  i = SendDlgItemMessage(hWnd, COMBO_PARITY, LB_GETCURSEL, (WPARAM)0, (LPARAM)0);
  dcb.Parity = NOPARITY; //ParityInt[i];
  //Stop Bits COMBO_STOP
  i = SendDlgItemMessage(hWnd, COMBO_STOP, LB_GETCURSEL, (WPARAM)0, (LPARAM)0);
  dcb.StopBits = ONESTOPBIT; //StopInt[i];
  
  if (!::SetCommState (hPort,&amp;dcb))
  {
      MessageBox(NULL, "Failed to Set COM settings", "Status", MB_OK | MB_ICONINFORMATION);
      return;
  }
  
  COMMTIMEOUTS comTimeOut;                
  comTimeOut.ReadIntervalTimeout = 3000;
  comTimeOut.ReadTotalTimeoutMultiplier = 3000;
  comTimeOut.ReadTotalTimeoutConstant = 2000;
  comTimeOut.WriteTotalTimeoutMultiplier = 3000;
  comTimeOut.WriteTotalTimeoutConstant = 2000;
  SetCommTimeouts(hPort,&amp;comTimeOut);
  </code></pre>
  
  <p>And how I write to the handle</p>
  
  <pre><code>BOOL success = WriteFile(hPort, "meas:volt?\n", sizeof("meas:volt?\n"), &amp;dwRet, NULL);
  DWORD error = GetLastError();
  HRESULT result = HRESULT_FROM_WIN32(error);
  </code></pre>
  
  <p>I keep getting "E_INVALIDARG One or more arguments are invalid" as the error.
  Can anyone help me figure this problem out? I am using usbser.sys (serial port driver)</p>