Internationalization and localization tools


Locale-Sensitive Windows C++ Function

int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);

Internationalization (I18n) Function Overview

The MultibyteToWideChar function maps the character string (from single or multibyte character sets) specified by lpMultiByteStr into a UTF-16 Unicode wide character string, using the dwFlags options and the code page specified by CodePage, and stores the result in lpWideCharStr. If successful and cchWideChar is non-zero, then the return value is the number of wide characters written to the buffer pointed to by lpWideCharStr; if cchWideChar is 0, then a successful return value is the required size, in wide characters, for a buffer that can receive the translated string. In the event of an error, the return value is 0 and extended error information can be obtained by calling GetLastError.

cbMultiByte is the byte size of the buffer pointed to by lpMultiByteStr. If this value is -1, lpMultiByteStr is assumed to be null-terminated and the length is calculated automatically and will include the null-terminator.

cchWideChar is the wide-character size of the buffer pointed to by lpWideCharStr. If this value is 0, MultibyteToWideChar returns the number of bytes required for the translated string and does not modify the lpWideCharStr buffer.

See the MSDN Library for more information.

I18n Issues

Formulate the correct code page to pass into MultibyteToWideChar, which, in an internationalized application, may be independent of any system settings.

Also, ensure that cchWideChar is set to a WCHAR length, and cbMultiByte is set to a byte length. See Locale-Sensitive Length Functions for a discussion on multibyte and wide character sizes.

Recommended Replacements*

There are no variations of this function.

*If you're already using the recommended function, see I18n Issues for other reasons why Globalyzer is detecting the function.

Locale-Sensitive Windows C++ Functions

 

Lingoport internationalization and localization services and software