| 변환명 | 코드 |
| ansi -> utf8 | #include <WTypes.h >
//ANSI to UTF8 string ansi_to_utf8(string& ansi) { WCHAR unicode[1024]; char utf8[1024]; memset(unicode, 0, sizeof(unicode)); memset(utf8, 0, sizeof(utf8)); ::MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), -1, unicode, sizeof(unicode)); ::WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, sizeof(utf8), NULL, NULL); return string(utf8); } |
| utf8 -> ansi | //UTF8 to ANSI string utf8_to_ansi(string& utf8) { WCHAR unicode[1024]; char ansi[1024]; memset(unicode, 0, sizeof(unicode)); memset(ansi, 0, sizeof(ansi)); ::MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1, unicode, sizeof(unicode)); ::WideCharToMultiByte(CP_ACP, 0, unicode, -1, ansi, sizeof(ansi), NULL, NULL); return string(ansi); } |
| WideByte -> MultiByte | // WideByte -> MultiByte string WBCS(const wchar_t strUni[256]) { char strUtf8[256] = { 0, }; int nLen = WideCharToMultiByte(CP_UTF8, 0, strUni, lstrlenW(strUni), NULL, 0, NULL, NULL); WideCharToMultiByte(CP_UTF8, 0, strUni, lstrlenW(strUni), strUtf8, nLen, NULL, NULL); return strUtf8; } |
| MultiByte -> WideByte | // MultiByte -> WideByte wchar_t* MBCS(const char* strMultibyte) { wchar_t strUnicode[256] = { 0, }; int nLen = MultiByteToWideChar(CP_ACP, 0, strMultibyte, strlen(strMultibyte), NULL, NULL); MultiByteToWideChar(CP_ACP, 0, strMultibyte, strlen(strMultibyte), strUnicode, nLen); return strUnicode; } |