Ansi转Unicode,Unicode转Ansi

 //ANSI转unicode
wchar_t* AnsiToUnicode(char *str)
{
	DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
	wchar_t *pwText;
	pwText = new wchar_t[dwNum];
	if(!pwText)
	{
		delete []pwText;
	}
	MultiByteToWideChar (CP_ACP, 0, str, -1, pwText, dwNum);
	return pwText;
}wchar_t *strUnicode = AnsiToUnicode(str);
OutputDebugStringW(strUnicode);


 

//Unicode转ansi
wchar_t wText[20] = {L"宽字符转换实例!"};
 DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE);
 char *psText;
 psText = new char[dwNum];
 if(!psText)
 {
    delete []psText;
 }
 WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE);
 delete []psText;


 

你可能感兴趣的:(Ansi转Unicode,Unicode转Ansi)