Wednesday, October 28, 2009

// ANSI(char) to Unicode(WCHAR)
char* pAnsi = "你好";
int nIndex = MultiByteToWideChar(CP_ACP, 0, pAnsi, -1, NULL, 0);
TCHAR *pUnicode = new TCHAR[nIndex + 1];
MultiByteToWideChar(CP_ACP, 0, pAnsi, -1, pUnicode, nIndex);
delete pUnicode;


// Unicode(WCHAR) to ANSI(char)
TCHAR *pUnicode = _T("你好");
int nIndex = WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, NULL, 0, NULL, NULL);
char *pAnsi = new char[nIndex + 1];
WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, pAnsi, nIndex, NULL, NULL);
delete pAnsi;

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home