UNICODE字符集
在进行多字节项目转UNICODE过程中经常忘记类型转换,故在此记录方便查找
CString转string
CString c_str;
std::string str;
str = (string)(CStringA)c_str;
string转CString
CString c_str;
std::string str;
c_str= (CString)str.c_str();
string转LPCTSTR
string str;
LPCTSTR lpctstr;
lpctstr = (CString)str.data();
char* 转LPCWSTR
char* str;
LPCWSTR lpcwstr;
lpwtstr = (CString)str;
CString转const char*
CString c_str;
const char* con_ch;
con_ch = (CStringA)c_str;
LPCTSTR转const char*
LPCTSTR lpct;
const char* con_ch;
con_ch = (CStringA)c_str;
char *转LPCWSTR
char* ch;
LPCWSTR lpcw;
lpcw= (CString)ch;
char *转LPTSTR
char* ch;
LPTSTR lpt;
lpt= (LPTSTR)ch;
const char *转LPWSTR
LPWSTR ConvertCharToLPWSTR(const char * szString)
{
int dwLen = strlen(szString) + 1;
int nwLen = MultiByteToWideChar(CP_ACP, 0, szString, dwLen, NULL, 0);//算出合适的长度
LPWSTR lpszPath = new WCHAR[dwLen];
MultiByteToWideChar(CP_ACP, 0, szString, dwLen, lpszPath, nwLen);
return lpszPath;
}