Internationalization and localization tools


Locale-Sensitive Windows C++ Function

int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar);

Internationalization (I18n) Function Overview

The WideCharToMultibyte function maps the UTF-16 Unicode wide character string specified by lpWideCharStr into a character string (from single or multibyte character sets), using the dwFlags options and the code page specified by CodePage, and stores the result in lpMultiByteStr. If successful and cbMultiByte is non-zero, then the return value is the number of byte characters written to the buffer pointed to by lpMultiByteStr; if cbMultiByte is 0, then a successful return value is the required size, in bytes, 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.

cchWideChar is the wide-character size of the buffer pointed to by lpWideCharStr. If this value is -1, lpWideCharStr is assumed to be null-terminated and the length is calculated automatically and will include the null-terminator.

cbMultiByte is the byte size of the buffer pointed to by lpMultiByteStr. If this value is 0, WideCharToMultibyte returns the number of bytes required for the translated string and does not modify the lpMultiByteStr buffer.

See the MSDN Library for more information.

I18n Issues

Formulate the correct code page to pass into WideCharToMultibyte, 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