1.字符串要使用_T();
例如 在VC6.0中MessageBox("串口见识失败");
但是在VS2005中需要给位 MessageBox(_T("串口见识失败"));
2.sprintf() 函数使用问题,在VS2005中更建议使用的是sprintf_s()函数来替代sprintf() 函数。也可以使用
#pragma warning (disable : 4996) 来屏蔽警告
3.在VC中
m_hComm = CreateFile(szPort,
// communication port string (COMX)
GENERIC_READ | GENERIC_WRITE,
// read/write types
0,
// comm devices must be opened with
NULL,
// no security attributes
OPEN_EXISTING,
// comm devices must use OPEN_EXISTING
FILE_FLAG_OVERLAPPED,
// Async I/O
0);
// template must be 0 for comm devices
在VS2005中提示错误 error C2664: “CreateFileW”: 不能将参数 1 从“char *”转换为“LPCWSTR”
解决方法 在变量前加上(LPCWSTR)强制转换
m_hComm = CreateFile((LPCWSTR)szPort,
// communication port string (COMX)
GENERIC_READ | GENERIC_WRITE,
// read/write types
0,
// comm devices must be opened with e
NULL,
// no security attributes
OPEN_EXISTING,
// comm devices must use OPEN_EXISTING
FILE_FLAG_OVERLAPPED,
// Async I/O
0);
// template must be 0 for comm devices
会出现很多这样的问题,最通常的该法是设置字符集格式为未设置
在项目--属性--配置熟悉--常规--字符集--未设置