CompareStringW

  int CompareStringW(LCID, dwCmpFlags, lpString1, cchCount1, lpString2, cchCount2)    
  LCID LCID;    
  DWORD dwCmpFlags;    
  LPWSTR lpString1;    
  int cchCount1;    
  LPWSTR lpString2;    
  int cchCount2;    

The CompareStringW function compares two wide character strings of the same locale according to the supplied locale ID.

Parameters

LCID

Locale context for the comparison.

dwCmpFlags

Indicates what character traits to use/ignore when comparing the two strings. Several flags can be combined (in the case of this function, there are no illegal combinations of flags). Compare flags include:#Value Meaning NORM_IGNORECASE ignore case; default is OFF NORM_IGNORENONSPACE ignore nonspacing; default is OFF NORM_IGNORESYMBOLS ignore symbols; default is OFF

lpString1 and lpString2

The two strings to be compared.

cchCount1 and cchCount2

The character counts of the two strings. The count does not include the null-terminator (if any). If either cchCount1 or cchCount2 is -1, the corresponding string is assumed to be null-terminated and the length will be calculated automatically.

Return Value

Success:

1 if lpString1 is less than lpString2

2 if lpString1 is equal to lpString2

3 if lpString1 is greater than lpString2

Failure: 0

This function sets GetLastError() with the following values: ERROR_INVALID_PARAMETER.

Comments

If the return value is 2, the two strings are “equal” in the collation sense, though not necessarily identical (i.e., case might be ignored, etc.).

If the two strings are of different lengths, they are compared up to the length of the shortest one. If they are equal to that point, then the return value will indicate that the longer string is greater.

To maintain the C runtime convention of comparing strings, the value 2 can be subtracted from a non zero return value. The meaning of < 0, == 0, and > 0 is then consistent with the C runtimes.