Internationalization and localization tools


Locale-Sensitive Windows C++ Function

BOOL GetStringTypeA(LCID Locale, DWORD dwInfoType, LPCSTR lpSrcStr, int cchSrc, LPWORD lpCharType);

Internationalization (I18n) Function Overview

The GetStringTypeA function determines character type information (alphabetic, numeric, control, etc), bi-directional layout information, and text processing information of the single or multibyte-character string argument lpSrcStr, and stores the result in the array pointed to by lpCharType. Locale is used to convert the multibyte-characters to Unicode UTF-16 characters prior to the analysis of each Unicode character for character type information. If successful, GetStringTypeA returns a non-zero value; otherwise, it returns 0 and sets extended error information that can be obtained by calling GetLastError.

The dwInfoType flag specifies the type of character information to retrieve, and can be one of the following values:
CT_CTYPE1 to retrieve character type information.
CT_CTYPE2 to retrieve bi-directional layout information.
CT_CTYPE3 to retrieve text processing information.

cchSrc specifies the size, in bytes, of the string pointed to by the lpSrcStr argument. If this count includes the null-terminating character, then GetStringTypeEx returns character type information for the NULL character. If cchSrc is a negative number, the string is assumed to be null-terminated and the length is calculated automatically and includes the NULL character. In other words, the calculated length is _tcslen(lpSrcStr) + 1.

The output array lpCharType must point to 16-bit values and be large enough to hold a value for each lpSrcStr single or multibyte character. Note that this is a character length rather than a byte length, since lpSrcStr may be a combination of single and multibyte characters. However, to ensure that the size of the array is large enough, Windows recommends that the size of the array be the same as cchSrc, or _tcslen(lpSrcStr) + 1 when cchSrc is a negative value.

Note that there is no Generic version of GetStringTypeA, and although there is a similar wide function GetStringTypeW, it does not pass in a locale argument.

See the MSDN Library for additional information.

I18n Issues

GetStringTypeA does not properly accommodate the #define UNICODE switch: there are no corresponding wide or Generic versions of the function. Use GetStringTypeEx as a better I18n alternative.

If GetStringTypeA is used, formulate the correct LCID to pass into GetStringTypeA. Although there are two predefined LCID constants that may be used: LOCALE_SYSTEM_DEFAULT (the system's default locale returned by GetSystemDefaultLCID) and LOCALE_USER_DEFAULT (the current user's default locale returned by GetUserDefaultLCID), neither of these will work in an internationalized application where the locale is independent of the user's system settings.

Ensure that if cchSrc is a positive value, it is set correctly; the number of bytes in the string lpSrcStr, which may be single-byte or multibyte characters. See Locale-Sensitive Length Functions for a discussion on single and multibyte character size.

Recommended Replacements*

*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