Directory Services


Use the ldap_compare_s function to determine whether an attribute for a given entry holds a known value.

ULONG ldap_compare_s(
  LDAP* ld,
  PCHAR dn,
  PCHAR attr,
  CHAR value


[in] The session handle.
[in] A pointer to a null-terminated string that contains the distinguished name of the entry.
[in] A pointer to a null-terminated string that contains the attribute to compare.
[in] A pointer to a null-terminated string that contains the string attribute value to compare to the attribute value.

Return Values

If the function succeeds, and the attribute and known values match, the return value is LDAP_COMPARE_TRUE. If the values do not match, the return value is LDAP_COMPARE_FALSE.

If the function fails, it returns an error code. See Return Values for more information.


The ldap_compare_s function initiates a synchronous compare operation, comparing the value of an attribute to a known string value. Use ldap_compare_ext_s if you need to compare binary values. Use ldap_compare or ldap_compare_ext to carry out an asynchronous compare operation.

Multithreading: Calls to ldap_compare_s are thread-safe.

Note  When connecting to an LDAP 2 server, the application must perform a bind operation (by calling one of the ldap_bind or ldap_simple_bind routines) before attempting any other operations.


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_bind, ldap_compare, ldap_compare_ext, ldap_compare_ext_s, ldap_simple_bind, Return Values