1.wchar *转 char *
string wtoc(wchar_t *wText)
{
DWORD dwNum = WideCharToMultiByte(CP_ACP, NULL, wText, -1, NULL, 0, NULL, FALSE);//把第五个参数设成NULL的到宽字符串的长度包括结尾符
char *psText = NULL;
psText = new char[dwNum];
if (!psText)
{
delete[]psText;
psText = NULL;
}
WideCharToMultiByte(CP_ACP, NULL, wText, -1, psText, dwNum, NULL, FALSE);
string ret = psText;
delete []psText;
return ret;
}
2. char *转wchar *
wstring ctow(char *sText)
{
DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, sText, -1, NULL, 0);//把第五个参数设成NULL的到宽字符串的长度包括结尾符
wchar_t *pwText = NULL;
pwText = new wchar_t[dwNum];
if(!pwText)
{
delete []pwText;
pwText = NULL;
}
unsigned nLen = MultiByteToWideChar (CP_ACP, 0, sText, -1, pwText, dwNum+10);
if (nLen >= 0)
{pwText[nLen] = 0;}
wstring ret = pwText;
delete []pwText;
return ret ;
}
宽字符(LPCWSTR)和普通字符(LPCSTR)互相转化【已解决】