Platform SDK: Active Directory, ADSI, and Directory Services

ldap_open

The ldap_open function creates and initializes a connection block, then opens the connection to an LDAP server.

LDAP* ldap_open(
  PCHAR HostName,
  ULONG PortNumber
);

Parameters

HostName
[in] A list of host names or dotted strings representing the IP address of LDAP server hosts. Use a single space to separate the host names in the list. Each host name in the list may be followed by a port number. The optional port number is separated from the host itself with a colon (:) character. The LDAP run time attempts connection with the hosts in the order listed, stopping when a successful connection is made. Note that only ldap_open attempts to make the connection before returning to the caller. The function ldap_init does not connect to the LDAP server.
PortNumber
[in] Contains the TCP port number to which to connect. The default LDAP port, 389, can be obtained by supplying the constant LDAP_PORT. If a host name includes a port number then this parameter is ignored.

Return Values

If the function succeeds, it returns a session handle, in the form of a pointer to an LDAP data structure.

If the function fails, it returns NULL. Use the LdapGetLastError function to retrieve the error code.

Remarks

Call ldap_open to create a connection block to an LDAP server. The HostName parameter can be NULL in which case the run time attempts to find the default LDAP server. The host names are tried in the order listed, stopping with the first successful connection.

The default LDAP server is a Microsoft specific option when you use LDAP_OPT_HOST_NAME. This option specifies the host name of the default LDAP server and returns the host name of the server in Unicode or ANSI, contingent on the use of ldap_get_optionW or ldap_get_optionA, respectively.

The ldap_open function allocates an LDAP data structure to maintain state information for the session and returns a handle to this structure. You can pass this handle to subsequent LDAP function calls during the course of the session.

Multithreading: Calls to ldap_open are thread-safe.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 SP4 or later.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Header: Declared in Winldap.h.
  Library: Use Wldap32.lib.
  Unicode: Declared as Unicode and ANSI prototypes.

See Also

cldap_open, Functions, ldap_init, LdapGetLastError