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