Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function determines whether an attribute for a given entry holds a known value.

Syntax

ULONG ldap_compare(
  LDAP* 
ld,
  UNICODE PTCHAR 
dn,
  UNICODE PTCHAR 
attr,
  UNICODE PTCHAR 
value
);

Parameters

ld

[in] Session handle.

dn

[in] Distinguished name of the entry.

attr

[in] Attribute to compare.

value

[in] String attribute value to compare to the attribute value.

Return Value

If this function succeeds, the return value is the message identifier of the compare operation.

If this function fails, it returns –1 and sets the session error parameters in the LDAP structure.

Remarks

This function initiates an asynchronous compare operation, comparing the value of an attribute to a known string value. Use ldap_compare_extor ldap_compare_ext_sif you need to compare binary values. Use ldap_compare_sor ldap_compare_ext_sto carry out a synchronous compare operation.

As an asynchronous function, ldap_comparereturns a message identifier for the operation. Call the ldap_resultfunction with the message identifier to get the result of the operation. To cancel an asynchronous operation before it has been completed, call the ldap_abandonfunction.

If you prefer to have the function return the results directly, use the synchronous routine ldap_compare_s. Use ldap_compare_extor ldap_compare_ext_sif you need support for LDAP 3 server and client controls.

In a multithreading environment, calls to ldap_compareare not thread-safe because the function returns a message identifier rather than the return code. To determine whether the call returned an error value, you have to retrieve the return code from the connection block. It is possible for another thread to overwrite the return code before you retrieve it. Use ldap_compare_ext, ldap_compare_s, or ldap_compare_ext_s, all of which are thread-safe.

When connecting to an LDAP 2 server, the application must perform a bind operation (by calling one of the ldap_bindor ldap_simple_bindroutines) before attempting other operations.

Requirements

Header winldap.h
Library wldap32.lib
Windows Embedded CE Windows CE .NET 4.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also