Windows/MFC

유니코드(Unicode) -> char* or Multibyte -> Unicode

aucd29 2013. 10. 2. 18:06
자주쓰는데도 길다보니 잊어묵는 사태..

[code]
// Unicode Build 일때... Unicode -> char 로
//
CString szSrc;
int nLen = szSrc.GetLength();
char* pszDest = new char [nLen + 1];
memset(pszDest, 0, nLen);
WideCharToMultiByte(CP_ACP, 0, szSrc, -1, pszDest, nLen, NULL, NULL);

// todo

delete pszDest;
[/code]


[code]
// MultiByte Build 일때 ... char -> Unicode 로
//
char* pszSrc = "cast test";
int nLen = strlen(pszSrc) + 1;
wchar_t* pszwDest = new wchar_t[nLen];
memset(szwDest , 0, nLen);
int nLen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pszSrc, nLen - 1, pszwDest , nLen);

// todo

delete pszwDest;
[code]