6.5.1 String Comparison by Using Sort Keys

To compare strings, the implementer needs to get a "sort key" for each string. A binary comparison of the sort keys can then be used to arrange the strings in any desired order.

This section utilizes the GetWindowsSortKey and CompareSortKeys procedures, which are specified in [MS-UCODEREF].

The flags that need to be passed to GetWindowsSortKey depend on the comparison being performed. This is specified in the following table.

Comparison being performed

Flags (from [MS-UCODEREF])

UnicodeString Comparison Rule (section

LDAP_SERVER_SORT_OID sorting (section, except for phonetic display name sort


Phonetic display name sort (section


In order to compare two strings, StringA and StringB, the following procedure is used. The value of flags is as specified in the table above. The value of LCID is the locale identifier (section 2.2.1) for the locale being used to compare the strings. To determine what value to pass for LCID, see sections and Note that when performing phonetic display name sort, LCID must be set equal to "1.2.840.113556.1.4.1538" (the Japanese sort order).

 set SortKeyA to call GetWindowsSortKey(StringA, LCID, flags)
 set SortKeyB to call GetWindowsSortKey(StringB, LCID, flags)
 set Result to call CompareSortKeys(SortKeyA, SortKeyB)
 if Result is "SortKeyA is equal to SortKeyB"
  StringA is considered equal to StringB
 else if Result is "SortKeyA is less than SortKeyB"
  StringA is sorted prior to StringB
  assert Result must be "SortKeyA is greater than SortKeyB"
  StringA is sorted after StringB

Any sorting mechanism can be used to arrange these strings by comparing their sort keys.