CString 转为 LPSTR类型 问题
CString Str =_T("消息处理程序");
LPSTR lps = (LPSTR)(LPCSTR)Str ; //错误 无法从“CString”转换为“LPCSTR”
LPSTR lps = (LPSTR)LPCTSTR(Str); //没提示错误 但值是乱码 坢o`Ytz廭
LPSTR lps=(LPSTR)Str.GetBuffer(Str.GetLength()); //没提示错误 但值是乱码 坢o`Ytz廭
LPSTR lps = Str.GetBuffer(0); //错误 无法从“wchar_t *”转换为“LPSTR”
LPSTR lps
strcpy(lps,(LPCTSTR) Str ); //错误 “strcpy”: 不能将参数 2 从“LPCTSTR”转换为“const char *” 上面的方法都出错,请问怎么转?
CString Str =_T("消息处理程序");
LPSTR lps = (LPSTR)(LPCSTR)Str ; //错误 无法从“CString”转换为“LPCSTR”
LPSTR lps = (LPSTR)LPCTSTR(Str); //没提示错误 但值是乱码 坢o`Ytz廭
LPSTR lps=(LPSTR)Str.GetBuffer(Str.GetLength()); //没提示错误 但值是乱码 坢o`Ytz廭
LPSTR lps = Str.GetBuffer(0); //错误 无法从“wchar_t *”转换为“LPSTR”
LPSTR lps
strcpy(lps,(LPCTSTR) Str ); //错误 “strcpy”: 不能将参数 2 从“LPCTSTR”转换为“const char *” 上面的方法都出错,请问怎么转?
所以
LPSTR 改成 LPWSTR看看
strcpy 换成 wcscpy 看看
LPCSTR 换成 LPCWSTR 看看
typedef CHAR *LPSTR;LPSTR lps=(LPSTR)Str.GetBuffer(Str.GetLength()); //没提示错误 但值是乱码 坢o`Yt z廭
改成:
LPTSTR lps = (LPTSTR)Str.GetBuffer(0);
这样就是否UNICODE都可以了。最后那个,lps是个野指针,那怎么拷贝。
你把宽字符强制赋值给它是会出错的