Internationalization and localization tools


Locale-Sensitive Windows C++ Function

int LCMapString(LCID Locale, DWORD dwMapFlags, LPCTSTR lpSrcStr, int cchSrc, LPTSTR lpDestStr, int cchDest);

int LCMapStringA(LCID Locale, DWORD dwMapFlags, LPCSTR lpSrcStr, int cchSrc, LPSTR lpDestStr, int cchDest);

int LCMapStringW(LCID Locale, DWORD dwMapFlags, LPCWSTR lpSrcStr, int cchSrc, LPWSTR lpDestStr, int cchDest);

Internationalization (I18n) Function Overview

The LCMapString function either maps the input character string lpSrcStr to another string at lpDestStr, using Locale and the specified transformation dwMapFlags, or generates a sort key for the input string based on Locale and stores the key in the buffer pointed to by lpDestStr.

cchSrc should be set to either the size, in TCHARs, of the lpSrcStr buffer, or to a negative value, in which case the function automatically calculates the number of TCHARs in the null-terminated lpSrcStr, including the NULL character.

If the function is being used for string mapping, then cchDest should be set to either the size, in TCHARs, of the lpDestStr buffer, or to 0, in which case, the function returns the number of TCHARs that would be written to lpDestStr, but does not actually modify the buffer.

If the function is being used to generate a sort key, then cchDest should be set to either the byte size of the lpDestStr buffer, including the sort key 0x00 terminator, or to 0, in which case, the function returns the number of bytes that would be written to lpDestStr, but does not actually modify the buffer.

In the event of an error, LCMapString returns 0 and sets extended error information that can be obtained by calling GetLastError.

LCMapStringA is the narrow version of the function, passing in single or multibyte strings and string length values in bytes.

LCMapStringW is the wide version of the function, passing in wide-character strings and string length values in wide characters (WCHARs).

See the MSDN Library for more information.

I18n Issues

Use the appropriate version of the function as required for internationalization support, noting the following:

Formulate the correct LCID to pass into LCMapString.

If the function is being used for string mapping, and cchSrc and cchDest are non-zero, then ensure that these length values are set correctly for the chosen platform; bytes for the narrow version and WCHARs for the wide version. See Locale-Sensitive Length Functions for a discussion on multibyte and wide character sizes.

If the function is being used to generate a sort key, and cchSrc and cchDest are non-zero, then ensure that these lengths are byte values, regardless the target platform.

Recommended Replacements*

When possible, use the Generic version of the function, rather than the narrow or wide versions, and let the Windows #define UNICODE switch determine which version of the function will be called.

*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