Internationalization and localization tools


Locale-Sensitive Windows C++ Function

LPTSTR lstrcmp(LPTSTR lpString1, LPTSTR lpString2);

LPSTR lstrcmpA(LPSTR lpString1, LPSTR lpString2);

LPWSTR lstrcmpW(LPWSTR lpString1, LPWSTR lpString2);

Internationalization (I18n) Function Overview

The lstrcmp function performs a case-insensitive compare of two null-terminated strings. It returns zero if the strings are equal, a negative number if lpString1 is less than lpString2 and a positive number if lpString1 is greater than lpString2. If one string is a prefix of the other, the longer string is greater than the shorter string.

lstrcmp uses a word sort, rather than a string sort. In a word sort, hyphens and apostrophes are treated differently from other symbols that are not alphanumeric, in order to ensure that words such as "coop" and "co-op" stay together within a sorted list. The comparison is based on the language (locale) selected by the user during setup or through the Control Panel.

lstrcmpA is the narrow version of the function; its arguments and return are single-byte or multibyte strings.

lstrcmpW is the wide version of the function; its arguments and return are wide-character strings.

See the MSDN Library for more information.

I18n Issues

lstrcmp should not be used in an internationalized application because its comparison relies on a language setting that may differ from the program's locale. Instead, use CompareString, which allows a locale to be passed in as an argument.

Recommended Replacements*

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. Using the Generic version facilitates switching between an MBCS and UTF-16 Unicode application.

*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