Directory Services


The ldap_create_sort_control function is used to format a list of sort keys into a search control. Support for controls is available effective with LDAP 3, but whether the sort control is supported or not is dependent on the particular server.

ULONG ldap_create_sort_control(
  PLDAP ExternalHandle,
  PLDAPSortKey* SortKeys,
  UCHAR IsCritical,
  PLDAPControl* Control


[in] The session handle.
[in] Pointer to an array of LDAPSortKey structures. Each structure in the array specifies the name of an attribute to use as a sort key, the matching rule for that key, and whether the sort order is ascending or descending.
[in] Notifies the server whether this control is critical to the search. 0 ==> FALSE, !0 ==> TRUE.
[out] Pointer to the newly created control.

Return Values

Return Code Description
LDAP_SUCCESS The call completed successfully.


The ldap_create_sort_control function creates a basic sort control. Such a control is useful when the LDAP client has limited functionality and cannot sort results, yet needs them sorted.

The sort controls allow a server to return a result code for the sorting of the results that is independent of the result code returned for the search operation.

This function creates the control — it does not verify that the server supports it, and consequently, does not return LDAP_UNAVAILABLE_CRIT_EXTENSION if the server does not support the control. However, it can return other standard LDAP return values, such as LDAP_NO_MEMORY or LDAP_PARAM_ERROR.

To free the control when it is no longer required, call ldap_control_free.


Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension on Windows NT 4.0 SP6a and Windows 95/98/Me.
Unicode: Implemented as Unicode and ANSI versions on all platforms.
Header: Declared in Winldap.h.
Library: Use Wldap32.lib.

See Also

Functions, ldap_control_free, LDAPSortKey, LDAP_SERVER_SORT_OID