VS2008中关于“MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCWSTR”的错误解决
2011-07-24 15:20
453 查看
问题:
1>d:\users\yangtse\documents\visual studio 2008\projects\winmain\winmain\54.cpp(27) : error C2440: “=”: 无法从“const char [14]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>d:\users\yangtse\documents\visual studio 2008\projects\winmain\winmain\54.cpp(35) : error C2664: “CreateWindowExW”: 不能将参数 2 从“const char [14]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>d:\users\yangtse\documents\visual studio 2008\projects\winmain\winmain\54.cpp(65) : error C2664: “MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
解决:
MessageBox(hwnd,szChar,"char",0);
MessageBox 在2008中定义为 MessageBoxW W指的是宽字节(也叫UNICODE),有3种方法可解决
①用函数MessageBoxA
②在内容前加上TEXT(对变量无效),如MessageBox(hwnd,szChar,TEXT("char"),0);
③在项目属性->常规中,把Uicode改成多字符段。
PS:在2008中,很多函数的返回值都是宽字节的,所以不一定要用MessageBoxA
在MSDN上可以查到用宽字节的函数和同样功能普通函数的名称。
在6.0中没用宽字节
转载自:http://apps.hi.baidu.com/share/detail/16474815
1>d:\users\yangtse\documents\visual studio 2008\projects\winmain\winmain\54.cpp(27) : error C2440: “=”: 无法从“const char [14]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>d:\users\yangtse\documents\visual studio 2008\projects\winmain\winmain\54.cpp(35) : error C2664: “CreateWindowExW”: 不能将参数 2 从“const char [14]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>d:\users\yangtse\documents\visual studio 2008\projects\winmain\winmain\54.cpp(65) : error C2664: “MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
解决:
MessageBox(hwnd,szChar,"char",0);
MessageBox 在2008中定义为 MessageBoxW W指的是宽字节(也叫UNICODE),有3种方法可解决
①用函数MessageBoxA
②在内容前加上TEXT(对变量无效),如MessageBox(hwnd,szChar,TEXT("char"),0);
③在项目属性->常规中,把Uicode改成多字符段。
PS:在2008中,很多函数的返回值都是宽字节的,所以不一定要用MessageBoxA
在MSDN上可以查到用宽字节的函数和同样功能普通函数的名称。
在6.0中没用宽字节
转载自:http://apps.hi.baidu.com/share/detail/16474815
相关文章推荐
- VS2008中关于“MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCWSTR”的错误解决
- VS2008中关于“MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCWSTR”的错误解决
- 关于vc6.0程序到vs2008下运行时的错误error C2664: “MessageBoxW”: 不能将参数 2 从“char *”转换为“LPCWSTR”
- VS2010 不能将参数 2 从“char [20]”转换为“LPCWSTR”的错误解决
- c++问题之-- MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCWSTR”
- “error C2664: “MessageBoxW”: 不能将参数 2 从“char [300]”转换为“LPCWSTR” 1> 与指向的类型无关;转换要求 reinterpret_”问题解决
- error C2664: MessageBoxW不能将参数2const char*转换为LPCWSTR的解决办法
- C++ 编译错误 “CREATEFILEW”: 不能将参数 _从“CHAR []”转换为“LPCWSTR”
- 关于错误 “strlen”: 不能将参数 1 从“TCHAR [256]”转换为“const char *”
- 下面的程序在VC6通过,在VS2008不能,错误信息都是“不能将参数……从const char[]转换为LPCWSTR”
- error: C2664: 不能将参数从“const char *”转换为“LPCWSTR” 的解决办法
- error: C2664: 不能将参数从“const char *”转换为“LPCWSTR” 的解决办法
- 不能将参数 2 从“const char *”转换为“LPCWSTR” vs 2010解决
- VS2010 C++ 串口编程 错误error C2664: “CreateFileW”: 不能将参数 1 从“const char *”转换为“LPCWSTR”
- 错误不能将参数“**”转换为“LPCWSTR”的解决方法(C++)
- error: C2664: 不能将参数从“const char *”转换为“LPCWSTR” 的解决办法
- 移植性问题のerror C2664: “MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCW...
- error C2664: “MessageBoxW”: 不能将参数 2 从“const char *”转换为“LPCWSTR”
- error: C2664: 不能将参数从“const char *”转换为“LPCWSTR” 的解决办法
- error C2664: “FindFirstFileW”: 不能将参数 1 从“char [261]”转换为“LPCWSTR” 解决