错误 C2664:"wsprintfW":无法将参数 1 从"字符 *"转换为"LPWSTR"
error C2664: 'wsprintfW' : cannot convert parameter 1 from 'char *' to 'LPWSTR'
我从VC6项目复制了一些代码到vc++2010项目,但代码无法编译。错误是'wsprintfW':无法将参数1从'char *'转换为'LPWSTR',问题代码是:
inline bool RingCtrl::BuildPathAndName(char* pBuf, int bufSize, int8 priority, int idxNumber) const
{
wsprintf(pBuf, "%s\R%u%06x.DAT", _directory, (int)priority, idxNumber);
return true;
}
wsprintf
在wmcommn.h
中定义如下:
WINUSERAPI
int
WINAPIV
wsprintfA(
__out LPSTR,
__in __format_string LPCSTR,
...);
WINUSERAPI
int
WINAPIV
wsprintfW(
__out LPWSTR,
__in __format_string LPCWSTR,
...);
#ifdef UNICODE
#define wsprintf wsprintfW
#else
#define wsprintf wsprintfA
#endif
您正在构建您的程序与UNICODE
定义(默认在vc++ 2010),而它没有在VC6中定义。当UNICODE
被定义时,wsprintf
的第一个参数是wchar_t*
而不是char*
,第二个参数是const wchar_t*
而不是const char*
。
简单的解决方案是在RingCtrl::BuildPathAndName
中显式地调用wsprintfA
而不是wsprintf
,但在这种情况下,您将遇到Unicode文件名的问题。你可能会有很多其他类似的错误连接到UNICODE
和_UNICODE
,所以你可能想改变你的项目设置在vc++ 2012:项目属性->通用->字符集->使用多字节字符集。
正确的解决方案是从char*
移动到wchar_t*
(或者更好地移动到TCHAR*
),但这可能需要很多努力。
相关文章:
- C++字符*缓冲区的大小
- HEX值到wchar_t字符(UTF-8)的转换
- 为什么 Serial.println(<char[]>);返回随机字符?
- 我的字符计数代码计算错误.为什么
- 字符串-C++后显示的随机字符
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 如何在C++中从字符串中分割字符
- 为什么msgrcv()将垃圾字符馈送到缓冲区
- 指向指向字符数组的指针数组的指针
- 如何用转义符替换字符串中的所有特殊字符
- 为什么 sscanf 无法从一个字符串中读取uint64_t和字符?
- 比较字符数组
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 如何在C++中确定文本文件中的元素是字符还是数字
- 如何将一个ostringstream十六进制字符串字符对转换为单个unit8t等价的二进制值
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- 如何连接字符* 和 LPWSTR 字符串
- 错误 C2664:"wsprintfW":无法将参数 1 从"字符 *"转换为"LPWSTR"