WindowsApi:MultiByteToWideChar
Multi Byte 문자열을 Wide Char 문자열로 변환해준다. (char -> wchar_t) 반대로 변환해주는 함수는 WideCharToMultiByte()이다.
더 정확한 설명은 아래와 같다.
Maps a character string to a UTF-16 (wide character) string. The character string is not necessarily from a multibyte character set.
문자열을 UTF-16 (와이드 문자) 문자열에 매핑합니다. 문자열은 멀티 바이트 문자 집합의 문자 일 필요는 없습니다.
Syntax
int MultiByteToWideChar(
__in UINT CodePage,
__in DWORD dwFlags,
__in LPCSTR lpMultiByteStr,
__in int cbMultiByte,
__out_opt LPWSTR lpWideCharStr,
__in int cchWideChar
);
-
CodePage
: 첫 번째 인자로CP_ACP
를 사용할 경우 ANSI코드페이지를 사용하게 된다.
Example
일반적으로 사용하는 char(ANSI)를 wchar_t(Unicode)로 변환해주는 코드는 아래와 같다.
int wcs_length = strlen(mbs_string) + 1;
wchar_t * convert_wcs = new wchar_t [wcs_length];
::MultiByteToWideChar(CP_ACP, 0, mbs_string, -1, convert_wcs, wcs_length);
// use convert_wcs varable.
delete [] convert_wcs;
See also
Favorite site
- [http://msdn.microsoft.com/en-us/library/windows/desktop/dd319072(v=vs.85.aspx MSDN: MultiByteToWideChar()에 대한 설명]
- Unicode and Character Set Functions
- MultiByteToWideChar() 사용방법 번역