1. Convet char* to CString
CODE:
char *p = "Just Only Test" ;
CString str = p ;
VS2005 编译上面的代码会提示如下错误:
error C2440: 'initializing' : cannot convert from 'char *' to 'ATL::CStringT<BaseType,StringTraits>'
解决方法:
(1) 使用MultiByteToWideChar函数,先把字符串编码转换为UNICODE编码,再赋值给CString对象
(2) 使用W2A 宏
MultiByteToWideChar()
函数功能:该函数映射一个字符串到一个宽字符(unicode)的字符串。由该函数映射的字符串没必要是多字节字符组。
函数原型:int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cchMultiByte,
LPWSTR lpWideCharStr, int cchWideChar);
本文详细介绍了如何将char*类型的数据转换为ATL::CStringT类型,并提供了两种解决方案:使用MultiByteToWideChar函数进行编码转换或使用W2A宏实现。详细解释了MultiByteToWideChar函数的功能及用法。
1989

被折叠的 条评论
为什么被折叠?



