Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
This 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 , DWORD dwFlags , LPCSTR lpMultiByteStr , int cbMultiByte , LPWSTR lpWideCharStr , int cchWideChar );
Parameters
Value | Description |
---|---|
CP_ACP | ANSI code page |
CP_MACCP | Not supported |
CP_OEMCP | OEM code page |
CP_SYMBOL | Not supported |
CP_THREAD_ACP | Not supported |
Value | Description |
---|---|
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 GetLastErrorreturns 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 eis 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.
Return Values
If cchWideCharis nonzero, the number of wide characters written to the buffer pointed to by lpWideCharStrindicates success. If cchWideCharis zero, the required size, in wide characters, for a buffer that can receive the translated string indicates success. Zero indicates failure. To get extended error information, call GetLastError. Possible values for GetLastErrorinclude the following:
Remarks
The lpMultiByteStrand lpWideCharStrpointers must not be the same. If they are the same, the function fails, and GetLastErrorreturns 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 GetLastErrorwith the error ERROR_NO_UNICODE_TRANSLATION.
Requirements
Runs on | Versions | Defined in | Include | Link to |
---|---|---|---|---|
Windows CE OS | 1.01 and later | Winnls.h |
Note This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.
See Also
GetLastError, WideCharToMultiByte