C++类型转换 const char *转LPWSTR
2018-06-30 本文已影响0人
刘千予
/******************************************************************************************
Function: ConvertCharToLPWSTR
Description: const char *转LPWSTR
Input: str:待转化的const char *类型字符串
Return: 转化后的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;
}