Skip to content

Instantly share code, notes, and snippets.

@ajchemist
Created March 30, 2015 13:16
Show Gist options
  • Select an option

  • Save ajchemist/f5b98be581009a400d35 to your computer and use it in GitHub Desktop.

Select an option

Save ajchemist/f5b98be581009a400d35 to your computer and use it in GitHub Desktop.
MFC utilities
char* ConvertUnicodeToMultybyte(CString strUnicode)
{
int nLen = WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, NULL, 0, NULL, NULL);
char* pMultibyte = new char[nLen];
memset(pMultibyte, 0x00, (nLen)*sizeof(char));
WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, pMultibyte, nLen, NULL, NULL);
return pMultibyte;
}
CString ConvertMultibyteToUnicode(char* pMultibyte)
{
int nLen = strlen(pMultibyte);
WCHAR *pWideChar = new WCHAR[nLen];
memset(pWideChar, 0x00, (nLen)*sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pMultibyte, -1, pWideChar, nLen);
CString strUnicode;
strUnicode.Format(_T("%s"), pWideChar);
delete [] pWideChar;
return strUnicode;
}
CString strUnicode(_T("유니코드"));
char* pMultibyte = ConvertUnicodeToMultibyte(strUnicode);
char* pMultibyte = "멀티바이트";
CString strUnicode = ConvertMultibyteToUnicode(pMultibyte);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment