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 creates and initializes a connection block, and then opens the connection to an LDAP server. This function is currently depreciated: users are strongly encouraged to use ldap_initinstead.

Syntax

LDAP* ldap_open(
  UNICODE PTCHAR 
HostName,
  ULONG 
PortNumber
);

Parameters

HostName

[in] Domain name, 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:
Only ldap_openattempts to make the connection before returning to the caller. The ldap_initfunction 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 Value

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

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

Remarks

Call this function to create a connection block to an LDAP server. The HostNameparameter 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.

This 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.

In a multithreading environment, calls to this function are thread-safe.

The use of this function is strongly depreciated by the current LDAP request for comments (RFC) because it precludes the use of setting any session options. Users are encouraged to use ldap_initas the preferred method of initializing an LDAP session.

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