Internationalization and localization tools


Locale-Sensitive Windows C++ Function

BOOL GetStringTypeW(DWORD dwInfoType, LPCWSTR lpSrcStr, int cchSrc, LPWORD lpCharType);

Internationalization (I18n) Function Overview

The GetStringTypeW function determines character type information (alphabetic, numeric, control, etc), bi-directional layout information, and text processing information of the wide-character string argument lpSrcStr, and stores the result in the array pointed to by lpCharType. If successful, GetStringTypeW 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 wide characters, of the string pointed to by the lpSrcStr argument. If this count includes the null-terminating character, then GetStringTypeW also 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 wsclen(lpSrcStr) + 1.

The output array lpCharType must point to 16-bit values and be large enough to hold a value for each lpSrcStr character. In other words, it must hold cchSrc elements, or if cchSrc is a negative value, then it contains wcslen(lpSrcStr) + 1 array elements.

Note that there is no Generic version of GetStringTypeW, and although there is a similar narrow function GetStringTypeA, it passes in an additional locale argument.

See the MSDN Library for additional information.

I18n Issues

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

In addition, because GetStringTypeW does not have the locale argument, on Win95/98/ME platforms the Microsoft Layer for Unicode uses the system locale rather than the program's locale, which is undesirable in an international environment.

If GetStringTypeW is used, ensure that if cchSrc is a positive value, it is set correctly; the number of wide characters in the string lpSrcStr. See Locale-Sensitive Length Functions for a discussion on wide character size.

Recommended Replacements*

When possible, use the Generic version of the function, rather than the narrow or wide versions, and let the Windows #define UNICODE compiler 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