Export (0) Print
Expand All

MultiByteToWideChar (Windows CE 5.0)

Windows CE 5.0
Send Feedback

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

CodePage
[in] The code page to be used to perform the conversion. This parameter can be given the value of any code page that is installed or available in the system.

You can also specify one of the values shown in the following table.

ValueDescription
CP_ACPANSI code page
CP_MACCPNot supported
CP_OEMCPOEM code page
CP_SYMBOLNot supported
CP_THREAD_ACPNot supported
CP_UTF7UTF-7 code page
CP_UTF8UTF-8 code page
dwFlags
[in] This specifies whether to translate to precomposed or composite wide characters if a composite form exists, whether to use glyph characters in place of control characters, and how to deal with invalid characters.

You can specify a combination of the flag constants shown in the following table.

ValueDescription
MB_PRECOMPOSEDAlways 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_COMPOSITEAlways 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_CHARSIf the function encounters an invalid input character, it fails and GetLastError returns ERROR_NO_UNICODE_TRANSLATION.
MB_USEGLYPHCHARSUse 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/nonspacing 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.

lpMultiByteStr
[in] Pointer to the character string to be converted.
cbMultiByte
[in] The size in bytes of the string pointed to by the lpMultiByteStr parameter.

If this value is –1, the string is assumed to be null terminated and the length is calculated automatically.

lpWideCharStr
[out] Pointer to a buffer that receives the translated string.
cchWideChar
[in] The size, in wide characters, of the buffer pointed to by the lpWideCharStr parameter.

If this value is zero, the function returns the required buffer size, in wide characters, and makes no use of the lpWideCharStr buffer.

Return Values

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.

Note   The return value includes the NULL termination character.

A return value of zero indicates failure.

To get extended error information, call GetLastError.

Possible values for GetLastError include the following:

  • ERROR_INSUFFICIENT_BUFFER
  • ERROR_INVALID_FLAGS
  • ERROR_INVALID_PARAMETER
  • ERROR_NO_UNICODE_TRANSLATION

Remarks

If lpMultiByteStr and lpWideCharStr pointers 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.

Requirements

OS Versions: Windows CE 1.01 and later.
Header: Winnls.h.
Link Library: Coredll.lib.

See Also

WideCharToMultiByte | DLGITEMTEMPLATE | DLGITEMTEMPLATEEX | DLGTEMPLATE | DLGTEMPLATEEX | IsDBCSLeadByte


Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft