VC++6.0到VS2005初次使用遇到的问题

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

会出现很多这样的问题,最通常的该法是设置字符集格式为未设置

在项目--属性--配置熟悉--常规--字符集--未设置




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值