EVC下CreateFile编译错误

 
  1. BOOL InitPort(HWND  pPortOwner, // the owner (CWnd) of the port (receives message)
  2.                            UINT  portnr,        // portnumber (1..4)
  3.                            UINT  baud,          // baudrate
  4.                            char  parity,        // parity 
  5.                            UINT  databits,      // databits 
  6.                            UINT  stopbits,      // stopbits 
  7.                            DWORD dwCommEvents,  // EV_RXCHAR, EV_CTS etc
  8.                            UINT  writebuffersize)   // size to the writebuffer
  9. {
  10.         HANDLE m_hComm ;
  11.         char *szPort = new char[50];
  12.     char *szBaud = new char[50];
  13.     sprintf(szPort, "COM%d", portnr);
  14.     sprintf(szBaud, "baud=%d parity=%c data=%d stop=%d", baud, parity, databits, stopbits);
  15.     // get a handle to the port
  16.     m_hComm = CreateFileW(szPort,                       // communication port string (COMX)
  17.                          GENERIC_READ | GENERIC_WRITE,  // read/write types
  18.                          0,                             // comm devices must be opened with exclusive access
  19.                          NULL,                          // no security attributes
  20.                          OPEN_EXISTING,                 // comm devices must use OPEN_EXISTING
  21.                          0,                             // Async I/O
  22.                          NULL); 
  23. }       

上面的代码在VS2005下编译没有错误,CreateFileW要改为CreateFileA。

 

移到WINCE下就出了小错误。

 

环境:EVC4.0

 

编译错误:

error C2664: 'CreateFileW' : cannot convert parameter 1 from 'char *' to 'const unsigned short *'

 

解决办法:强制转换

m_hComm = CreateFileW((LPCWSTR)szPort, 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值