The MultiByteToWideChar function maps a character string to a wide-character (Unicode) string. The character string mapped by this function is not necessarily from a multibyte character set.
int MultiByteToWideChar(
UINT CodePage, |
// code page |
DWORD dwFlags, |
// character-type options |
LPCSTR lpMultiByteStr, |
// address of string to map |
int cchMultiByte, |
// number of characters in string |
LPWSTR lpWideCharStr, |
// address of wide-character buffer |
int cchWideChar |
// size of buffer |
); |
Value |
Meaning |
CP_ACP |
ANSI code page |
CP_MACCP |
Macintosh code page |
CP_OEMCP |
OEM code page |
CP_UTF7 |
Translate using UTF-7 |
CP_UTF8 |
Translate using UTF-8 |
Value |
Meaning |
MB_PRECOMPOSED |
Always use precomposed characters ¾ that is, characters in which a base character and a nonspacing character have a single character value. This is the default translation option. Cannot be used with MB_COMPOSITE. |
MB_COMPOSITE |
Always use composite characters ¾ that is, characters in which a base character and a nonspacing character have different character values. Cannot be used with MB_PRECOMPOSED. |
MB_ERR_INVALID_CHARS |
If the function encounters an invalid input character, it fails and GetLastError returns ERROR_NO_UNICODE_TRANSLATION. |
MB_USEGLYPHCHARS |
Use glyph characters instead of control characters. |
A composite character consists of a base character and a nonspacing character, each having different character values. A precomposed character has a single character value for a base/non-spacing character combination. In the character è, the e is the base character and the accent grave mark is the nonspacing character.
The function’s default behavior is to translate to the precomposed form. If a precomposed form does not exist, the function attempts to translate to a composite form.
The flags MB_PRECOMPOSED and MB_COMPOSITE are mutually exclusive. The
MB_USEGLYPHCHARS flag and the MB_ERR_INVALID_CHARS can be set regardless of
the state of the other flags.
If the function succeeds, and cchWideChar is nonzero, the return value is the number of wide characters written to the buffer pointed to by lpWideCharStr.
If the function succeeds, and cchWideChar is zero, the return value is the required size, in wide characters, for a buffer that can receive the translated string.
If the function fails, the return value is zero. To get extended error information, call GetLastError. GetLastError may return one of the following error codes:
ERROR_INSUFFICIENT_BUFFER |
ERROR_INVALID_FLAGS |
ERROR_INVALID_PARAMETER |
ERROR_NO_UNICODE_TRANSLATION |
The lpMultiByteStr and lpWideCharStr pointers must not be the same. If they are the same, the function fails, and GetLastError returns the value ERROR_INVALID_PARAMETER.
The function fails if MB_ERR_INVALID_CHARS is set and it encounters an invalid character in the source string. An invalid character is one that would translate to the default character if MB_ERR_INVALID_CHARS was not set, but is not the default character in the source string, or when a lead byte is found in a string and there is no valid trail byte for DBCS strings. When an invalid character is found, and MB_ERR_INVALID_CHARS is set, the function returns 0 and sets GetLastError with the error ERROR_NO_UNICODE_TRANSLATION.
Comments:
file: /Techref/os/win/api/win32/func/src/f58_2.htm, 8KB, , updated: 2007/7/27 10:21, local time: 2024/11/9 23:49,
3.15.240.208:LOG IN ©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://linistepper.com/Techref/os/win/api/win32/func/src/f58_2.htm"> MultiByteToWideChar</A> |
Did you find what you needed? |