1.wchar *转 char *
char *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);
return psText;
}wchar_t *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;}
return pwText;
}VC++/MFC中WCHAR *转化为char *的方法,即宽字符和普通字符互相转化【已解决】
原文:http://blog.csdn.net/zwc2xm/article/details/42921999