title: How to use Win32 API to talk to a com port (RS232)
body: <p>I am trying to use win32 API to talk to a com port
  I found this 
  <a href="http://www.robbayer.com/files/serial-win.pdf" rel="nofollow">http://www.robbayer.com/files/serial-win.pdf</a></p>
  
  <pre><code>hSerial = CreateFile("COM1",
  GENERIC_READ | GENERIC_WRITE,
  0,
  0,
  OPEN_EXISTING,
  FILE_ATTRIBUTE_NORMAL,
  0);
  </code></pre>
  
  <p>I use VS2008 and it complains 
  error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char [5]' to 'LPCWSTR'</p>
  
  <p>OK, I guess it doesn't like "COM1" to be char* type, </p>
  
  <p>I tried casting it LPCWSTR("COM1"), then it compiles with no problem.</p>
  
  <p>However, it returns "ERROR opening serial port -1", so it doesn't find the com port successfully. I guess direct casting is not the right way?</p>
  
  <p>Please tell me what I should do to make this work.</p>
  
  <p>the msdn is not that helpful
  <a href="http://msdn.microsoft.com/en-us/library/ms810467.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms810467.aspx</a></p>
  
  <p>I don't know what the "gszPort" means there</p>