[PATCH 8/8] wldap32: Get rid of the WLDAP32_ prefix.

Hans Leidekker hans at codeweavers.com
Mon Apr 19 03:04:54 CDT 2021


We can now include the public header without conflicts.

Signed-off-by: Hans Leidekker <hans at codeweavers.com>
---
 dlls/wldap32/add.c             |  45 +--
 dlls/wldap32/ber.c             | 104 +++----
 dlls/wldap32/bind.c            | 132 ++++-----
 dlls/wldap32/compare.c         |  57 ++--
 dlls/wldap32/control.c         |  65 ++--
 dlls/wldap32/delete.c          |  51 ++--
 dlls/wldap32/dn.c              |  31 +-
 dlls/wldap32/error.c           |  59 ++--
 dlls/wldap32/extended.c        |  58 ++--
 dlls/wldap32/init.c            |  67 ++---
 dlls/wldap32/libldap.c         |   5 +-
 dlls/wldap32/libldap.h         | 147 ++++-----
 dlls/wldap32/misc.c            | 106 +++----
 dlls/wldap32/modify.c          |  49 +--
 dlls/wldap32/modrdn.c          |  41 +--
 dlls/wldap32/option.c          | 525 ++++++++++++++++----------------
 dlls/wldap32/page.c            | 112 +++----
 dlls/wldap32/parse.c           | 118 ++++----
 dlls/wldap32/rename.c          |  33 ++-
 dlls/wldap32/search.c          |  76 ++---
 dlls/wldap32/value.c           |  31 +-
 dlls/wldap32/winldap_private.h | 527 +++------------------------------
 dlls/wldap32/wldap32.spec      |  56 ++--
 include/winber.h               |   2 +-
 include/winldap.h              |  10 +-
 25 files changed, 1039 insertions(+), 1468 deletions(-)

diff --git a/dlls/wldap32/add.c b/dlls/wldap32/add.c
index 605c1535914..e9684f2d209 100644
--- a/dlls/wldap32/add.c
+++ b/dlls/wldap32/add.c
@@ -22,6 +22,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -33,9 +34,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *
  * See ldap_addW.
  */
-ULONG CDECL ldap_addA( WLDAP32_LDAP *ld, char *dn, LDAPModA **attrs )
+ULONG CDECL ldap_addA( LDAP *ld, char *dn, LDAPModA **attrs )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL;
     LDAPModW **attrsW = NULL;
 
@@ -74,14 +75,14 @@ exit:
  *  the operation. Cancel the operation by calling ldap_abandon
  *  with the message ID.
  */
-ULONG CDECL ldap_addW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPModW **attrs )
+ULONG CDECL ldap_addW( LDAP *ld, WCHAR *dn, LDAPModW **attrs )
 {
     ULONG ret, msg;
 
     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
 
     ret = ldap_add_extW( ld, dn, attrs, NULL, NULL, &msg );
-    if (ret == WLDAP32_LDAP_SUCCESS) return msg;
+    if (ret == LDAP_SUCCESS) return msg;
     return ~0u;
 }
 
@@ -90,17 +91,17 @@ ULONG CDECL ldap_addW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPModW **attrs )
  *
  * See ldap_add_extW.
  */
-ULONG CDECL ldap_add_extA( WLDAP32_LDAP *ld, char *dn, LDAPModA **attrs, LDAPControlA **serverctrls,
+ULONG CDECL ldap_add_extA( LDAP *ld, char *dn, LDAPModA **attrs, LDAPControlA **serverctrls,
                            LDAPControlA **clientctrls, ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL;
     LDAPModW **attrsW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), attrs, serverctrls, clientctrls, message );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (attrs && !(attrsW = modarrayAtoW( attrs ))) goto exit;
@@ -140,24 +141,24 @@ exit:
  *  the operation. The serverctrls and clientctrls parameters are
  *  optional and should be set to NULL if not used.
  */
-ULONG CDECL ldap_add_extW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPModW **attrs, LDAPControlW **serverctrls,
+ULONG CDECL ldap_add_extW( LDAP *ld, WCHAR *dn, LDAPModW **attrs, LDAPControlW **serverctrls,
                            LDAPControlW **clientctrls, ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL;
     LDAPModU **attrsU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), attrs, serverctrls, clientctrls, message );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (attrs && !(attrsU = modarrayWtoU( attrs ))) goto exit;
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_add_ext( ld->ld, dnU, attrsU, serverctrlsU, clientctrlsU, message ) );
+    ret = map_error( ldap_funcs->fn_ldap_add_ext( CTX(ld), dnU, attrsU, serverctrlsU, clientctrlsU, message ) );
 
 exit:
     free( dnU );
@@ -172,17 +173,17 @@ exit:
  *
  * See ldap_add_ext_sW.
  */
-ULONG CDECL ldap_add_ext_sA( WLDAP32_LDAP *ld, char *dn, LDAPModA **attrs, LDAPControlA **serverctrls,
+ULONG CDECL ldap_add_ext_sA( LDAP *ld, char *dn, LDAPModA **attrs, LDAPControlA **serverctrls,
                              LDAPControlA **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL;
     LDAPModW **attrsW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), attrs, serverctrls, clientctrls );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (attrs && !(attrsW = modarrayAtoW( attrs ))) goto exit;
@@ -220,24 +221,24 @@ exit:
  *  The serverctrls and clientctrls parameters are optional and
  *  should be set to NULL if not used.
  */
-ULONG CDECL ldap_add_ext_sW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPModW **attrs, LDAPControlW **serverctrls,
+ULONG CDECL ldap_add_ext_sW( LDAP *ld, WCHAR *dn, LDAPModW **attrs, LDAPControlW **serverctrls,
                              LDAPControlW **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL;
     LDAPModU **attrsU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), attrs, serverctrls, clientctrls );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (attrs && !(attrsU = modarrayWtoU( attrs ))) goto exit;
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_add_ext_s( ld->ld, dnU, attrsU, serverctrlsU, clientctrlsU ) );
+    ret = map_error( ldap_funcs->fn_ldap_add_ext_s( CTX(ld), dnU, attrsU, serverctrlsU, clientctrlsU ) );
 
 exit:
     free( dnU );
@@ -252,15 +253,15 @@ exit:
  *
  * See ldap_add_sW.
  */
-ULONG CDECL ldap_add_sA( WLDAP32_LDAP *ld, char *dn, LDAPModA **attrs )
+ULONG CDECL ldap_add_sA( LDAP *ld, char *dn, LDAPModA **attrs )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL;
     LDAPModW **attrsW = NULL;
 
     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (attrs && !(attrsW = modarrayAtoW( attrs ))) goto exit;
@@ -288,7 +289,7 @@ exit:
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_add_sW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPModW **attrs )
+ULONG CDECL ldap_add_sW( LDAP *ld, WCHAR *dn, LDAPModW **attrs )
 {
     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
     return ldap_add_ext_sW( ld, dn, attrs, NULL, NULL );
diff --git a/dlls/wldap32/ber.c b/dlls/wldap32/ber.c
index ffb8e862d0e..ca5bbc305c5 100644
--- a/dlls/wldap32/ber.c
+++ b/dlls/wldap32/ber.c
@@ -23,6 +23,8 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
+#include "winber.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -44,12 +46,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  * NOTES
  *  Free the berelement structure with ber_free.
  */
-WLDAP32_BerElement * CDECL WLDAP32_ber_alloc_t( int options )
+BerElement * CDECL ber_alloc_t( int options )
 {
-    WLDAP32_BerElement *ret;
+    BerElement *ret;
 
     if (!(ret = malloc( sizeof(*ret) ))) return NULL;
-    if (!(ret->opaque = ldap_funcs->ber_alloc_t( options )))
+    if (!(BER(ret) = ldap_funcs->fn_ber_alloc_t( options )))
     {
         free( ret );
         return NULL;
@@ -73,7 +75,7 @@ WLDAP32_BerElement * CDECL WLDAP32_ber_alloc_t( int options )
  * NOTES
  *  Free the copy with ber_bvfree.
  */
-BERVAL * CDECL WLDAP32_ber_bvdup( BERVAL *berval )
+BERVAL * CDECL ber_bvdup( BERVAL *berval )
 {
     return bervalWtoW( berval );
 }
@@ -94,7 +96,7 @@ BERVAL * CDECL WLDAP32_ber_bvdup( BERVAL *berval )
  *  Use this function only to free an array of berval structures
  *  returned by a call to ber_scanf with a 'V' in the format string.
  */
-void CDECL WLDAP32_ber_bvecfree( BERVAL **berval )
+void CDECL ber_bvecfree( BERVAL **berval )
 {
     bvarrayfreeW( berval );
 }
@@ -115,7 +117,7 @@ void CDECL WLDAP32_ber_bvecfree( BERVAL **berval )
  *  Use this function only to free berval structures allocated by
  *  an LDAP API.
  */
-void CDECL WLDAP32_ber_bvfree( BERVAL *berval )
+void CDECL ber_bvfree( BERVAL *berval )
 {
     free( berval );
 }
@@ -138,9 +140,9 @@ void CDECL WLDAP32_ber_bvfree( BERVAL *berval )
  * NOTES
  *  len and cookie should be passed to ber_next_element.
  */
-ULONG CDECL WLDAP32_ber_first_element( WLDAP32_BerElement *ber, ULONG *len, char **opaque )
+ULONG CDECL ber_first_element( BerElement *ber, ULONG *len, char **opaque )
 {
-    return ldap_funcs->ber_first_element( ber->opaque, len, opaque );
+    return ldap_funcs->fn_ber_first_element( BER(ber), len, opaque );
 }
 
 
@@ -160,16 +162,16 @@ ULONG CDECL WLDAP32_ber_first_element( WLDAP32_BerElement *ber, ULONG *len, char
  * NOTES
  *  Free the berval structure with ber_bvfree.
  */
-int CDECL WLDAP32_ber_flatten( WLDAP32_BerElement *ber, BERVAL **berval )
+int CDECL ber_flatten( BerElement *ber, BERVAL **berval )
 {
     struct bervalU *bervalU;
-    struct WLDAP32_berval *bervalW;
+    struct berval *bervalW;
 
-    if (ldap_funcs->ber_flatten( ber->opaque, &bervalU )) return WLDAP32_LBER_ERROR;
+    if (ldap_funcs->fn_ber_flatten( BER(ber), &bervalU )) return LBER_ERROR;
 
-    if (!(bervalW = bervalUtoW( bervalU ))) return WLDAP32_LBER_ERROR;
-    ldap_funcs->ber_bvfree( bervalU );
-    if (!bervalW) return WLDAP32_LBER_ERROR;
+    if (!(bervalW = bervalUtoW( bervalU ))) return LBER_ERROR;
+    ldap_funcs->fn_ber_bvfree( bervalU );
+    if (!bervalW) return LBER_ERROR;
     *berval = bervalW;
     return 0;
 }
@@ -191,9 +193,9 @@ int CDECL WLDAP32_ber_flatten( WLDAP32_BerElement *ber, BERVAL **berval )
  *  Set buf to 0 if the berelement was allocated with ldap_first_attribute
  *  or ldap_next_attribute, otherwise set it to 1.
  */
-void CDECL WLDAP32_ber_free( WLDAP32_BerElement *ber, int freebuf )
+void CDECL ber_free( BerElement *ber, int freebuf )
 {
-    ldap_funcs->ber_free( ber->opaque, freebuf );
+    ldap_funcs->fn_ber_free( BER(ber), freebuf );
     free( ber );
 }
 
@@ -213,10 +215,10 @@ void CDECL WLDAP32_ber_free( WLDAP32_BerElement *ber, int freebuf )
  * NOTES
  *  Call ber_free to free the returned berelement structure.
  */
-WLDAP32_BerElement * CDECL WLDAP32_ber_init( BERVAL *berval )
+BerElement * CDECL ber_init( BERVAL *berval )
 {
     struct bervalU *bervalU;
-    WLDAP32_BerElement *ret;
+    BerElement *ret;
 
     if (!(ret = malloc( sizeof(*ret) ))) return NULL;
     if (!(bervalU = bervalWtoU( berval )))
@@ -224,7 +226,7 @@ WLDAP32_BerElement * CDECL WLDAP32_ber_init( BERVAL *berval )
         free( ret );
         return NULL;
     }
-    if (!(ret->opaque = ldap_funcs->ber_init( bervalU )))
+    if (!(BER(ret) = ldap_funcs->fn_ber_init( bervalU )))
     {
         free( ret );
         ret = NULL;
@@ -252,9 +254,9 @@ WLDAP32_BerElement * CDECL WLDAP32_ber_init( BERVAL *berval )
  *  len and cookie are initialized by ber_first_element and should
  *  be passed on in subsequent calls to ber_next_element.
  */
-ULONG CDECL WLDAP32_ber_next_element( WLDAP32_BerElement *ber, ULONG *len, char *opaque )
+ULONG CDECL ber_next_element( BerElement *ber, ULONG *len, char *opaque )
 {
-    return ldap_funcs->ber_next_element( ber->opaque, len, opaque );
+    return ldap_funcs->fn_ber_next_element( BER(ber), len, opaque );
 }
 
 
@@ -271,9 +273,9 @@ ULONG CDECL WLDAP32_ber_next_element( WLDAP32_BerElement *ber, ULONG *len, char
  *  Success: Tag of the next element.
  *  Failure: LBER_DEFAULT (no more data).
  */
-ULONG CDECL WLDAP32_ber_peek_tag( WLDAP32_BerElement *ber, ULONG *len )
+ULONG CDECL ber_peek_tag( BerElement *ber, ULONG *len )
 {
-    return ldap_funcs->ber_peek_tag( ber->opaque, len );
+    return ldap_funcs->fn_ber_peek_tag( BER(ber), len );
 }
 
 
@@ -290,9 +292,9 @@ ULONG CDECL WLDAP32_ber_peek_tag( WLDAP32_BerElement *ber, ULONG *len )
  *  Success: Tag of the next element.
  *  Failure: LBER_DEFAULT (no more data).
  */
-ULONG CDECL WLDAP32_ber_skip_tag( WLDAP32_BerElement *ber, ULONG *len )
+ULONG CDECL ber_skip_tag( BerElement *ber, ULONG *len )
 {
-    return ldap_funcs->ber_skip_tag( ber->opaque, len );
+    return ldap_funcs->fn_ber_skip_tag( BER(ber), len );
 }
 
 
@@ -314,7 +316,7 @@ ULONG CDECL WLDAP32_ber_skip_tag( WLDAP32_BerElement *ber, ULONG *len )
  *  berelement must have been allocated with ber_alloc_t. This function
  *  can be called multiple times to append data.
  */
-int WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *ber, char *fmt, ... )
+int WINAPIV ber_printf( BerElement *ber, char *fmt, ... )
 {
     __ms_va_list list;
     int ret = 0;
@@ -332,38 +334,38 @@ int WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *ber, char *fmt, ... )
         case 'i':
         {
             int i = va_arg( list, int );
-            ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, i );
+            ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, i );
             break;
         }
         case 'o':
         case 's':
         {
             char *str = va_arg( list, char * );
-            ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, str );
+            ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, str );
             break;
         }
         case 't':
         {
             unsigned int tag = va_arg( list, unsigned int );
-            ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, tag );
+            ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, tag );
             break;
         }
         case 'v':
         {
             char **array = va_arg( list, char ** );
-            ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, array );
+            ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, array );
             break;
         }
         case 'V':
         {
-            struct WLDAP32_berval **array = va_arg( list, struct WLDAP32_berval ** );
+            struct berval **array = va_arg( list, struct berval ** );
             struct bervalU **arrayU;
             if (!(arrayU = bvarrayWtoU( array )))
             {
                 ret = -1;
                 break;
             }
-            ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, arrayU );
+            ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, arrayU );
             bvarrayfreeU( arrayU );
             break;
         }
@@ -372,7 +374,7 @@ int WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *ber, char *fmt, ... )
             char *str = va_arg( list, char * );
             int len = va_arg( list, int );
             new_fmt[0] = 'B';  /* 'X' is deprecated */
-            ret = ldap_funcs->ber_printf( ber->opaque, new_fmt, str, len );
+            ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt, str, len );
             break;
         }
         case 'n':
@@ -380,7 +382,7 @@ int WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *ber, char *fmt, ... )
         case '}':
         case '[':
         case ']':
-            ret = ldap_funcs->ber_printf( ber->opaque, new_fmt );
+            ret = ldap_funcs->fn_ber_printf( BER(ber), new_fmt );
             break;
 
         default:
@@ -413,7 +415,7 @@ int WINAPIV WLDAP32_ber_printf( WLDAP32_BerElement *ber, char *fmt, ... )
  *  berelement must have been allocated with ber_init. This function
  *  can be called multiple times to decode data.
  */
-ULONG WINAPIV WLDAP32_ber_scanf( WLDAP32_BerElement *ber, char *fmt, ... )
+ULONG WINAPIV ber_scanf( BerElement *ber, char *fmt, ... )
 {
     __ms_va_list list;
     int ret = 0;
@@ -429,9 +431,9 @@ ULONG WINAPIV WLDAP32_ber_scanf( WLDAP32_BerElement *ber, char *fmt, ... )
         case 'a':
         {
             char *str, **ptr = va_arg( list, char ** );
-            if ((ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, &str )) == -1) break;
+            if ((ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, &str )) == -1) break;
             *ptr = strdupU( str );
-            ldap_funcs->ldap_memfree( str );
+            ldap_funcs->fn_ldap_memfree( str );
             break;
         }
         case 'b':
@@ -439,55 +441,55 @@ ULONG WINAPIV WLDAP32_ber_scanf( WLDAP32_BerElement *ber, char *fmt, ... )
         case 'i':
         {
             int *i = va_arg( list, int * );
-            ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, i );
+            ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, i );
             break;
         }
         case 't':
         {
             unsigned int *tag = va_arg( list, unsigned int * );
-            ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, tag );
+            ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, tag );
             break;
         }
         case 'v':
         {
             char *str, **arrayU, **ptr, ***array = va_arg( list, char *** );
-            if ((ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, &arrayU )) == -1) break;
+            if ((ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, &arrayU )) == -1) break;
             *array = strarrayUtoU( arrayU );
             ptr = arrayU;
             while ((str = *ptr))
             {
-                ldap_funcs->ldap_memfree( str );
+                ldap_funcs->fn_ldap_memfree( str );
                 ptr++;
             }
-            ldap_funcs->ldap_memfree( arrayU );
+            ldap_funcs->fn_ldap_memfree( arrayU );
             break;
         }
         case 'B':
         {
             char *strU, **str = va_arg( list, char ** );
             int *len = va_arg( list, int * );
-            if ((ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, &strU, len )) == -1) break;
+            if ((ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, &strU, len )) == -1) break;
             *str = malloc( *len );
             memcpy( *str, strU, *len );
-            ldap_funcs->ldap_memfree( strU );
+            ldap_funcs->fn_ldap_memfree( strU );
             break;
         }
         case 'O':
         {
-            struct WLDAP32_berval **berval = va_arg( list, struct WLDAP32_berval ** );
+            struct berval **berval = va_arg( list, struct berval ** );
             struct bervalU *bervalU;
-            if ((ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, &bervalU )) == -1) break;
+            if ((ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, &bervalU )) == -1) break;
             *berval = bervalUtoW( bervalU );
-            ldap_funcs->ber_bvfree( bervalU );
+            ldap_funcs->fn_ber_bvfree( bervalU );
             break;
         }
         case 'V':
         {
-            struct WLDAP32_berval ***array = va_arg( list, struct WLDAP32_berval *** );
+            struct berval ***array = va_arg( list, struct berval *** );
             struct bervalU **arrayU;
-            if ((ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt, &arrayU )) == -1) break;
+            if ((ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt, &arrayU )) == -1) break;
             *array = bvarrayUtoW( arrayU );
-            ldap_funcs->ber_bvecfree( arrayU );
+            ldap_funcs->fn_ber_bvecfree( arrayU );
             break;
         }
         case 'n':
@@ -496,7 +498,7 @@ ULONG WINAPIV WLDAP32_ber_scanf( WLDAP32_BerElement *ber, char *fmt, ... )
         case '}':
         case '[':
         case ']':
-            ret = ldap_funcs->ber_scanf( ber->opaque, new_fmt );
+            ret = ldap_funcs->fn_ber_scanf( BER(ber), new_fmt );
             break;
 
         default:
diff --git a/dlls/wldap32/bind.c b/dlls/wldap32/bind.c
index c9a597e8868..d45ed5d60e0 100644
--- a/dlls/wldap32/bind.c
+++ b/dlls/wldap32/bind.c
@@ -24,6 +24,7 @@
 #include "winbase.h"
 #include "winnls.h"
 #include "rpc.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -35,9 +36,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *
  * See ldap_bindW.
  */
-ULONG CDECL ldap_bindA( WLDAP32_LDAP *ld, char *dn, char *cred, ULONG method )
+ULONG CDECL ldap_bindA( LDAP *ld, char *dn, char *cred, ULONG method )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *credW = NULL;
 
     TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_a(dn), cred, method );
@@ -73,9 +74,9 @@ exit:
  * NOTES
  *  Only LDAP_AUTH_SIMPLE is supported (just like native).
  */
-ULONG CDECL ldap_bindW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *cred, ULONG method )
+ULONG CDECL ldap_bindW( LDAP *ld, WCHAR *dn, WCHAR *cred, ULONG method )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL, *credU = NULL;
     struct bervalU pwd = { 0, NULL };
     int msg;
@@ -83,7 +84,7 @@ ULONG CDECL ldap_bindW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *cred, ULONG method )
     TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_w(dn), cred, method );
 
     if (!ld) return ~0u;
-    if (method != WLDAP32_LDAP_AUTH_SIMPLE) return WLDAP32_LDAP_PARAM_ERROR;
+    if (method != LDAP_AUTH_SIMPLE) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (cred)
@@ -93,8 +94,8 @@ ULONG CDECL ldap_bindW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *cred, ULONG method )
         pwd.bv_val = credU;
     }
 
-    ret = map_error( ldap_funcs->ldap_sasl_bind( ld->ld, dnU, 0, &pwd, NULL, NULL, &msg ) );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    ret = map_error( ldap_funcs->fn_ldap_sasl_bind( CTX(ld), dnU, 0, &pwd, NULL, NULL, &msg ) );
+    if (ret == LDAP_SUCCESS)
         ret = msg;
     else
         ret = ~0u;
@@ -110,19 +111,19 @@ exit:
  *
  * See ldap_bind_sW.
  */
-ULONG CDECL ldap_bind_sA( WLDAP32_LDAP *ld, char *dn, char *cred, ULONG method )
+ULONG CDECL ldap_bind_sA( LDAP *ld, char *dn, char *cred, ULONG method )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *credW = NULL;
 
     TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_a(dn), cred, method );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (cred)
     {
-        if (method == WLDAP32_LDAP_AUTH_SIMPLE)
+        if (method == LDAP_AUTH_SIMPLE)
         {
             if (!(credW = strAtoW( cred ))) goto exit;
         }
@@ -166,7 +167,7 @@ int CDECL sasl_interact_cb( void *ld, unsigned flags, void *defaults, void *inte
         sasl++;
     }
 
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -184,17 +185,17 @@ int CDECL sasl_interact_cb( void *ld, unsigned flags, void *defaults, void *inte
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_bind_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *cred, ULONG method )
+ULONG CDECL ldap_bind_sW( LDAP *ld, WCHAR *dn, WCHAR *cred, ULONG method )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL, *credU = NULL;
     struct bervalU pwd = { 0, NULL };
 
     TRACE( "(%p, %s, %p, 0x%08x)\n", ld, debugstr_w(dn), cred, method );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
-    if (method == WLDAP32_LDAP_AUTH_SIMPLE)
+    if (method == LDAP_AUTH_SIMPLE)
     {
         if (dn && !(dnU = strWtoU( dn ))) goto exit;
         if (cred)
@@ -204,9 +205,9 @@ ULONG CDECL ldap_bind_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *cred, ULONG method
             pwd.bv_val = credU;
         }
 
-        ret = map_error( ldap_funcs->ldap_sasl_bind_s( ld->ld, dnU, 0, &pwd, NULL, NULL, NULL ) );
+        ret = map_error( ldap_funcs->fn_ldap_sasl_bind_s( CTX(ld), dnU, 0, &pwd, NULL, NULL, NULL ) );
     }
-    else if (method == WLDAP32_LDAP_AUTH_NEGOTIATE)
+    else if (method == LDAP_AUTH_NEGOTIATE)
     {
         SEC_WINNT_AUTH_IDENTITY_A idU;
         SEC_WINNT_AUTH_IDENTITY_W idW;
@@ -228,10 +229,10 @@ ULONG CDECL ldap_bind_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *cred, ULONG method
             idU.Password = (unsigned char *)strnWtoU( id->Password, id->PasswordLength, &idU.PasswordLength );
         }
 
-        ret = map_error( ldap_funcs->ldap_sasl_interactive_bind_s( ld->ld,
-                                                                   NULL /* server will ignore DN anyway */,
-                                                                   NULL /* query supportedSASLMechanisms */,
-                                                                   NULL, NULL, 2 /* LDAP_SASL_QUIET */, &idU ) );
+        ret = map_error( ldap_funcs->fn_ldap_sasl_interactive_bind_s( CTX(ld),
+                                                                      NULL /* server will ignore DN anyway */,
+                                                                      NULL /* query supportedSASLMechanisms */,
+                                                                      NULL, NULL, 2 /* LDAP_SASL_QUIET */, &idU ) );
 
         if (id && (id->Flags & SEC_WINNT_AUTH_IDENTITY_ANSI))
         {
@@ -247,7 +248,7 @@ ULONG CDECL ldap_bind_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *cred, ULONG method
     else
     {
         FIXME( "method %#x not supported\n", method );
-        return WLDAP32_LDAP_PARAM_ERROR;
+        return LDAP_PARAM_ERROR;
     }
 
 exit:
@@ -261,18 +262,17 @@ exit:
  *
  * See ldap_sasl_bindW.
  */
-ULONG CDECL ldap_sasl_bindA( WLDAP32_LDAP *ld, const PCHAR dn, const PCHAR mechanism, const BERVAL *cred,
+ULONG CDECL ldap_sasl_bindA( LDAP *ld, const PCHAR dn, const PCHAR mechanism, const BERVAL *cred,
     LDAPControlA **serverctrls, LDAPControlA **clientctrls, int *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW, *mechanismW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
            debugstr_a(mechanism), cred, serverctrls, clientctrls, message );
 
-    if (!ld || !dn || !mechanism || !cred || !message)
-        return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !dn || !mechanism || !cred || !message) return LDAP_PARAM_ERROR;
 
     if (!(dnW = strAtoW( dn ))) goto exit;
     if (!(mechanismW = strAtoW( mechanism ))) goto exit;
@@ -311,10 +311,10 @@ exit:
  *  The serverctrls and clientctrls parameters are optional and should
  *  be set to NULL if not used.
  */
-ULONG CDECL ldap_sasl_bindW( WLDAP32_LDAP *ld, const PWCHAR dn, const PWCHAR mechanism, const BERVAL *cred,
+ULONG CDECL ldap_sasl_bindW( LDAP *ld, const PWCHAR dn, const PWCHAR mechanism, const BERVAL *cred,
     LDAPControlW **serverctrls, LDAPControlW **clientctrls, int *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU, *mechanismU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
     struct bervalU credU;
@@ -322,8 +322,7 @@ ULONG CDECL ldap_sasl_bindW( WLDAP32_LDAP *ld, const PWCHAR dn, const PWCHAR mec
     TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
            debugstr_w(mechanism), cred, serverctrls, clientctrls, message );
 
-    if (!ld || !dn || !mechanism || !cred || !message)
-        return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !dn || !mechanism || !cred || !message) return LDAP_PARAM_ERROR;
 
     if (!(dnU = strWtoU( dn ))) goto exit;
     if (!(mechanismU = strWtoU( mechanism ))) goto exit;
@@ -333,7 +332,8 @@ ULONG CDECL ldap_sasl_bindW( WLDAP32_LDAP *ld, const PWCHAR dn, const PWCHAR mec
     credU.bv_len = cred->bv_len;
     credU.bv_val = cred->bv_val;
 
-    ret = map_error( ldap_funcs->ldap_sasl_bind( ld->ld, dnU, mechanismU, &credU, serverctrlsU, clientctrlsU, message ) );
+    ret = map_error( ldap_funcs->fn_ldap_sasl_bind( CTX(ld), dnU, mechanismU, &credU, serverctrlsU, clientctrlsU,
+                                                    message ) );
 
 exit:
     free( dnU );
@@ -348,18 +348,17 @@ exit:
  *
  * See ldap_sasl_bind_sW.
  */
-ULONG CDECL ldap_sasl_bind_sA( WLDAP32_LDAP *ld, const PCHAR dn, const PCHAR mechanism, const BERVAL *cred,
+ULONG CDECL ldap_sasl_bind_sA( LDAP *ld, const PCHAR dn, const PCHAR mechanism, const BERVAL *cred,
     LDAPControlA **serverctrls, LDAPControlA **clientctrls, BERVAL **serverdata )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW, *mechanismW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
            debugstr_a(mechanism), cred, serverctrls, clientctrls, serverdata );
 
-    if (!ld || !dn || !mechanism || !cred || !serverdata)
-        return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !dn || !mechanism || !cred || !serverdata) return LDAP_PARAM_ERROR;
 
     if (!(dnW = strAtoW( dn ))) goto exit;
     if (!(mechanismW = strAtoW( mechanism ))) goto exit;
@@ -398,11 +397,10 @@ exit:
  *  The serverctrls and clientctrls parameters are optional and should
  *  be set to NULL if not used.
  */
-ULONG CDECL ldap_sasl_bind_sW( WLDAP32_LDAP *ld, const PWCHAR dn,
-    const PWCHAR mechanism, const BERVAL *cred, LDAPControlW **serverctrls,
-    LDAPControlW **clientctrls, BERVAL **serverdata )
+ULONG CDECL ldap_sasl_bind_sW( LDAP *ld, const PWCHAR dn, const PWCHAR mechanism, const BERVAL *cred,
+    LDAPControlW **serverctrls, LDAPControlW **clientctrls, BERVAL **serverdata )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU, *mechanismU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
     struct bervalU *dataU, credU;
@@ -410,8 +408,7 @@ ULONG CDECL ldap_sasl_bind_sW( WLDAP32_LDAP *ld, const PWCHAR dn,
     TRACE( "(%p, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
            debugstr_w(mechanism), cred, serverctrls, clientctrls, serverdata );
 
-    if (!ld || !dn || !mechanism || !cred || !serverdata)
-        return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !dn || !mechanism || !cred || !serverdata) return LDAP_PARAM_ERROR;
 
     if (!(dnU = strWtoU( dn ))) goto exit;
     if (!(mechanismU = strWtoU( mechanism ))) goto exit;
@@ -421,13 +418,14 @@ ULONG CDECL ldap_sasl_bind_sW( WLDAP32_LDAP *ld, const PWCHAR dn,
     credU.bv_len = cred->bv_len;
     credU.bv_val = cred->bv_val;
 
-    ret = map_error( ldap_funcs->ldap_sasl_bind_s( ld->ld, dnU, mechanismU, &credU, serverctrlsU, clientctrlsU, &dataU ) );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    ret = map_error( ldap_funcs->fn_ldap_sasl_bind_s( CTX(ld), dnU, mechanismU, &credU, serverctrlsU, clientctrlsU,
+                                                      &dataU ) );
+    if (ret == LDAP_SUCCESS)
     {
         BERVAL *ptr;
-        if (!(ptr = bervalUtoW( dataU ))) ret = WLDAP32_LDAP_NO_MEMORY;
+        if (!(ptr = bervalUtoW( dataU ))) ret = LDAP_NO_MEMORY;
         else *serverdata = ptr;
-        ldap_funcs->ber_bvfree( dataU );
+        ldap_funcs->fn_ber_bvfree( dataU );
     }
 
 exit:
@@ -443,9 +441,9 @@ exit:
  *
  * See ldap_simple_bindW.
  */
-ULONG CDECL ldap_simple_bindA( WLDAP32_LDAP *ld, char *dn, char *passwd )
+ULONG CDECL ldap_simple_bindA( LDAP *ld, char *dn, char *passwd )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *passwdW = NULL;
 
     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
@@ -480,9 +478,9 @@ exit:
  * NOTES
  *  Set dn and passwd to NULL to bind as an anonymous user.
  */
-ULONG CDECL ldap_simple_bindW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *passwd )
+ULONG CDECL ldap_simple_bindW( LDAP *ld, WCHAR *dn, WCHAR *passwd )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL, *passwdU = NULL;
     struct bervalU pwd = { 0, NULL };
     int msg;
@@ -499,8 +497,8 @@ ULONG CDECL ldap_simple_bindW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *passwd )
         pwd.bv_val = passwdU;
     }
 
-    ret = map_error( ldap_funcs->ldap_sasl_bind( ld->ld, dnU, 0, &pwd, NULL, NULL, &msg ) );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    ret = map_error( ldap_funcs->fn_ldap_sasl_bind( CTX(ld), dnU, 0, &pwd, NULL, NULL, &msg ) );
+    if (ret == LDAP_SUCCESS)
         ret = msg;
     else
         ret = ~0u;
@@ -516,14 +514,14 @@ exit:
  *
  * See ldap_simple_bind_sW.
  */
-ULONG CDECL ldap_simple_bind_sA( WLDAP32_LDAP *ld, char *dn, char *passwd )
+ULONG CDECL ldap_simple_bind_sA( LDAP *ld, char *dn, char *passwd )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *passwdW = NULL;
 
     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), passwd );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (passwd && !(passwdW = strAtoW( passwd ))) goto exit;
@@ -553,15 +551,15 @@ exit:
  * NOTES
  *  Set dn and passwd to NULL to bind as an anonymous user.
  */
-ULONG CDECL ldap_simple_bind_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *passwd )
+ULONG CDECL ldap_simple_bind_sW( LDAP *ld, WCHAR *dn, WCHAR *passwd )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL, *passwdU = NULL;
     struct bervalU pwd = { 0, NULL };
 
     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), passwd );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (passwd)
@@ -571,7 +569,7 @@ ULONG CDECL ldap_simple_bind_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *passwd )
         pwd.bv_val = passwdU;
     }
 
-    ret = map_error( ldap_funcs->ldap_sasl_bind_s( ld->ld, dnU, 0, &pwd, NULL, NULL, NULL ) );
+    ret = map_error( ldap_funcs->fn_ldap_sasl_bind_s( CTX(ld), dnU, 0, &pwd, NULL, NULL, NULL ) );
 
 exit:
     free( dnU );
@@ -591,16 +589,16 @@ exit:
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL WLDAP32_ldap_unbind( WLDAP32_LDAP *ld )
+ULONG CDECL ldap_unbind( LDAP *ld )
 {
     ULONG ret;
 
     TRACE( "(%p)\n", ld );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
-    ret = map_error( ldap_funcs->ldap_unbind_ext( ld->ld, NULL, NULL ));
-    if (ld->ld_server_ctrls) ldap_funcs->ldap_value_free_len( ld->ld_server_ctrls );
+    ret = map_error( ldap_funcs->fn_ldap_unbind_ext( CTX(ld), NULL, NULL ));
+    if (SERVER_CTRLS(ld)) ldap_funcs->fn_ldap_value_free_len( SERVER_CTRLS(ld) );
 
     free( ld );
     return ret;
@@ -618,16 +616,16 @@ ULONG CDECL WLDAP32_ldap_unbind( WLDAP32_LDAP *ld )
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL WLDAP32_ldap_unbind_s( WLDAP32_LDAP *ld )
+ULONG CDECL ldap_unbind_s( LDAP *ld )
 {
     ULONG ret;
 
     TRACE( "(%p)\n", ld );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
-    ret = map_error( ldap_funcs->ldap_unbind_ext_s( ld->ld, NULL, NULL ) );
-    if (ld->ld_server_ctrls) ldap_funcs->ldap_value_free_len( ld->ld_server_ctrls );
+    ret = map_error( ldap_funcs->fn_ldap_unbind_ext_s( CTX(ld), NULL, NULL ) );
+    if (SERVER_CTRLS(ld)) ldap_funcs->fn_ldap_value_free_len( SERVER_CTRLS(ld) );
 
     free( ld );
     return ret;
diff --git a/dlls/wldap32/compare.c b/dlls/wldap32/compare.c
index 63b56ef9f4c..3d68da0a792 100644
--- a/dlls/wldap32/compare.c
+++ b/dlls/wldap32/compare.c
@@ -22,6 +22,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -33,7 +34,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *
  * See ldap_compareW.
  */
-ULONG CDECL ldap_compareA( WLDAP32_LDAP *ld, char *dn, char *attr, char *value )
+ULONG CDECL ldap_compareA( LDAP *ld, char *dn, char *attr, char *value )
 {
     ULONG ret = ~0u;
     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
@@ -70,14 +71,14 @@ exit:
  *  Success: Message ID of the compare operation.
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_compareW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR *value )
+ULONG CDECL ldap_compareW( LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR *value )
 {
     ULONG msg, ret;
 
     TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(attr), debugstr_w(value) );
 
     ret = ldap_compare_extW( ld, dn, attr, value, NULL, NULL, NULL, &msg );
-    if (ret == WLDAP32_LDAP_SUCCESS) return msg;
+    if (ret == LDAP_SUCCESS) return msg;
     return ~0u;
 }
 
@@ -86,18 +87,18 @@ ULONG CDECL ldap_compareW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR *valu
  *
  * See ldap_compare_extW.
  */
-ULONG CDECL ldap_compare_extA( WLDAP32_LDAP *ld, char *dn, char *attr, char *value,
-    struct WLDAP32_berval *data, LDAPControlA **serverctrls, LDAPControlA **clientctrls,
+ULONG CDECL ldap_compare_extA( LDAP *ld, char *dn, char *attr, char *value,
+    struct berval *data, LDAPControlA **serverctrls, LDAPControlA **clientctrls,
     ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), debugstr_a(attr), debugstr_a(value),
            data, serverctrls, clientctrls, message );
 
-    if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !message) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (attr && !(attrW = strAtoW( attr ))) goto exit;
@@ -140,10 +141,10 @@ exit:
  *  both are non-NULL, data will be used. The serverctrls and clientctrls
  *  parameters are optional and should be set to NULL if not used.
  */
-ULONG CDECL ldap_compare_extW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR *value,
-    struct WLDAP32_berval *data, LDAPControlW **serverctrls, LDAPControlW **clientctrls, ULONG *message )
+ULONG CDECL ldap_compare_extW( LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR *value, struct berval *data,
+    LDAPControlW **serverctrls, LDAPControlW **clientctrls, ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL, *attrU = NULL, *valueU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
     struct bervalU *dataU = NULL, val = { 0, NULL };
@@ -151,8 +152,8 @@ ULONG CDECL ldap_compare_extW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR *
     TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), debugstr_w(attr), debugstr_w(value),
            data, serverctrls, clientctrls, message );
 
-    if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
-    if (!attr) return WLDAP32_LDAP_NO_MEMORY;
+    if (!ld || !message) return LDAP_PARAM_ERROR;
+    if (!attr) return LDAP_NO_MEMORY;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (!(attrU = strWtoU( attr ))) goto exit;
@@ -170,8 +171,8 @@ ULONG CDECL ldap_compare_extW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR *
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_compare_ext( ld->ld, dnU, attrU, dataU ? dataU : &val, serverctrlsU,
-                                                   clientctrlsU, message ) );
+    ret = map_error( ldap_funcs->fn_ldap_compare_ext( CTX(ld), dnU, attrU, dataU ? dataU : &val, serverctrlsU,
+                                                      clientctrlsU, message ) );
 exit:
     free( dnU );
     free( attrU );
@@ -187,17 +188,17 @@ exit:
  *
  * See ldap_compare_ext_sW.
  */
-ULONG CDECL ldap_compare_ext_sA( WLDAP32_LDAP *ld, char *dn, char *attr, char *value,
-    struct WLDAP32_berval *data, LDAPControlA **serverctrls, LDAPControlA **clientctrls )
+ULONG CDECL ldap_compare_ext_sA( LDAP *ld, char *dn, char *attr, char *value, struct berval *data,
+    LDAPControlA **serverctrls, LDAPControlA **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld, debugstr_a(dn), debugstr_a(attr), debugstr_a(value),
            data, serverctrls, clientctrls );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (attr && !(attrW = strAtoW( attr ))) goto exit;
@@ -239,10 +240,10 @@ exit:
  *  both are non-NULL, data will be used. The serverctrls and clientctrls
  *  parameters are optional and should be set to NULL if not used.
  */
-ULONG CDECL ldap_compare_ext_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR *value,
-    struct WLDAP32_berval *data, LDAPControlW **serverctrls, LDAPControlW **clientctrls )
+ULONG CDECL ldap_compare_ext_sW( LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR *value, struct berval *data,
+    LDAPControlW **serverctrls, LDAPControlW **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL, *attrU = NULL, *valueU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
     struct bervalU *dataU = NULL, val = { 0, NULL };
@@ -250,7 +251,7 @@ ULONG CDECL ldap_compare_ext_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR
     TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld, debugstr_w(dn), debugstr_w(attr), debugstr_w(value), data,
            serverctrls, clientctrls );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (attr && !(attrU = strWtoU( attr ))) goto exit;
@@ -268,8 +269,8 @@ ULONG CDECL ldap_compare_ext_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_compare_ext_s( ld->ld, dnU, attrU, dataU ? dataU : &val, serverctrlsU,
-                                                     clientctrlsU ) );
+    ret = map_error( ldap_funcs->fn_ldap_compare_ext_s( CTX(ld), dnU, attrU, dataU ? dataU : &val, serverctrlsU,
+                                                        clientctrlsU ) );
 exit:
     free( dnU );
     free( attrU );
@@ -285,14 +286,14 @@ exit:
  *
  * See ldap_compare_sW.
  */
-ULONG CDECL ldap_compare_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value )
+ULONG CDECL ldap_compare_sA( LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
 
     TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(attr), debugstr_a(value) );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (attr && !(attrW = strAtoW( attr ))) goto exit;
@@ -322,7 +323,7 @@ exit:
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_compare_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR *value )
+ULONG CDECL ldap_compare_sW( LDAP *ld, WCHAR *dn, WCHAR *attr, WCHAR *value )
 {
     TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(attr), debugstr_w(value) );
     return ldap_compare_ext_sW( ld, dn, attr, value, NULL, NULL, NULL );
diff --git a/dlls/wldap32/control.c b/dlls/wldap32/control.c
index b012648797c..3afd0ddecf0 100644
--- a/dlls/wldap32/control.c
+++ b/dlls/wldap32/control.c
@@ -22,6 +22,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -37,7 +38,7 @@ ULONG CDECL ldap_control_freeA( LDAPControlA *control )
 {
     TRACE( "(%p)\n", control );
     controlfreeA( control );
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -55,7 +56,7 @@ ULONG CDECL ldap_control_freeW( LDAPControlW *control )
 {
     TRACE( "(%p)\n", control );
     controlfreeW( control );
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -67,7 +68,7 @@ ULONG CDECL ldap_controls_freeA( LDAPControlA **controls )
 {
     TRACE( "(%p)\n", controls );
     controlarrayfreeA( controls );
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -85,7 +86,7 @@ ULONG CDECL ldap_controls_freeW( LDAPControlW **controls )
 {
     TRACE( "(%p)\n", controls );
     controlarrayfreeW( controls );
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -93,8 +94,7 @@ ULONG CDECL ldap_controls_freeW( LDAPControlW **controls )
  *
  * See ldap_create_sort_controlW.
  */
-ULONG CDECL ldap_create_sort_controlA( WLDAP32_LDAP *ld, LDAPSortKeyA **sortkey, UCHAR critical,
-    LDAPControlA **control )
+ULONG CDECL ldap_create_sort_controlA( LDAP *ld, LDAPSortKeyA **sortkey, UCHAR critical, LDAPControlA **control )
 {
     ULONG ret;
     LDAPSortKeyW **sortkeyW;
@@ -102,16 +102,16 @@ ULONG CDECL ldap_create_sort_controlA( WLDAP32_LDAP *ld, LDAPSortKeyA **sortkey,
 
     TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
 
-    if (!ld || !sortkey || !control) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !sortkey || !control) return LDAP_PARAM_ERROR;
 
-    if (!(sortkeyW = sortkeyarrayAtoW( sortkey ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (!(sortkeyW = sortkeyarrayAtoW( sortkey ))) return LDAP_NO_MEMORY;
 
     ret = ldap_create_sort_controlW( ld, sortkeyW, critical, &controlW );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    if (ret == LDAP_SUCCESS)
     {
         LDAPControlA *controlA = controlWtoA( controlW );
         if (controlA) *control = controlA;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
+        else ret = LDAP_NO_MEMORY;
         ldap_control_freeW( controlW );
     }
 
@@ -141,8 +141,7 @@ ULONG CDECL ldap_create_sort_controlA( WLDAP32_LDAP *ld, LDAPSortKeyA **sortkey,
  *  Pass the created control as a server control in subsequent calls
  *  to ldap_search_ext(_s) to obtain sorted search results.
  */
-ULONG CDECL ldap_create_sort_controlW( WLDAP32_LDAP *ld, LDAPSortKeyW **sortkey, UCHAR critical,
-    LDAPControlW **control )
+ULONG CDECL ldap_create_sort_controlW( LDAP *ld, LDAPSortKeyW **sortkey, UCHAR critical, LDAPControlW **control )
 {
     ULONG ret;
     LDAPSortKeyU **sortkeyU;
@@ -150,17 +149,17 @@ ULONG CDECL ldap_create_sort_controlW( WLDAP32_LDAP *ld, LDAPSortKeyW **sortkey,
 
     TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
 
-    if (!ld || !sortkey || !control) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !sortkey || !control) return LDAP_PARAM_ERROR;
 
-    if (!(sortkeyU = sortkeyarrayWtoU( sortkey ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (!(sortkeyU = sortkeyarrayWtoU( sortkey ))) return LDAP_NO_MEMORY;
 
-    ret = map_error( ldap_funcs->ldap_create_sort_control( ld->ld, sortkeyU, critical, &controlU ) );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    ret = map_error( ldap_funcs->fn_ldap_create_sort_control( CTX(ld), sortkeyU, critical, &controlU ) );
+    if (ret == LDAP_SUCCESS)
     {
         LDAPControlW *controlW = controlUtoW( controlU );
         if (controlW) *control = controlW;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
-        ldap_funcs->ldap_control_free( controlU );
+        else ret = LDAP_NO_MEMORY;
+        ldap_funcs->fn_ldap_control_free( controlU );
     }
 
     sortkeyarrayfreeU( sortkeyU );
@@ -172,8 +171,7 @@ ULONG CDECL ldap_create_sort_controlW( WLDAP32_LDAP *ld, LDAPSortKeyW **sortkey,
  *
  * See ldap_create_vlv_controlW.
  */
-INT CDECL ldap_create_vlv_controlA( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info, UCHAR critical,
-    LDAPControlA **control )
+INT CDECL ldap_create_vlv_controlA( LDAP *ld, LDAPVLVInfo *info, UCHAR critical, LDAPControlA **control )
 {
     INT ret;
     LDAPControlW *controlW;
@@ -183,11 +181,11 @@ INT CDECL ldap_create_vlv_controlA( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
     if (!ld || !control) return ~0u;
 
     ret = ldap_create_vlv_controlW( ld, info, critical, &controlW );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    if (ret == LDAP_SUCCESS)
     {
         LDAPControlA *controlA = controlWtoA( controlW );
         if (controlA) *control = controlA;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
+        else ret = LDAP_NO_MEMORY;
         ldap_control_freeW( controlW );
     }
 
@@ -216,8 +214,7 @@ INT CDECL ldap_create_vlv_controlA( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
  *  server will then return a sorted, contiguous subset of results
  *  that meets the criteria specified in the LDAPVLVInfo structure.
  */
-INT CDECL ldap_create_vlv_controlW( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info, UCHAR critical,
-    LDAPControlW **control )
+INT CDECL ldap_create_vlv_controlW( LDAP *ld, LDAPVLVInfo *info, UCHAR critical, LDAPControlW **control )
 {
     ULONG ret;
     LDAPVLVInfoU *infoU = NULL;
@@ -227,22 +224,22 @@ INT CDECL ldap_create_vlv_controlW( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
 
     if (!ld || !control) return ~0u;
 
-    if (info && !(infoU = vlvinfoWtoU( info ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (info && !(infoU = vlvinfoWtoU( info ))) return LDAP_NO_MEMORY;
 
-    ret = map_error( ldap_funcs->ldap_create_vlv_control( ld->ld, infoU, &controlU ) );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    ret = map_error( ldap_funcs->fn_ldap_create_vlv_control( CTX(ld), infoU, &controlU ) );
+    if (ret == LDAP_SUCCESS)
     {
         LDAPControlW *controlW = controlUtoW( controlU );
         if (controlW) *control = controlW;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
-        ldap_funcs->ldap_control_free( controlU );
+        else ret = LDAP_NO_MEMORY;
+        ldap_funcs->fn_ldap_control_free( controlU );
     }
 
     vlvinfofreeU( infoU );
     return ret;
 }
 
-static inline void bv_val_dup( const struct WLDAP32_berval *src, struct WLDAP32_berval *dst )
+static inline void bv_val_dup( const struct berval *src, struct berval *dst )
 {
     if ((dst->bv_val = RtlAllocateHeap( GetProcessHeap(), 0 , src->bv_len )))
     {
@@ -258,12 +255,12 @@ static inline void bv_val_dup( const struct WLDAP32_berval *src, struct WLDAP32_
  *
  * See ldap_encode_sort_controlW.
  */
-ULONG CDECL ldap_encode_sort_controlA( WLDAP32_LDAP *ld, LDAPSortKeyA **sortkeys, LDAPControlA *ret, BOOLEAN critical )
+ULONG CDECL ldap_encode_sort_controlA( LDAP *ld, LDAPSortKeyA **sortkeys, LDAPControlA *ret, BOOLEAN critical )
 {
     LDAPControlA *control;
     ULONG result;
 
-    if ((result = ldap_create_sort_controlA( ld, sortkeys, critical, &control )) == WLDAP32_LDAP_SUCCESS)
+    if ((result = ldap_create_sort_controlA( ld, sortkeys, critical, &control )) == LDAP_SUCCESS)
     {
         ret->ldctl_oid = strdupU(control->ldctl_oid);
         bv_val_dup( &control->ldctl_value, &ret->ldctl_value );
@@ -295,12 +292,12 @@ ULONG CDECL ldap_encode_sort_controlA( WLDAP32_LDAP *ld, LDAPSortKeyA **sortkeys
  *  This function is obsolete. Use its equivalent
  *  ldap_create_sort_control instead.
  */
-ULONG CDECL ldap_encode_sort_controlW( WLDAP32_LDAP *ld, LDAPSortKeyW **sortkeys, LDAPControlW *ret, BOOLEAN critical )
+ULONG CDECL ldap_encode_sort_controlW( LDAP *ld, LDAPSortKeyW **sortkeys, LDAPControlW *ret, BOOLEAN critical )
 {
     LDAPControlW *control;
     ULONG result;
 
-    if ((result = ldap_create_sort_controlW( ld, sortkeys, critical, &control )) == WLDAP32_LDAP_SUCCESS)
+    if ((result = ldap_create_sort_controlW( ld, sortkeys, critical, &control )) == LDAP_SUCCESS)
     {
         ret->ldctl_oid = strdupW(control->ldctl_oid);
         bv_val_dup( &control->ldctl_value, &ret->ldctl_value );
diff --git a/dlls/wldap32/delete.c b/dlls/wldap32/delete.c
index 2f3d078629f..21fd8d08d4b 100644
--- a/dlls/wldap32/delete.c
+++ b/dlls/wldap32/delete.c
@@ -22,6 +22,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -33,7 +34,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *
  * See ldap_deleteW.
  */
-ULONG CDECL ldap_deleteA( WLDAP32_LDAP *ld, char *dn )
+ULONG CDECL ldap_deleteA( LDAP *ld, char *dn )
 {
     ULONG ret;
     WCHAR *dnW = NULL;
@@ -41,7 +42,7 @@ ULONG CDECL ldap_deleteA( WLDAP32_LDAP *ld, char *dn )
     TRACE( "(%p, %s)\n", ld, debugstr_a(dn) );
 
     if (!ld) return ~0u;
-    if (dn && !(dnW = strAtoW( dn ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (dn && !(dnW = strAtoW( dn ))) return LDAP_NO_MEMORY;
 
     ret = ldap_deleteW( ld, dnW );
     free( dnW );
@@ -66,14 +67,14 @@ ULONG CDECL ldap_deleteA( WLDAP32_LDAP *ld, char *dn )
  *  the operation. Cancel the operation by calling ldap_abandon
  *  with the message ID.
  */
-ULONG CDECL ldap_deleteW( WLDAP32_LDAP *ld, WCHAR *dn )
+ULONG CDECL ldap_deleteW( LDAP *ld, WCHAR *dn )
 {
     ULONG ret, msg;
 
     TRACE( "(%p, %s)\n", ld, debugstr_w(dn) );
 
     ret = ldap_delete_extW( ld, dn, NULL, NULL, &msg );
-    if (ret == WLDAP32_LDAP_SUCCESS) return msg;
+    if (ret == LDAP_SUCCESS) return msg;
     return ~0u;
 }
 
@@ -82,16 +83,16 @@ ULONG CDECL ldap_deleteW( WLDAP32_LDAP *ld, WCHAR *dn )
  *
  * See ldap_delete_extW.
  */
-ULONG CDECL ldap_delete_extA( WLDAP32_LDAP *ld, char *dn, LDAPControlA **serverctrls,
-    LDAPControlA **clientctrls, ULONG *message )
+ULONG CDECL ldap_delete_extA( LDAP *ld, char *dn, LDAPControlA **serverctrls, LDAPControlA **clientctrls,
+    ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), serverctrls, clientctrls, message );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit;
@@ -127,22 +128,22 @@ exit:
  *  the operation. The serverctrls and clientctrls parameters are
  *  optional and should be set to NULL if not used.
  */
-ULONG CDECL ldap_delete_extW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPControlW **serverctrls,
-    LDAPControlW **clientctrls, ULONG *message )
+ULONG CDECL ldap_delete_extW( LDAP *ld, WCHAR *dn, LDAPControlW **serverctrls, LDAPControlW **clientctrls,
+    ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), serverctrls, clientctrls, message );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_delete_ext( ld->ld, dnU, serverctrlsU, clientctrlsU, message ) );
+    ret = map_error( ldap_funcs->fn_ldap_delete_ext( CTX(ld), dnU, serverctrlsU, clientctrlsU, message ) );
 
 exit:
     free( dnU );
@@ -156,16 +157,15 @@ exit:
  *
  * See ldap_delete_ext_sW.
  */
-ULONG CDECL ldap_delete_ext_sA( WLDAP32_LDAP *ld, char *dn, LDAPControlA **serverctrls,
-    LDAPControlA **clientctrls )
+ULONG CDECL ldap_delete_ext_sA( LDAP *ld, char *dn, LDAPControlA **serverctrls, LDAPControlA **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %p, %p)\n", ld, debugstr_a(dn), serverctrls, clientctrls );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit;
@@ -199,22 +199,21 @@ exit:
  *  The serverctrls and clientctrls parameters are optional and
  *  should be set to NULL if not used.
  */
-ULONG CDECL ldap_delete_ext_sW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPControlW **serverctrls,
-    LDAPControlW **clientctrls )
+ULONG CDECL ldap_delete_ext_sW( LDAP *ld, WCHAR *dn, LDAPControlW **serverctrls, LDAPControlW **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
 
     TRACE( "(%p, %s, %p, %p)\n", ld, debugstr_w(dn), serverctrls, clientctrls );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_delete_ext_s( ld->ld, dnU, serverctrlsU, clientctrlsU ) );
+    ret = map_error( ldap_funcs->fn_ldap_delete_ext_s( CTX(ld), dnU, serverctrlsU, clientctrlsU ) );
 
 exit:
     free( dnU );
@@ -228,15 +227,15 @@ exit:
  *
  * See ldap_delete_sW.
  */
-ULONG CDECL ldap_delete_sA( WLDAP32_LDAP *ld, char *dn )
+ULONG CDECL ldap_delete_sA( LDAP *ld, char *dn )
 {
     ULONG ret;
     WCHAR *dnW = NULL;
 
     TRACE( "(%p, %s)\n", ld, debugstr_a(dn) );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
-    if (dn && !(dnW = strAtoW( dn ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (!ld) return LDAP_PARAM_ERROR;
+    if (dn && !(dnW = strAtoW( dn ))) return LDAP_NO_MEMORY;
 
     ret = ldap_delete_sW( ld, dnW );
     free( dnW );
@@ -256,7 +255,7 @@ ULONG CDECL ldap_delete_sA( WLDAP32_LDAP *ld, char *dn )
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_delete_sW( WLDAP32_LDAP *ld, WCHAR *dn )
+ULONG CDECL ldap_delete_sW( LDAP *ld, WCHAR *dn )
 {
     TRACE( "(%p, %s)\n", ld, debugstr_w(dn) );
     return ldap_delete_ext_sW( ld, dn, NULL, NULL );
diff --git a/dlls/wldap32/dn.c b/dlls/wldap32/dn.c
index e9a6be999a8..1528d8aef1e 100644
--- a/dlls/wldap32/dn.c
+++ b/dlls/wldap32/dn.c
@@ -22,6 +22,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -74,11 +75,11 @@ WCHAR * CDECL ldap_dn2ufnW( WCHAR *dn )
 
     if (!(dnU = strWtoU( dn ))) return NULL;
 
-    retU = ldap_funcs->ldap_dn2ufn( dnU );
+    retU = ldap_funcs->fn_ldap_dn2ufn( dnU );
     ret = strUtoW( retU );
 
     free( dnU );
-    ldap_funcs->ldap_memfree( retU );
+    ldap_funcs->fn_ldap_memfree( retU );
     return ret;
 }
 
@@ -130,11 +131,11 @@ WCHAR ** CDECL ldap_explode_dnW( WCHAR *dn, ULONG notypes )
 
     if (!(dnU = strWtoU( dn ))) return NULL;
 
-    retU = ldap_funcs->ldap_explode_dn( dnU, notypes );
+    retU = ldap_funcs->fn_ldap_explode_dn( dnU, notypes );
     ret = strarrayUtoW( retU );
 
     free( dnU );
-    ldap_funcs->ldap_memvfree( (void **)retU );
+    ldap_funcs->fn_ldap_memvfree( (void **)retU );
     return ret;
 }
 
@@ -143,7 +144,7 @@ WCHAR ** CDECL ldap_explode_dnW( WCHAR *dn, ULONG notypes )
  *
  * See ldap_get_dnW.
  */
-char * CDECL ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
+char * CDECL ldap_get_dnA( LDAP *ld, LDAPMessage *entry )
 {
     char *ret;
     WCHAR *retW;
@@ -175,7 +176,7 @@ char * CDECL ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
  * NOTES
  *  Free the string with ldap_memfree.
  */
-WCHAR * CDECL ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
+WCHAR * CDECL ldap_get_dnW( LDAP *ld, LDAPMessage *entry )
 {
     WCHAR *ret;
     char *retU;
@@ -184,10 +185,10 @@ WCHAR * CDECL ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
 
     if (!ld || !entry) return NULL;
 
-    retU = ldap_funcs->ldap_get_dn( ld->ld, entry->Request );
+    retU = ldap_funcs->fn_ldap_get_dn( CTX(ld), MSG(entry) );
 
     ret = strUtoW( retU );
-    ldap_funcs->ldap_memfree( retU );
+    ldap_funcs->fn_ldap_memfree( retU );
     return ret;
 }
 
@@ -203,16 +204,16 @@ ULONG CDECL ldap_ufn2dnA( char *ufn, char **dn )
 
     TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
 
-    if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!dn) return LDAP_PARAM_ERROR;
 
     *dn = NULL;
-    if (ufn && !(ufnW = strAtoW( ufn ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (ufn && !(ufnW = strAtoW( ufn ))) return LDAP_NO_MEMORY;
 
     ret = ldap_ufn2dnW( ufnW, &dnW );
     if (dnW)
     {
         char *str;
-        if (!(str = strWtoA( dnW ))) ret = WLDAP32_LDAP_NO_MEMORY;
+        if (!(str = strWtoA( dnW ))) ret = LDAP_NO_MEMORY;
         else *dn = str;
     }
 
@@ -239,21 +240,21 @@ ULONG CDECL ldap_ufn2dnA( char *ufn, char **dn )
  */
 ULONG CDECL ldap_ufn2dnW( WCHAR *ufn, WCHAR **dn )
 {
-    ULONG ret = WLDAP32_LDAP_SUCCESS;
+    ULONG ret = LDAP_SUCCESS;
     char *ufnU = NULL;
 
     TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
 
-    if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!dn) return LDAP_PARAM_ERROR;
 
     *dn = NULL;
     if (ufn)
     {
         WCHAR *str;
-        if (!(ufnU = strWtoU( ufn ))) return WLDAP32_LDAP_NO_MEMORY;
+        if (!(ufnU = strWtoU( ufn ))) return LDAP_NO_MEMORY;
 
         /* FIXME: do more than just a copy */
-        if (!(str = strUtoW( ufnU ))) ret = WLDAP32_LDAP_NO_MEMORY;
+        if (!(str = strUtoW( ufnU ))) ret = LDAP_NO_MEMORY;
         else *dn = str;
     }
 
diff --git a/dlls/wldap32/error.c b/dlls/wldap32/error.c
index a56adc11c02..e7a19144bf2 100644
--- a/dlls/wldap32/error.c
+++ b/dlls/wldap32/error.c
@@ -23,6 +23,7 @@
 #include "winbase.h"
 #include "winuser.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -35,24 +36,24 @@ ULONG map_error( int error )
 {
     switch (error)
     {
-    case  0:    return WLDAP32_LDAP_SUCCESS;
-    case -1:    return WLDAP32_LDAP_SERVER_DOWN;
-    case -2:    return WLDAP32_LDAP_LOCAL_ERROR;
-    case -3:    return WLDAP32_LDAP_ENCODING_ERROR;
-    case -4:    return WLDAP32_LDAP_DECODING_ERROR;
-    case -5:    return WLDAP32_LDAP_TIMEOUT;
-    case -6:    return WLDAP32_LDAP_AUTH_UNKNOWN;
-    case -7:    return WLDAP32_LDAP_FILTER_ERROR;
-    case -8:    return WLDAP32_LDAP_USER_CANCELLED;
-    case -9:    return WLDAP32_LDAP_PARAM_ERROR;
-    case -10:   return WLDAP32_LDAP_NO_MEMORY;
-    case -11:   return WLDAP32_LDAP_CONNECT_ERROR;
-    case -12:   return WLDAP32_LDAP_NOT_SUPPORTED;
-    case -13:   return WLDAP32_LDAP_CONTROL_NOT_FOUND;
-    case -14:   return WLDAP32_LDAP_NO_RESULTS_RETURNED;
-    case -15:   return WLDAP32_LDAP_MORE_RESULTS_TO_RETURN;
-    case -16:   return WLDAP32_LDAP_CLIENT_LOOP;
-    case -17:   return WLDAP32_LDAP_REFERRAL_LIMIT_EXCEEDED;
+    case  0:    return LDAP_SUCCESS;
+    case -1:    return LDAP_SERVER_DOWN;
+    case -2:    return LDAP_LOCAL_ERROR;
+    case -3:    return LDAP_ENCODING_ERROR;
+    case -4:    return LDAP_DECODING_ERROR;
+    case -5:    return LDAP_TIMEOUT;
+    case -6:    return LDAP_AUTH_UNKNOWN;
+    case -7:    return LDAP_FILTER_ERROR;
+    case -8:    return LDAP_USER_CANCELLED;
+    case -9:    return LDAP_PARAM_ERROR;
+    case -10:   return LDAP_NO_MEMORY;
+    case -11:   return LDAP_CONNECT_ERROR;
+    case -12:   return LDAP_NOT_SUPPORTED;
+    case -13:   return LDAP_CONTROL_NOT_FOUND;
+    case -14:   return LDAP_NO_RESULTS_RETURNED;
+    case -15:   return LDAP_MORE_RESULTS_TO_RETURN;
+    case -16:   return LDAP_CLIENT_LOOP;
+    case -17:   return LDAP_REFERRAL_LIMIT_EXCEEDED;
     default: return error;
     }
 }
@@ -68,10 +69,10 @@ char * CDECL ldap_err2stringA( ULONG err )
 
     TRACE( "(0x%08x)\n", err );
 
-    if (err <= WLDAP32_LDAP_REFERRAL_LIMIT_EXCEEDED)
+    if (err <= LDAP_REFERRAL_LIMIT_EXCEEDED)
         LoadStringA( hwldap32, err, buf, 256 );
     else
-        LoadStringA( hwldap32, WLDAP32_LDAP_LOCAL_ERROR, buf, 256 );
+        LoadStringA( hwldap32, LDAP_LOCAL_ERROR, buf, 256 );
 
     return buf;
 }
@@ -98,10 +99,10 @@ WCHAR * CDECL ldap_err2stringW( ULONG err )
 
     TRACE( "(0x%08x)\n", err );
 
-    if (err <= WLDAP32_LDAP_REFERRAL_LIMIT_EXCEEDED)
+    if (err <= LDAP_REFERRAL_LIMIT_EXCEEDED)
         LoadStringW( hwldap32, err, buf, 256 );
     else
-        LoadStringW( hwldap32, WLDAP32_LDAP_LOCAL_ERROR, buf, 256 );
+        LoadStringW( hwldap32, LDAP_LOCAL_ERROR, buf, 256 );
 
     return buf;
 }
@@ -121,7 +122,7 @@ WCHAR * CDECL ldap_err2stringW( ULONG err )
  * NOTES
  *  Like native, this function does nothing.
  */
-void CDECL WLDAP32_ldap_perror( WLDAP32_LDAP *ld, const PCHAR msg )
+void CDECL ldap_perror( LDAP *ld, const PCHAR msg )
 {
     TRACE( "(%p, %s)\n", ld, debugstr_a(msg) );
 }
@@ -143,7 +144,7 @@ void CDECL WLDAP32_ldap_perror( WLDAP32_LDAP *ld, const PCHAR msg )
  * NOTES
  *  If not asked for, use ldap_msgfree to free the LDAPMessage.
  */
-ULONG CDECL WLDAP32_ldap_result2error( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *res, ULONG free )
+ULONG CDECL ldap_result2error( LDAP *ld, LDAPMessage *res, ULONG free )
 {
     ULONG ret;
     int error;
@@ -152,8 +153,8 @@ ULONG CDECL WLDAP32_ldap_result2error( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *re
 
     if (!ld || !res) return ~0u;
 
-    ret = map_error( ldap_funcs->ldap_parse_result( ld->ld, res->Request, &error, NULL, NULL, NULL, NULL, free ) );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    ret = map_error( ldap_funcs->fn_ldap_parse_result( CTX(ld), MSG(res), &error, NULL, NULL, NULL, NULL, free ) );
+    if (ret == LDAP_SUCCESS)
         ret = error;
     else
         ret = ~0u;
@@ -178,7 +179,7 @@ ULONG CDECL LdapGetLastError( void )
     return GetLastError();
 }
 
-static const ULONG WLDAP32_errormap[] = {
+static const ULONG errormap[] = {
     /* LDAP_SUCCESS */                      ERROR_SUCCESS,
     /* LDAP_OPERATIONS_ERROR */             ERROR_OPEN_FAILED,
     /* LDAP_PROTOCOL_ERROR */               ERROR_INVALID_LEVEL,
@@ -294,6 +295,6 @@ ULONG CDECL LdapMapErrorToWin32( ULONG err )
 {
     TRACE( "(0x%08x)\n", err );
 
-    if (err >= ARRAY_SIZE( WLDAP32_errormap )) return ERROR_DS_GENERIC_ERROR;
-    return WLDAP32_errormap[err];
+    if (err >= ARRAY_SIZE( errormap )) return ERROR_DS_GENERIC_ERROR;
+    return errormap[err];
 }
diff --git a/dlls/wldap32/extended.c b/dlls/wldap32/extended.c
index 2a71ce59acf..3b33b0e588b 100644
--- a/dlls/wldap32/extended.c
+++ b/dlls/wldap32/extended.c
@@ -22,6 +22,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -45,12 +46,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *  Contrary to native, OpenLDAP does not require us to close
  *  extended operations, so this is a no-op.
  */
-ULONG CDECL ldap_close_extended_op( WLDAP32_LDAP *ld, ULONG msgid )
+ULONG CDECL ldap_close_extended_op( LDAP *ld, ULONG msgid )
 {
     TRACE( "(%p, 0x%08x)\n", ld, msgid );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
-    return WLDAP32_LDAP_SUCCESS;
+    if (!ld) return LDAP_PARAM_ERROR;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -58,16 +59,16 @@ ULONG CDECL ldap_close_extended_op( WLDAP32_LDAP *ld, ULONG msgid )
  *
  * See ldap_extended_operationW.
  */
-ULONG CDECL ldap_extended_operationA( WLDAP32_LDAP *ld, char *oid, struct WLDAP32_berval *data,
-    LDAPControlA **serverctrls, LDAPControlA **clientctrls, ULONG *message )
+ULONG CDECL ldap_extended_operationA( LDAP *ld, char *oid, struct berval *data, LDAPControlA **serverctrls,
+    LDAPControlA **clientctrls, ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *oidW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls, clientctrls, message );
 
-    if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !message) return LDAP_PARAM_ERROR;
 
     if (oid && !(oidW = strAtoW( oid ))) goto exit;
     if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit;
@@ -107,24 +108,25 @@ exit:
  *  are optional and should be set to NULL if not used. Call
  *  ldap_close_extended_op to close the operation.
  */
-ULONG CDECL ldap_extended_operationW( WLDAP32_LDAP *ld, WCHAR *oid, struct WLDAP32_berval *data,
-    LDAPControlW **serverctrls, LDAPControlW **clientctrls, ULONG *message )
+ULONG CDECL ldap_extended_operationW( LDAP *ld, WCHAR *oid, struct berval *data, LDAPControlW **serverctrls,
+    LDAPControlW **clientctrls, ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *oidU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
     struct bervalU *dataU = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls, clientctrls, message );
 
-    if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !message) return LDAP_PARAM_ERROR;
 
     if (oid && !(oidU = strWtoU( oid ))) goto exit;
     if (data && !(dataU = bervalWtoU( data ))) goto exit;
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_extended_operation( ld->ld, oidU, dataU, serverctrlsU, clientctrlsU, message ) );
+    ret = map_error( ldap_funcs->fn_ldap_extended_operation( CTX(ld), oidU, dataU, serverctrlsU, clientctrlsU,
+                                                             message ) );
 
 exit:
     free( oidU );
@@ -139,16 +141,16 @@ exit:
  *
  * See ldap_extended_operation_sW.
  */
-ULONG CDECL ldap_extended_operation_sA( WLDAP32_LDAP *ld, char *oid, struct WLDAP32_berval *data,
-    LDAPControlA **serverctrls, LDAPControlA **clientctrls, char **retoid, struct WLDAP32_berval **retdata )
+ULONG CDECL ldap_extended_operation_sA( LDAP *ld, char *oid, struct berval *data, LDAPControlA **serverctrls,
+    LDAPControlA **clientctrls, char **retoid, struct berval **retdata )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *oidW = NULL, *retoidW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls, clientctrls, retoid, retdata );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (oid && !(oidW = strAtoW( oid ))) goto exit;
     if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit;
@@ -159,7 +161,7 @@ ULONG CDECL ldap_extended_operation_sA( WLDAP32_LDAP *ld, char *oid, struct WLDA
     {
         char *str = strWtoA( retoidW );
         if (str) *retoid = str;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
+        else ret = LDAP_NO_MEMORY;
         ldap_memfreeW( retoidW );
     }
 
@@ -194,38 +196,38 @@ exit:
  *  and retdata parameters are also optional. Set to NULL if not
  *  used. Free retoid and retdata after use with ldap_memfree.
  */
-ULONG CDECL ldap_extended_operation_sW( WLDAP32_LDAP *ld, WCHAR *oid, struct WLDAP32_berval *data,
-    LDAPControlW **serverctrls, LDAPControlW **clientctrls, WCHAR **retoid, struct WLDAP32_berval **retdata )
+ULONG CDECL ldap_extended_operation_sW( LDAP *ld, WCHAR *oid, struct berval *data, LDAPControlW **serverctrls,
+    LDAPControlW **clientctrls, WCHAR **retoid, struct berval **retdata )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *oidU = NULL, *retoidU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
     struct bervalU *retdataU, *dataU = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls, clientctrls, retoid, retdata );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (oid && !(oidU = strWtoU( oid ))) goto exit;
     if (data && !(dataU = bervalWtoU( data ))) goto exit;
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_extended_operation_s( ld->ld, oidU, dataU, serverctrlsU, clientctrlsU,
-                                                            &retoidU, &retdataU ) );
+    ret = map_error( ldap_funcs->fn_ldap_extended_operation_s( CTX(ld), oidU, dataU, serverctrlsU, clientctrlsU,
+                                                               &retoidU, &retdataU ) );
     if (retoid && retoidU)
     {
         WCHAR *str = strUtoW( retoidU );
         if (str) *retoid = str;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
-        ldap_funcs->ldap_memfree( retoidU );
+        else ret = LDAP_NO_MEMORY;
+        ldap_funcs->fn_ldap_memfree( retoidU );
     }
     if (retdata && retdataU)
     {
-        struct WLDAP32_berval *bv = bervalUtoW( retdataU );
+        struct berval *bv = bervalUtoW( retdataU );
         if (bv) *retdata = bv;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
-        ldap_funcs->ber_bvfree( retdataU );
+        else ret = LDAP_NO_MEMORY;
+        ldap_funcs->fn_ber_bvfree( retdataU );
     }
 
 exit:
diff --git a/dlls/wldap32/init.c b/dlls/wldap32/init.c
index 8043164ad30..35f97754f64 100644
--- a/dlls/wldap32/init.c
+++ b/dlls/wldap32/init.c
@@ -24,6 +24,7 @@
 #include "winbase.h"
 #include "winnls.h"
 #include "winternl.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -190,18 +191,18 @@ static char *urlify_hostnames( const char *scheme, char *hostnames, ULONG port )
 }
 
 
-static WLDAP32_LDAP *create_context( const char *url )
+static LDAP *create_context( const char *url )
 {
-    WLDAP32_LDAP *ld;
-    int version = WLDAP32_LDAP_VERSION3;
+    LDAP *ld;
+    int version = LDAP_VERSION3;
 
     if (!(ld = calloc( 1, sizeof( *ld )))) return NULL;
-    if (map_error( ldap_funcs->ldap_initialize( &ld->ld, url ) ) != WLDAP32_LDAP_SUCCESS)
+    if (map_error( ldap_funcs->fn_ldap_initialize( &CTX(ld), url ) ) != LDAP_SUCCESS)
     {
         free( ld );
         return NULL;
     }
-    ldap_funcs->ldap_set_option( ld->ld, WLDAP32_LDAP_OPT_PROTOCOL_VERSION, &version );
+    ldap_funcs->fn_ldap_set_option( CTX(ld), LDAP_OPT_PROTOCOL_VERSION, &version );
     return ld;
 }
 
@@ -210,9 +211,9 @@ static WLDAP32_LDAP *create_context( const char *url )
  *
  * See cldap_openW.
  */
-WLDAP32_LDAP * CDECL cldap_openA( char *hostname, ULONG portnumber )
+LDAP * CDECL cldap_openA( char *hostname, ULONG portnumber )
 {
-    WLDAP32_LDAP *ld;
+    LDAP *ld;
     WCHAR *hostnameW = NULL;
 
     TRACE( "(%s, %d)\n", debugstr_a(hostname), portnumber );
@@ -246,9 +247,9 @@ WLDAP32_LDAP * CDECL cldap_openA( char *hostname, ULONG portnumber )
  *  will take precedence over the port number supplied as a parameter
  *  to this function.
  */
-WLDAP32_LDAP * CDECL cldap_openW( WCHAR *hostname, ULONG portnumber )
+LDAP * CDECL cldap_openW( WCHAR *hostname, ULONG portnumber )
 {
-    WLDAP32_LDAP *ld = NULL;
+    LDAP *ld = NULL;
     char *hostnameU, *url = NULL;
 
     TRACE( "(%s, %d)\n", debugstr_w(hostname), portnumber );
@@ -282,12 +283,12 @@ exit:
  *  The timeout parameter may be NULL in which case a default timeout
  *  value will be used.
  */
-ULONG CDECL ldap_connect( WLDAP32_LDAP *ld, struct l_timeval *timeout )
+ULONG CDECL ldap_connect( LDAP *ld, struct l_timeval *timeout )
 {
     TRACE( "(%p, %p)\n", ld, timeout );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
-    return WLDAP32_LDAP_SUCCESS; /* FIXME: do something, e.g. ping the host */
+    if (!ld) return LDAP_PARAM_ERROR;
+    return LDAP_SUCCESS; /* FIXME: do something, e.g. ping the host */
 }
 
 /***********************************************************************
@@ -295,9 +296,9 @@ ULONG CDECL ldap_connect( WLDAP32_LDAP *ld, struct l_timeval *timeout )
  *
  * See ldap_initW.
  */
-WLDAP32_LDAP *  CDECL ldap_initA( const PCHAR hostname, ULONG portnumber )
+LDAP *  CDECL ldap_initA( const PCHAR hostname, ULONG portnumber )
 {
-    WLDAP32_LDAP *ld;
+    LDAP *ld;
     WCHAR *hostnameW = NULL;
 
     TRACE( "(%s, %d)\n", debugstr_a(hostname), portnumber );
@@ -332,9 +333,9 @@ WLDAP32_LDAP *  CDECL ldap_initA( const PCHAR hostname, ULONG portnumber )
  *  to this function. The connection will not be made until the first
  *  LDAP function that needs it is called.
  */
-WLDAP32_LDAP * CDECL ldap_initW( const PWCHAR hostname, ULONG portnumber )
+LDAP * CDECL ldap_initW( const PWCHAR hostname, ULONG portnumber )
 {
-    WLDAP32_LDAP *ld = NULL;
+    LDAP *ld = NULL;
     char *hostnameU, *url = NULL;
 
     TRACE( "(%s, %d)\n", debugstr_w(hostname), portnumber );
@@ -355,9 +356,9 @@ exit:
  *
  * See ldap_openW.
  */
-WLDAP32_LDAP * CDECL ldap_openA( char *hostname, ULONG portnumber )
+LDAP * CDECL ldap_openA( char *hostname, ULONG portnumber )
 {
-    WLDAP32_LDAP *ld;
+    LDAP *ld;
     WCHAR *hostnameW = NULL;
 
     TRACE( "(%s, %d)\n", debugstr_a(hostname), portnumber );
@@ -391,9 +392,9 @@ WLDAP32_LDAP * CDECL ldap_openA( char *hostname, ULONG portnumber )
  *  will take precedence over the port number supplied as a parameter
  *  to this function.
  */
-WLDAP32_LDAP * CDECL ldap_openW( WCHAR *hostname, ULONG portnumber )
+LDAP * CDECL ldap_openW( WCHAR *hostname, ULONG portnumber )
 {
-    WLDAP32_LDAP *ld = NULL;
+    LDAP *ld = NULL;
     char *hostnameU, *url = NULL;
 
     TRACE( "(%s, %d)\n", debugstr_w(hostname), portnumber );
@@ -414,9 +415,9 @@ exit:
  *
  * See ldap_sslinitW.
  */
-WLDAP32_LDAP * CDECL ldap_sslinitA( char *hostname, ULONG portnumber, int secure )
+LDAP * CDECL ldap_sslinitA( char *hostname, ULONG portnumber, int secure )
 {
-    WLDAP32_LDAP *ld;
+    LDAP *ld;
     WCHAR *hostnameW = NULL;
 
     TRACE( "(%s, %d, 0x%08x)\n", debugstr_a(hostname), portnumber, secure );
@@ -452,9 +453,9 @@ WLDAP32_LDAP * CDECL ldap_sslinitA( char *hostname, ULONG portnumber, int secure
  *  to this function. The connection will not be made until the first
  *  LDAP function that needs it is called.
  */
-WLDAP32_LDAP * CDECL ldap_sslinitW( WCHAR *hostname, ULONG portnumber, int secure )
+LDAP * CDECL ldap_sslinitW( WCHAR *hostname, ULONG portnumber, int secure )
 {
-    WLDAP32_LDAP *ld = NULL;
+    LDAP *ld = NULL;
     char *hostnameU, *url = NULL;
 
     TRACE( "(%s, %d, 0x%08x)\n", debugstr_w(hostname), portnumber, secure );
@@ -480,10 +481,10 @@ exit:
  *
  * See ldap_start_tls_sW.
  */
-ULONG CDECL ldap_start_tls_sA( WLDAP32_LDAP *ld, ULONG *retval, WLDAP32_LDAPMessage **result,
-    LDAPControlA **serverctrls, LDAPControlA **clientctrls )
+ULONG CDECL ldap_start_tls_sA( LDAP *ld, ULONG *retval, LDAPMessage **result, LDAPControlA **serverctrls,
+    LDAPControlA **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %p, %p, %p, %p)\n", ld, retval, result, serverctrls, clientctrls );
@@ -520,10 +521,10 @@ exit:
  * NOTES
  *  LDAP function that needs it is called.
  */
-ULONG CDECL ldap_start_tls_sW( WLDAP32_LDAP *ld, ULONG *retval, WLDAP32_LDAPMessage **result,
-    LDAPControlW **serverctrls, LDAPControlW **clientctrls )
+ULONG CDECL ldap_start_tls_sW( LDAP *ld, ULONG *retval, LDAPMessage **result, LDAPControlW **serverctrls,
+    LDAPControlW **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
 
     TRACE( "(%p, %p, %p, %p, %p)\n", ld, retval, result, serverctrls, clientctrls );
@@ -538,7 +539,7 @@ ULONG CDECL ldap_start_tls_sW( WLDAP32_LDAP *ld, ULONG *retval, WLDAP32_LDAPMess
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_start_tls_s( ld->ld, serverctrlsU, clientctrlsU ) );
+    ret = map_error( ldap_funcs->fn_ldap_start_tls_s( CTX(ld), serverctrlsU, clientctrlsU ) );
 
 exit:
     controlarrayfreeU( serverctrlsU );
@@ -552,7 +553,7 @@ exit:
 ULONG CDECL ldap_startup( LDAP_VERSION_INFO *version, HANDLE *instance )
 {
     TRACE( "(%p, %p)\n", version, instance );
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -567,7 +568,7 @@ ULONG CDECL ldap_startup( LDAP_VERSION_INFO *version, HANDLE *instance )
  *  Success: TRUE
  *  Failure: FALSE
  */
-BOOLEAN CDECL ldap_stop_tls_s( WLDAP32_LDAP *ld )
+BOOLEAN CDECL ldap_stop_tls_s( LDAP *ld )
 {
     TRACE( "(%p)\n", ld );
     return TRUE; /* FIXME: find a way to stop tls on a connection */
diff --git a/dlls/wldap32/libldap.c b/dlls/wldap32/libldap.c
index f71970e2a59..5cea944729d 100644
--- a/dlls/wldap32/libldap.c
+++ b/dlls/wldap32/libldap.c
@@ -25,6 +25,7 @@
 #include "config.h"
 
 #ifdef HAVE_LDAP
+#include <assert.h>
 #include <stdarg.h>
 #include <sys/time.h>
 #ifdef HAVE_LDAP_H
@@ -41,7 +42,7 @@
 #include "winbase.h"
 
 #include "wine/debug.h"
-#include "winldap_private.h"
+#include "libldap.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
 
@@ -54,6 +55,8 @@ C_ASSERT( sizeof(LDAPAPIInfoU) == sizeof(LDAPAPIInfo) );
 C_ASSERT( sizeof(LDAPAPIFeatureInfoU) == sizeof(LDAPAPIFeatureInfo) );
 C_ASSERT( sizeof(struct timevalU) == sizeof(struct timeval) );
 
+#define WLDAP32_LBER_ERROR  (~0l)
+
 static LDAPMod *nullmods[] = { NULL };
 
 static const struct ldap_callbacks *callbacks;
diff --git a/dlls/wldap32/libldap.h b/dlls/wldap32/libldap.h
index cc247e8fd82..3d2719452c4 100644
--- a/dlls/wldap32/libldap.h
+++ b/dlls/wldap32/libldap.h
@@ -184,80 +184,81 @@ extern void CDECL wrap_ldap_value_free_len(struct bervalU **) DECLSPEC_HIDDEN;
 
 struct ldap_funcs
 {
-    void * (CDECL *ber_alloc_t)(int);
-    void (CDECL *ber_bvecfree)(struct bervalU **);
-    void (CDECL *ber_bvfree)(struct bervalU *);
-    unsigned int (CDECL *ber_first_element)(void *, unsigned int *, char **);
-    int (CDECL *ber_flatten)(void *, struct bervalU **);
-    void (CDECL *ber_free)(void *, int);
-    void * (CDECL *ber_init)(struct bervalU *);
-    unsigned int (CDECL *ber_next_element)(void *, unsigned int *, char *);
-    unsigned int (CDECL *ber_peek_tag)(void *, unsigned int *);
-    unsigned int (CDECL *ber_skip_tag)(void *, unsigned int *);
-    int (WINAPIV *ber_printf)(void *, char *, ...);
-    int (WINAPIV *ber_scanf)(void *, char *, ...);
+    void * (CDECL *fn_ber_alloc_t)(int);
+    void (CDECL *fn_ber_bvecfree)(struct bervalU **);
+    void (CDECL *fn_ber_bvfree)(struct bervalU *);
+    unsigned int (CDECL *fn_ber_first_element)(void *, unsigned int *, char **);
+    int (CDECL *fn_ber_flatten)(void *, struct bervalU **);
+    void (CDECL *fn_ber_free)(void *, int);
+    void * (CDECL *fn_ber_init)(struct bervalU *);
+    unsigned int (CDECL *fn_ber_next_element)(void *, unsigned int *, char *);
+    unsigned int (CDECL *fn_ber_peek_tag)(void *, unsigned int *);
+    unsigned int (CDECL *fn_ber_skip_tag)(void *, unsigned int *);
+    int (WINAPIV *fn_ber_printf)(void *, char *, ...);
+    int (WINAPIV *fn_ber_scanf)(void *, char *, ...);
 
-    int (CDECL *ldap_abandon_ext)(void *, int, LDAPControlU **, LDAPControlU **);
-    int (CDECL *ldap_add_ext)(void *, const char *, LDAPModU **, LDAPControlU **, LDAPControlU **, ULONG *);
-    int (CDECL *ldap_add_ext_s)(void *, const char *, LDAPModU **, LDAPControlU **, LDAPControlU **);
-    int (CDECL *ldap_compare_ext)(void *, const char *, const char *, struct bervalU *, LDAPControlU **,
-                                  LDAPControlU **, ULONG *);
-    int (CDECL *ldap_compare_ext_s)(void *, const char *, const char *, struct bervalU *, LDAPControlU **,
-                                    LDAPControlU **);
-    void (CDECL *ldap_control_free)(LDAPControlU *);
-    void (CDECL *ldap_controls_free)(LDAPControlU **);
-    int (CDECL *ldap_count_entries)(void *, void *);
-    int (CDECL *ldap_count_references)(void *, void *);
-    int (CDECL *ldap_count_values_len)(struct bervalU **);
-    int (CDECL *ldap_create_sort_control)(void *, LDAPSortKeyU **, int, LDAPControlU **);
-    int (CDECL *ldap_create_vlv_control)(void *, LDAPVLVInfoU *, LDAPControlU **);
-    int (CDECL *ldap_delete_ext)(void *, const char *, LDAPControlU **, LDAPControlU **, ULONG *);
-    int (CDECL *ldap_delete_ext_s)(void *, const char *, LDAPControlU **, LDAPControlU **);
-    char * (CDECL *ldap_dn2ufn)(const char *);
-    char ** (CDECL *ldap_explode_dn)(const char *, int);
-    int (CDECL *ldap_extended_operation)(void *, const char *, struct bervalU *, LDAPControlU **,
-                                         LDAPControlU **, ULONG *);
-    int (CDECL *ldap_extended_operation_s)(void *, const char *, struct bervalU *, LDAPControlU **,
-                                           LDAPControlU **, char **, struct bervalU **);
-    char * (CDECL *ldap_get_dn)(void *, void *);
-    int (CDECL *ldap_get_option)(void *, int, void *);
-    struct bervalU ** (CDECL *ldap_get_values_len)(void *, void *, const char *);
-    int (CDECL *ldap_initialize)(void **, const char *);
-    char * (CDECL *ldap_first_attribute)(void *, void *, void **);
-    void * (CDECL *ldap_first_entry)(void *, void *);
-    void * (CDECL *ldap_first_reference)(void *, void *);
-    void (CDECL *ldap_memfree)(void *);
-    void (CDECL *ldap_memvfree)(void **);
-    int (CDECL *ldap_modify_ext)(void *, const char *, LDAPModU **, LDAPControlU **, LDAPControlU **, ULONG *);
-    int (CDECL *ldap_modify_ext_s)(void *, const char *, LDAPModU **, LDAPControlU **, LDAPControlU **);
-    int (CDECL *ldap_msgfree)(void *);
-    char * (CDECL *ldap_next_attribute)(void *, void *, void *);
-    void * (CDECL *ldap_next_entry)(void *, void *);
-    void * (CDECL *ldap_next_reference)(void *, void *);
-    int (CDECL *ldap_parse_extended_result)(void *, void *, char **, struct bervalU **, int);
-    int (CDECL *ldap_parse_reference)(void *, void *, char ***, LDAPControlU ***, int);
-    int (CDECL *ldap_parse_result)(void *, void *, int *, char **, char **, char ***, LDAPControlU ***, int);
-    int (CDECL *ldap_parse_sortresponse_control)(void *, LDAPControlU *, int *, char **);
-    int (CDECL *ldap_parse_vlvresponse_control)(void *, LDAPControlU *, int *, int *, struct bervalU **, int *);
-    int (CDECL *ldap_rename)(void *, const char *, const char *, const char *, int, LDAPControlU **, LDAPControlU **,
-                             ULONG *);
-    int (CDECL *ldap_rename_s)(void *, const char *, const char *, const char *, int, LDAPControlU **, LDAPControlU **);
-    int (CDECL *ldap_result)(void *, int, int, struct timevalU *, void **);
-    int (CDECL *ldap_sasl_bind)(void *, const char *, const char *, struct bervalU *, LDAPControlU **, LDAPControlU **,
-                                int *);
-    int (CDECL *ldap_sasl_bind_s)(void *, const char *, const char *, struct bervalU *, LDAPControlU **,
-                                  LDAPControlU **, struct bervalU **);
-    int (CDECL *ldap_sasl_interactive_bind_s)(void *, const char *, const char *, LDAPControlU **, LDAPControlU **,
-                                              unsigned int, void *);
-    int (CDECL *ldap_search_ext)(void *, const char *, int, const char *, char **, int, LDAPControlU **,
-                                 LDAPControlU **, struct timevalU *, int, ULONG *);
-    int (CDECL *ldap_search_ext_s)(void *, const char *, int, const char *, char **, int, LDAPControlU **,
-                                   LDAPControlU **, struct timevalU *, int, void **);
-    int (CDECL *ldap_set_option)(void *, int, const void *);
-    int (CDECL *ldap_start_tls_s)(void *, LDAPControlU **, LDAPControlU **);
-    int (CDECL *ldap_unbind_ext)(void *, LDAPControlU **, LDAPControlU **);
-    int (CDECL *ldap_unbind_ext_s)(void *, LDAPControlU **, LDAPControlU **);
-    void (CDECL *ldap_value_free_len)(struct bervalU **);
+    int (CDECL *fn_ldap_abandon_ext)(void *, int, LDAPControlU **, LDAPControlU **);
+    int (CDECL *fn_ldap_add_ext)(void *, const char *, LDAPModU **, LDAPControlU **, LDAPControlU **, ULONG *);
+    int (CDECL *fn_ldap_add_ext_s)(void *, const char *, LDAPModU **, LDAPControlU **, LDAPControlU **);
+    int (CDECL *fn_ldap_compare_ext)(void *, const char *, const char *, struct bervalU *, LDAPControlU **,
+                                     LDAPControlU **, ULONG *);
+    int (CDECL *fn_ldap_compare_ext_s)(void *, const char *, const char *, struct bervalU *, LDAPControlU **,
+                                       LDAPControlU **);
+    void (CDECL *fn_ldap_control_free)(LDAPControlU *);
+    void (CDECL *fn_ldap_controls_free)(LDAPControlU **);
+    int (CDECL *fn_ldap_count_entries)(void *, void *);
+    int (CDECL *fn_ldap_count_references)(void *, void *);
+    int (CDECL *fn_ldap_count_values_len)(struct bervalU **);
+    int (CDECL *fn_ldap_create_sort_control)(void *, LDAPSortKeyU **, int, LDAPControlU **);
+    int (CDECL *fn_ldap_create_vlv_control)(void *, LDAPVLVInfoU *, LDAPControlU **);
+    int (CDECL *fn_ldap_delete_ext)(void *, const char *, LDAPControlU **, LDAPControlU **, ULONG *);
+    int (CDECL *fn_ldap_delete_ext_s)(void *, const char *, LDAPControlU **, LDAPControlU **);
+    char * (CDECL *fn_ldap_dn2ufn)(const char *);
+    char ** (CDECL *fn_ldap_explode_dn)(const char *, int);
+    int (CDECL *fn_ldap_extended_operation)(void *, const char *, struct bervalU *, LDAPControlU **,
+                                            LDAPControlU **, ULONG *);
+    int (CDECL *fn_ldap_extended_operation_s)(void *, const char *, struct bervalU *, LDAPControlU **,
+                                              LDAPControlU **, char **, struct bervalU **);
+    char * (CDECL *fn_ldap_get_dn)(void *, void *);
+    int (CDECL *fn_ldap_get_option)(void *, int, void *);
+    struct bervalU ** (CDECL *fn_ldap_get_values_len)(void *, void *, const char *);
+    int (CDECL *fn_ldap_initialize)(void **, const char *);
+    char * (CDECL *fn_ldap_first_attribute)(void *, void *, void **);
+    void * (CDECL *fn_ldap_first_entry)(void *, void *);
+    void * (CDECL *fn_ldap_first_reference)(void *, void *);
+    void (CDECL *fn_ldap_memfree)(void *);
+    void (CDECL *fn_ldap_memvfree)(void **);
+    int (CDECL *fn_ldap_modify_ext)(void *, const char *, LDAPModU **, LDAPControlU **, LDAPControlU **, ULONG *);
+    int (CDECL *fn_ldap_modify_ext_s)(void *, const char *, LDAPModU **, LDAPControlU **, LDAPControlU **);
+    int (CDECL *fn_ldap_msgfree)(void *);
+    char * (CDECL *fn_ldap_next_attribute)(void *, void *, void *);
+    void * (CDECL *fn_ldap_next_entry)(void *, void *);
+    void * (CDECL *fn_ldap_next_reference)(void *, void *);
+    int (CDECL *fn_ldap_parse_extended_result)(void *, void *, char **, struct bervalU **, int);
+    int (CDECL *fn_ldap_parse_reference)(void *, void *, char ***, LDAPControlU ***, int);
+    int (CDECL *fn_ldap_parse_result)(void *, void *, int *, char **, char **, char ***, LDAPControlU ***, int);
+    int (CDECL *fn_ldap_parse_sortresponse_control)(void *, LDAPControlU *, int *, char **);
+    int (CDECL *fn_ldap_parse_vlvresponse_control)(void *, LDAPControlU *, int *, int *, struct bervalU **, int *);
+    int (CDECL *fn_ldap_rename)(void *, const char *, const char *, const char *, int, LDAPControlU **,
+                                LDAPControlU **, ULONG *);
+    int (CDECL *fn_ldap_rename_s)(void *, const char *, const char *, const char *, int, LDAPControlU **,
+                                  LDAPControlU **);
+    int (CDECL *fn_ldap_result)(void *, int, int, struct timevalU *, void **);
+    int (CDECL *fn_ldap_sasl_bind)(void *, const char *, const char *, struct bervalU *, LDAPControlU **,
+                                   LDAPControlU **, int *);
+    int (CDECL *fn_ldap_sasl_bind_s)(void *, const char *, const char *, struct bervalU *, LDAPControlU **,
+                                     LDAPControlU **, struct bervalU **);
+    int (CDECL *fn_ldap_sasl_interactive_bind_s)(void *, const char *, const char *, LDAPControlU **,
+                                                 LDAPControlU **, unsigned int, void *);
+    int (CDECL *fn_ldap_search_ext)(void *, const char *, int, const char *, char **, int, LDAPControlU **,
+                                    LDAPControlU **, struct timevalU *, int, ULONG *);
+    int (CDECL *fn_ldap_search_ext_s)(void *, const char *, int, const char *, char **, int, LDAPControlU **,
+                                      LDAPControlU **, struct timevalU *, int, void **);
+    int (CDECL *fn_ldap_set_option)(void *, int, const void *);
+    int (CDECL *fn_ldap_start_tls_s)(void *, LDAPControlU **, LDAPControlU **);
+    int (CDECL *fn_ldap_unbind_ext)(void *, LDAPControlU **, LDAPControlU **);
+    int (CDECL *fn_ldap_unbind_ext_s)(void *, LDAPControlU **, LDAPControlU **);
+    void (CDECL *fn_ldap_value_free_len)(struct bervalU **);
 };
 
 extern int CDECL sasl_interact_cb(void *, unsigned int, void *, void *) DECLSPEC_HIDDEN;
diff --git a/dlls/wldap32/misc.c b/dlls/wldap32/misc.c
index 330355e573c..dbda4609ff2 100644
--- a/dlls/wldap32/misc.c
+++ b/dlls/wldap32/misc.c
@@ -23,6 +23,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -42,12 +43,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL WLDAP32_ldap_abandon( WLDAP32_LDAP *ld, ULONG msgid )
+ULONG CDECL ldap_abandon( LDAP *ld, ULONG msgid )
 {
     TRACE( "(%p, 0x%08x)\n", ld, msgid );
 
     if (!ld) return ~0u;
-    return map_error( ldap_funcs->ldap_abandon_ext( ld->ld, msgid, NULL, NULL ) );
+    return map_error( ldap_funcs->fn_ldap_abandon_ext( CTX(ld), msgid, NULL, NULL ) );
 }
 
 /***********************************************************************
@@ -55,15 +56,15 @@ ULONG CDECL WLDAP32_ldap_abandon( WLDAP32_LDAP *ld, ULONG msgid )
  *
  * See ldap_check_filterW.
  */
-ULONG CDECL ldap_check_filterA( WLDAP32_LDAP *ld, char *filter )
+ULONG CDECL ldap_check_filterA( LDAP *ld, char *filter )
 {
     ULONG ret;
     WCHAR *filterW = NULL;
 
     TRACE( "(%p, %s)\n", ld, debugstr_a(filter) );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
-    if (filter && !(filterW = strAtoW( filter ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (!ld) return LDAP_PARAM_ERROR;
+    if (filter && !(filterW = strAtoW( filter ))) return LDAP_NO_MEMORY;
 
     ret = ldap_check_filterW( ld, filterW );
 
@@ -84,12 +85,12 @@ ULONG CDECL ldap_check_filterA( WLDAP32_LDAP *ld, char *filter )
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_check_filterW( WLDAP32_LDAP *ld, WCHAR *filter )
+ULONG CDECL ldap_check_filterW( LDAP *ld, WCHAR *filter )
 {
     TRACE( "(%p, %s)\n", ld, debugstr_w(filter) );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
-    return WLDAP32_LDAP_SUCCESS; /* FIXME: do some checks */
+    if (!ld) return LDAP_PARAM_ERROR;
+    return LDAP_SUCCESS; /* FIXME: do some checks */
 }
 
 /***********************************************************************
@@ -98,7 +99,7 @@ ULONG CDECL ldap_check_filterW( WLDAP32_LDAP *ld, WCHAR *filter )
 ULONG CDECL ldap_cleanup( HANDLE instance )
 {
     TRACE( "(%p)\n", instance );
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -114,7 +115,7 @@ ULONG CDECL ldap_cleanup( HANDLE instance )
  *  Success: Pointer to an LDAP context.
  *  Failure: NULL
  */
-WLDAP32_LDAP * CDECL ldap_conn_from_msg( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *res )
+LDAP * CDECL ldap_conn_from_msg( LDAP *ld, LDAPMessage *res )
 {
     TRACE( "(%p, %p)\n", ld, res );
 
@@ -135,12 +136,12 @@ WLDAP32_LDAP * CDECL ldap_conn_from_msg( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *
  *  Success: The number of entries.
  *  Failure: ~0u
  */
-ULONG CDECL WLDAP32_ldap_count_entries( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *res )
+ULONG CDECL ldap_count_entries( LDAP *ld, LDAPMessage *res )
 {
     TRACE( "(%p, %p)\n", ld, res );
 
     if (!ld) return ~0u;
-    return ldap_funcs->ldap_count_entries( ld->ld, res->Request );
+    return ldap_funcs->fn_ldap_count_entries( CTX(ld), MSG(res) );
 }
 
 /***********************************************************************
@@ -156,12 +157,12 @@ ULONG CDECL WLDAP32_ldap_count_entries( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *r
  *  Success: The number of references.
  *  Failure: ~0u
  */
-ULONG CDECL WLDAP32_ldap_count_references( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *res )
+ULONG CDECL ldap_count_references( LDAP *ld, LDAPMessage *res )
 {
     TRACE( "(%p, %p)\n", ld, res );
 
     if (!ld) return 0;
-    return ldap_funcs->ldap_count_references( ld->ld, res->Request );
+    return ldap_funcs->fn_ldap_count_references( CTX(ld), MSG(res) );
 }
 
 static ULONG get_escape_size( PCHAR src, ULONG srclen )
@@ -213,10 +214,10 @@ ULONG CDECL ldap_escape_filter_elementA( char *src, ULONG srclen, char *dst, ULO
     TRACE( "(%p, 0x%08x, %p, 0x%08x)\n", src, srclen, dst, dstlen );
 
     if (!dst) return len;
-    if (!src || dstlen < len) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!src || dstlen < len) return LDAP_PARAM_ERROR;
 
     escape_filter_element( src, srclen, dst );
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -243,7 +244,7 @@ ULONG CDECL ldap_escape_filter_elementW( char *src, ULONG srclen, WCHAR *dst, UL
     if (!dst) return len;
 
     /* no matter what you throw at it, this is what native returns */
-    return WLDAP32_LDAP_PARAM_ERROR;
+    return LDAP_PARAM_ERROR;
 }
 
 /***********************************************************************
@@ -251,7 +252,7 @@ ULONG CDECL ldap_escape_filter_elementW( char *src, ULONG srclen, WCHAR *dst, UL
  *
  * See ldap_first_attributeW.
  */
-char * CDECL ldap_first_attributeA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, WLDAP32_BerElement **ber )
+char * CDECL ldap_first_attributeA( LDAP *ld, LDAPMessage *entry, BerElement **ber )
 {
     char *ret = NULL;
     WCHAR *retW;
@@ -260,7 +261,7 @@ char * CDECL ldap_first_attributeA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry
 
     if (!ld || !entry) return NULL;
 
-    retW = ldap_first_attributeW( ld, entry->Request, ber );
+    retW = ldap_first_attributeW( ld, entry, ber );
     if (retW)
     {
         ret = strWtoA( retW );
@@ -287,10 +288,10 @@ char * CDECL ldap_first_attributeA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry
  * NOTES
  *  Use ldap_memfree to free the returned string.
  */
-WCHAR * CDECL ldap_first_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, WLDAP32_BerElement **ptr )
+WCHAR * CDECL ldap_first_attributeW( LDAP *ld, LDAPMessage *entry, BerElement **ptr )
 {
     WCHAR *ret = NULL;
-    WLDAP32_BerElement *ber;
+    BerElement *ber;
     char *retU;
     void *berU;
 
@@ -298,15 +299,15 @@ WCHAR * CDECL ldap_first_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entr
 
     if (!ld || !entry) return NULL;
 
-    retU = ldap_funcs->ldap_first_attribute( ld->ld, entry->Request, &berU );
+    retU = ldap_funcs->fn_ldap_first_attribute( CTX(ld), MSG(entry), &berU );
     if (retU && (ber = malloc( sizeof(*ber) )))
     {
-        ber->opaque = (char *)berU;
+        BER(ber) = (char *)berU;
         *ptr = ber;
         ret = strUtoW( retU );
     }
 
-    ldap_funcs->ldap_memfree( retU );
+    ldap_funcs->fn_ldap_memfree( retU );
     return ret;
 }
 
@@ -326,7 +327,7 @@ WCHAR * CDECL ldap_first_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entr
  * NOTES
  *  The returned entry will be freed when the message is freed.
  */
-WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_first_entry( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *res )
+LDAPMessage * CDECL ldap_first_entry( LDAP *ld, LDAPMessage *res )
 {
     void *msgU;
 
@@ -334,10 +335,10 @@ WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_first_entry( WLDAP32_LDAP *ld, WLDAP32_
 
     if (!ld || !res) return NULL;
 
-    msgU = ldap_funcs->ldap_first_entry( ld->ld, res->Request );
+    msgU = ldap_funcs->fn_ldap_first_entry( CTX(ld), MSG(res) );
     if (msgU)
     {
-        assert( msgU == res->Request );
+        assert( msgU == MSG(res) );
         return res;
     }
 
@@ -357,7 +358,7 @@ WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_first_entry( WLDAP32_LDAP *ld, WLDAP32_
  *  Success: The first reference.
  *  Failure: NULL
  */
-WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_first_reference( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *res )
+LDAPMessage * CDECL ldap_first_reference( LDAP *ld, LDAPMessage *res )
 {
     void *msgU;
 
@@ -365,10 +366,10 @@ WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_first_reference( WLDAP32_LDAP *ld, WLDA
 
     if (!ld) return NULL;
 
-    msgU = ldap_funcs->ldap_first_reference( ld->ld, res->Request );
+    msgU = ldap_funcs->fn_ldap_first_reference( CTX(ld), MSG(res) );
     if (msgU)
     {
-        assert( msgU == res->Request );
+        assert( msgU == MSG(res) );
         return res;
     }
 
@@ -408,15 +409,15 @@ void CDECL ldap_memfreeW( WCHAR *block )
  * PARAMS
  *  res [I] Message to be freed.
  */
-ULONG CDECL WLDAP32_ldap_msgfree( WLDAP32_LDAPMessage *res )
+ULONG CDECL ldap_msgfree( LDAPMessage *res )
 {
-    WLDAP32_LDAPMessage *entry, *list = res;
+    LDAPMessage *entry, *list = res;
 
     TRACE( "(%p)\n", res );
 
-    if (!res) return WLDAP32_LDAP_SUCCESS;
+    if (!res) return LDAP_SUCCESS;
 
-    ldap_funcs->ldap_msgfree( res->Request );
+    ldap_funcs->fn_ldap_msgfree( MSG(res) );
     while (list)
     {
         entry = list;
@@ -424,7 +425,7 @@ ULONG CDECL WLDAP32_ldap_msgfree( WLDAP32_LDAPMessage *res )
         free( entry );
     }
 
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -432,7 +433,7 @@ ULONG CDECL WLDAP32_ldap_msgfree( WLDAP32_LDAPMessage *res )
  *
  * See ldap_next_attributeW.
  */
-char * CDECL ldap_next_attributeA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, WLDAP32_BerElement *ptr )
+char * CDECL ldap_next_attributeA( LDAP *ld, LDAPMessage *entry, BerElement *ptr )
 {
     char *ret = NULL;
     WCHAR *retW;
@@ -441,7 +442,7 @@ char * CDECL ldap_next_attributeA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry,
 
     if (!ld || !entry || !ptr) return NULL;
 
-    retW = ldap_next_attributeW( ld, entry->Request, ptr );
+    retW = ldap_next_attributeW( ld, entry, ptr );
     if (retW)
     {
         ret = strWtoA( retW );
@@ -469,7 +470,7 @@ char * CDECL ldap_next_attributeA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry,
  *  Free the returned string after each iteration with ldap_memfree.
  *  When done iterating and when ptr != NULL, call ber_free( ptr, 0 ).
  */
-WCHAR * CDECL ldap_next_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, WLDAP32_BerElement *ptr )
+WCHAR * CDECL ldap_next_attributeW( LDAP *ld, LDAPMessage *entry, BerElement *ptr )
 {
     WCHAR *ret = NULL;
     char *retU;
@@ -478,11 +479,11 @@ WCHAR * CDECL ldap_next_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry
 
     if (!ld || !entry || !ptr) return NULL;
 
-    retU = ldap_funcs->ldap_next_attribute( ld->ld, entry->Request, ptr->opaque );
+    retU = ldap_funcs->fn_ldap_next_attribute( CTX(ld), MSG(entry), BER(ptr) );
     if (retU)
     {
         ret = strUtoW( retU );
-        ldap_funcs->ldap_memfree( retU );
+        ldap_funcs->fn_ldap_memfree( retU );
     }
 
     return ret;
@@ -504,9 +505,9 @@ WCHAR * CDECL ldap_next_attributeW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry
  * NOTES
  *  The returned entry will be freed when the message is freed.
  */
-WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_next_entry( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
+LDAPMessage * CDECL ldap_next_entry( LDAP *ld, LDAPMessage *entry )
 {
-    WLDAP32_LDAPMessage *msg = NULL;
+    LDAPMessage *msg = NULL;
     void *msgU;
 
     TRACE( "(%p, %p)\n", ld, entry );
@@ -515,10 +516,10 @@ WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_next_entry( WLDAP32_LDAP *ld, WLDAP32_L
 
     if (entry->lm_next) return entry->lm_next;
 
-    msgU = ldap_funcs->ldap_next_entry( ld->ld, entry->Request );
+    msgU = ldap_funcs->fn_ldap_next_entry( CTX(ld), MSG(entry) );
     if (msgU && (msg = calloc( 1, sizeof(*msg) )))
     {
-        msg->Request = msgU;
+        MSG(msg) = msgU;
         entry->lm_next = msg;
     }
 
@@ -541,9 +542,9 @@ WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_next_entry( WLDAP32_LDAP *ld, WLDAP32_L
  * NOTES
  *  The returned entry will be freed when the message is freed.
  */
-WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_next_reference( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
+LDAPMessage * CDECL ldap_next_reference( LDAP *ld, LDAPMessage *entry )
 {
-    WLDAP32_LDAPMessage *msg = NULL;
+    LDAPMessage *msg = NULL;
     void *msgU;
 
     TRACE( "(%p, %p)\n", ld, entry );
@@ -552,10 +553,10 @@ WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_next_reference( WLDAP32_LDAP *ld, WLDAP
 
     if (entry->lm_next) return entry->lm_next;
 
-    msgU = ldap_funcs->ldap_next_reference( ld->ld, entry->Request );
+    msgU = ldap_funcs->fn_ldap_next_reference( CTX(ld), MSG(entry) );
     if (msgU && (msg = calloc( 1, sizeof(*msg) )))
     {
-        msg->Request = msgU;
+        MSG(msg) = msgU;
         entry->lm_next = msg;
     }
 
@@ -598,10 +599,9 @@ WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_next_reference( WLDAP32_LDAP *ld, WLDAP
  *  to immediately return any available results. Free returned results
  *  with ldap_msgfree.
  */
-ULONG CDECL WLDAP32_ldap_result( WLDAP32_LDAP *ld, ULONG msgid, ULONG all, struct l_timeval *timeout,
-    WLDAP32_LDAPMessage **res )
+ULONG CDECL ldap_result( LDAP *ld, ULONG msgid, ULONG all, struct l_timeval *timeout, LDAPMessage **res )
 {
-    WLDAP32_LDAPMessage *msg;
+    LDAPMessage *msg;
     struct timevalU timeval;
     void *msgU = NULL;
     ULONG ret;
@@ -616,10 +616,10 @@ ULONG CDECL WLDAP32_ldap_result( WLDAP32_LDAP *ld, ULONG msgid, ULONG all, struc
         timeval.tv_usec = timeout->tv_usec;
     }
 
-    ret = ldap_funcs->ldap_result( ld->ld, msgid, all, timeout ? &timeval : NULL, &msgU );
+    ret = ldap_funcs->fn_ldap_result( CTX(ld), msgid, all, timeout ? &timeval : NULL, &msgU );
     if (msgU && (msg = calloc( 1, sizeof(*msg) )))
     {
-        msg->Request = msgU;
+        MSG(msg) = msgU;
         *res = msg;
     }
 
diff --git a/dlls/wldap32/modify.c b/dlls/wldap32/modify.c
index 280989f88b4..6f56f5a0e87 100644
--- a/dlls/wldap32/modify.c
+++ b/dlls/wldap32/modify.c
@@ -22,6 +22,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -33,9 +34,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *
  * See ldap_modifyW.
  */
-ULONG CDECL ldap_modifyA( WLDAP32_LDAP *ld, char *dn, LDAPModA **mods )
+ULONG CDECL ldap_modifyA( LDAP *ld, char *dn, LDAPModA **mods )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL;
     LDAPModW **modsW = NULL;
 
@@ -74,14 +75,14 @@ exit:
  *  the operation. Cancel the operation by calling ldap_abandon
  *  with the message ID.
  */
-ULONG CDECL ldap_modifyW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPModW **mods )
+ULONG CDECL ldap_modifyW( LDAP *ld, WCHAR *dn, LDAPModW **mods )
 {
     ULONG ret, msg;
 
     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), mods );
 
     ret = ldap_modify_extW( ld, dn, mods, NULL, NULL, &msg );
-    if (ret == WLDAP32_LDAP_SUCCESS) return msg;
+    if (ret == LDAP_SUCCESS) return msg;
     return ~0u;
 }
 
@@ -90,10 +91,10 @@ ULONG CDECL ldap_modifyW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPModW **mods )
  *
  * See ldap_modify_extW.
  */
-ULONG CDECL ldap_modify_extA( WLDAP32_LDAP *ld, char *dn, LDAPModA **mods,
-    LDAPControlA **serverctrls, LDAPControlA **clientctrls, ULONG *message )
+ULONG CDECL ldap_modify_extA( LDAP *ld, char *dn, LDAPModA **mods, LDAPControlA **serverctrls,
+    LDAPControlA **clientctrls, ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL;
     LDAPModW **modsW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
@@ -140,10 +141,10 @@ exit:
  *  the operation. The serverctrls and clientctrls parameters are
  *  optional and should be set to NULL if not used.
  */
-ULONG CDECL ldap_modify_extW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPModW **mods,
-    LDAPControlW **serverctrls, LDAPControlW **clientctrls, ULONG *message )
+ULONG CDECL ldap_modify_extW( LDAP *ld, WCHAR *dn, LDAPModW **mods, LDAPControlW **serverctrls,
+    LDAPControlW **clientctrls, ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL;
     LDAPModU **modsU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
@@ -157,7 +158,7 @@ ULONG CDECL ldap_modify_extW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPModW **mods,
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_modify_ext( ld->ld, dnU, modsU, serverctrlsU, clientctrlsU, message ) );
+    ret = map_error( ldap_funcs->fn_ldap_modify_ext( CTX(ld), dnU, modsU, serverctrlsU, clientctrlsU, message ) );
 
 exit:
     free( dnU );
@@ -172,17 +173,17 @@ exit:
  *
  * See ldap_modify_ext_sW.
  */
-ULONG CDECL ldap_modify_ext_sA( WLDAP32_LDAP *ld, char *dn, LDAPModA **mods,
-    LDAPControlA **serverctrls, LDAPControlA **clientctrls )
+ULONG CDECL ldap_modify_ext_sA( LDAP *ld, char *dn, LDAPModA **mods, LDAPControlA **serverctrls,
+    LDAPControlA **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL;
     LDAPModW **modsW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), mods, serverctrls, clientctrls );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (mods && !(modsW = modarrayAtoW( mods ))) goto exit;
@@ -220,24 +221,24 @@ exit:
  *  The serverctrls and clientctrls parameters are optional and
  *  should be set to NULL if not used.
  */
-ULONG CDECL ldap_modify_ext_sW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPModW **mods,
-    LDAPControlW **serverctrls, LDAPControlW **clientctrls )
+ULONG CDECL ldap_modify_ext_sW( LDAP *ld, WCHAR *dn, LDAPModW **mods, LDAPControlW **serverctrls,
+    LDAPControlW **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL;
     LDAPModU **modsU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
 
     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), mods, serverctrls, clientctrls );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (mods && !(modsU = modarrayWtoU( mods ))) goto exit;
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_modify_ext_s( ld->ld, dnU, modsU, serverctrlsU, clientctrlsU ) );
+    ret = map_error( ldap_funcs->fn_ldap_modify_ext_s( CTX(ld), dnU, modsU, serverctrlsU, clientctrlsU ) );
 
 exit:
     free( dnU );
@@ -252,15 +253,15 @@ exit:
  *
  * See ldap_modify_sW.
  */
-ULONG CDECL ldap_modify_sA( WLDAP32_LDAP *ld, char *dn, LDAPModA **mods )
+ULONG CDECL ldap_modify_sA( LDAP *ld, char *dn, LDAPModA **mods )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL;
     LDAPModW **modsW = NULL;
 
     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), mods );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (mods && !(modsW = modarrayAtoW( mods ))) goto exit;
@@ -288,7 +289,7 @@ exit:
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_modify_sW( WLDAP32_LDAP *ld, WCHAR *dn, LDAPModW **mods )
+ULONG CDECL ldap_modify_sW( LDAP *ld, WCHAR *dn, LDAPModW **mods )
 {
     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), mods );
     return ldap_modify_ext_sW( ld, dn, mods, NULL, NULL );
diff --git a/dlls/wldap32/modrdn.c b/dlls/wldap32/modrdn.c
index 937bd651f5e..3e1969163d7 100644
--- a/dlls/wldap32/modrdn.c
+++ b/dlls/wldap32/modrdn.c
@@ -22,6 +22,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -33,9 +34,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *
  * See ldap_modrdnW.
  */
-ULONG CDECL ldap_modrdnA( WLDAP32_LDAP *ld, char *dn, char *newdn )
+ULONG CDECL ldap_modrdnA( LDAP *ld, char *dn, char *newdn )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *newdnW = NULL;
 
     TRACE( "(%p, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(newdn) );
@@ -72,7 +73,7 @@ exit:
  *  the operation. Cancel the operation by calling ldap_abandon
  *  with the message ID.
  */
-ULONG CDECL ldap_modrdnW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *newdn )
+ULONG CDECL ldap_modrdnW( LDAP *ld, WCHAR *dn, WCHAR *newdn )
 {
     TRACE( "(%p, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(newdn) );
     return ldap_modrdn2W( ld, dn, newdn, 1 );
@@ -83,9 +84,9 @@ ULONG CDECL ldap_modrdnW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *newdn )
  *
  * See ldap_modrdn2W.
  */
-ULONG CDECL ldap_modrdn2A( WLDAP32_LDAP *ld, char *dn, char *newdn, int delete )
+ULONG CDECL ldap_modrdn2A( LDAP *ld, char *dn, char *newdn, int delete )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *newdnW = NULL;
 
     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
@@ -123,9 +124,9 @@ exit:
  *  the operation. Cancel the operation by calling ldap_abandon
  *  with the message ID.
  */
-ULONG CDECL ldap_modrdn2W( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *newdn, int delete )
+ULONG CDECL ldap_modrdn2W( LDAP *ld, WCHAR *dn, WCHAR *newdn, int delete )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL, *newdnU = NULL;
     ULONG msg;
 
@@ -136,8 +137,8 @@ ULONG CDECL ldap_modrdn2W( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *newdn, int delete
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (!(newdnU = strWtoU( newdn ))) goto exit;
 
-    ret = ldap_funcs->ldap_rename( ld->ld, dnU, newdnU, NULL, delete, NULL, NULL, &msg );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    ret = ldap_funcs->fn_ldap_rename( CTX(ld), dnU, newdnU, NULL, delete, NULL, NULL, &msg );
+    if (ret == LDAP_SUCCESS)
         ret = msg;
     else
         ret = ~0u;
@@ -153,14 +154,14 @@ exit:
  *
  * See ldap_modrdn2_sW.
  */
-ULONG CDECL ldap_modrdn2_sA( WLDAP32_LDAP *ld, char *dn, char *newdn, int delete )
+ULONG CDECL ldap_modrdn2_sA( LDAP *ld, char *dn, char *newdn, int delete )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *newdnW = NULL;
 
     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
 
-    if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !newdn) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (!(newdnW = strAtoW( newdn ))) goto exit;
@@ -188,19 +189,19 @@ exit:
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_modrdn2_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *newdn, int delete )
+ULONG CDECL ldap_modrdn2_sW( LDAP *ld, WCHAR *dn, WCHAR *newdn, int delete )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL, *newdnU = NULL;
 
     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
 
-    if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !newdn) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (!(newdnU = strWtoU( newdn ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_rename_s( ld->ld, dnU, newdnU, NULL, delete, NULL, NULL ));
+    ret = map_error( ldap_funcs->fn_ldap_rename_s( CTX(ld), dnU, newdnU, NULL, delete, NULL, NULL ));
 
 exit:
     free( dnU );
@@ -213,14 +214,14 @@ exit:
  *
  * See ldap_modrdn_sW.
  */
-ULONG CDECL ldap_modrdn_sA( WLDAP32_LDAP *ld, char *dn, char *newdn )
+ULONG CDECL ldap_modrdn_sA( LDAP *ld, char *dn, char *newdn )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *newdnW = NULL;
 
     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), newdn );
 
-    if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !newdn) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (!(newdnW = strAtoW( newdn ))) goto exit;
@@ -247,7 +248,7 @@ exit:
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_modrdn_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *newdn )
+ULONG CDECL ldap_modrdn_sW( LDAP *ld, WCHAR *dn, WCHAR *newdn )
 {
     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), newdn );
     return ldap_modrdn2_sW( ld, dn, newdn, 1 );
diff --git a/dlls/wldap32/option.c b/dlls/wldap32/option.c
index f307837d83a..1037b73174b 100644
--- a/dlls/wldap32/option.c
+++ b/dlls/wldap32/option.c
@@ -22,45 +22,50 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
 
+#ifndef LDAP_OPT_SERVER_CONTROLS
+#define LDAP_OPT_SERVER_CONTROLS 0x0012
+#endif
+
 /***********************************************************************
  *      ldap_get_optionA     (WLDAP32.@)
  *
  * See ldap_get_optionW.
  */
-ULONG CDECL ldap_get_optionA( WLDAP32_LDAP *ld, int option, void *value )
+ULONG CDECL ldap_get_optionA( LDAP *ld, int option, void *value )
 {
     ULONG ret;
 
     TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
 
-    if (!ld || !value) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !value) return LDAP_PARAM_ERROR;
 
     switch (option)
     {
-    case WLDAP32_LDAP_OPT_API_FEATURE_INFO:
+    case LDAP_OPT_API_FEATURE_INFO:
     {
         LDAPAPIFeatureInfoW featureW;
         LDAPAPIFeatureInfoA *featureA = value;
 
-        if (!featureA->ldapaif_name) return WLDAP32_LDAP_PARAM_ERROR;
+        if (!featureA->ldapaif_name) return LDAP_PARAM_ERROR;
 
         featureW.ldapaif_info_version = featureA->ldapaif_info_version;
-        if (!(featureW.ldapaif_name = strAtoW( featureA->ldapaif_name ))) return WLDAP32_LDAP_NO_MEMORY;
+        if (!(featureW.ldapaif_name = strAtoW( featureA->ldapaif_name ))) return LDAP_NO_MEMORY;
         featureW.ldapaif_version = 0;
 
         ret = ldap_get_optionW( ld, option, &featureW );
 
-        if (ret == WLDAP32_LDAP_SUCCESS) featureA->ldapaif_version = featureW.ldapaif_version;
+        if (ret == LDAP_SUCCESS) featureA->ldapaif_version = featureW.ldapaif_version;
         free( featureW.ldapaif_name );
         return ret;
     }
-    case WLDAP32_LDAP_OPT_API_INFO:
+    case LDAP_OPT_API_INFO:
     {
         LDAPAPIInfoW infoW;
         LDAPAPIInfoA *infoA = value;
@@ -69,17 +74,17 @@ ULONG CDECL ldap_get_optionA( WLDAP32_LDAP *ld, int option, void *value )
         infoW.ldapai_info_version = infoA->ldapai_info_version;
 
         ret = ldap_get_optionW( ld, option, &infoW );
-        if (ret == WLDAP32_LDAP_SUCCESS)
+        if (ret == LDAP_SUCCESS)
         {
             infoA->ldapai_api_version = infoW.ldapai_api_version;
             infoA->ldapai_protocol_version = infoW.ldapai_protocol_version;
 
             if (infoW.ldapai_extensions && !(infoA->ldapai_extensions = strarrayWtoA( infoW.ldapai_extensions )))
-                return WLDAP32_LDAP_NO_MEMORY;
+                return LDAP_NO_MEMORY;
             if (infoW.ldapai_vendor_name && !(infoA->ldapai_vendor_name = strWtoA( infoW.ldapai_vendor_name )))
             {
                 ldap_value_freeW( infoW.ldapai_extensions );
-                return WLDAP32_LDAP_NO_MEMORY;
+                return LDAP_NO_MEMORY;
             }
             infoA->ldapai_vendor_version = infoW.ldapai_vendor_version;
 
@@ -89,61 +94,61 @@ ULONG CDECL ldap_get_optionA( WLDAP32_LDAP *ld, int option, void *value )
         return ret;
     }
 
-    case WLDAP32_LDAP_OPT_DEREF:
-    case WLDAP32_LDAP_OPT_DESC:
-    case WLDAP32_LDAP_OPT_ERROR_NUMBER:
-    case WLDAP32_LDAP_OPT_PROTOCOL_VERSION:
-    case WLDAP32_LDAP_OPT_REFERRALS:
-    case WLDAP32_LDAP_OPT_SIZELIMIT:
-    case WLDAP32_LDAP_OPT_TIMELIMIT:
+    case LDAP_OPT_DEREF:
+    case LDAP_OPT_DESC:
+    case LDAP_OPT_ERROR_NUMBER:
+    case LDAP_OPT_PROTOCOL_VERSION:
+    case LDAP_OPT_REFERRALS:
+    case LDAP_OPT_SIZELIMIT:
+    case LDAP_OPT_TIMELIMIT:
         return ldap_get_optionW( ld, option, value );
 
-    case WLDAP32_LDAP_OPT_CACHE_ENABLE:
-    case WLDAP32_LDAP_OPT_CACHE_FN_PTRS:
-    case WLDAP32_LDAP_OPT_CACHE_STRATEGY:
-    case WLDAP32_LDAP_OPT_IO_FN_PTRS:
-    case WLDAP32_LDAP_OPT_REBIND_ARG:
-    case WLDAP32_LDAP_OPT_REBIND_FN:
-    case WLDAP32_LDAP_OPT_RESTART:
-    case WLDAP32_LDAP_OPT_THREAD_FN_PTRS:
-        return WLDAP32_LDAP_LOCAL_ERROR;
-
-    case WLDAP32_LDAP_OPT_AREC_EXCLUSIVE:
-    case WLDAP32_LDAP_OPT_AUTO_RECONNECT:
-    case WLDAP32_LDAP_OPT_CLIENT_CERTIFICATE:
-    case WLDAP32_LDAP_OPT_DNSDOMAIN_NAME:
-    case WLDAP32_LDAP_OPT_ENCRYPT:
-    case WLDAP32_LDAP_OPT_ERROR_STRING:
-    case WLDAP32_LDAP_OPT_FAST_CONCURRENT_BIND:
-    case WLDAP32_LDAP_OPT_GETDSNAME_FLAGS:
-    case WLDAP32_LDAP_OPT_HOST_NAME:
-    case WLDAP32_LDAP_OPT_HOST_REACHABLE:
-    case WLDAP32_LDAP_OPT_PING_KEEP_ALIVE:
-    case WLDAP32_LDAP_OPT_PING_LIMIT:
-    case WLDAP32_LDAP_OPT_PING_WAIT_TIME:
-    case WLDAP32_LDAP_OPT_PROMPT_CREDENTIALS:
-    case WLDAP32_LDAP_OPT_REF_DEREF_CONN_PER_MSG:
-    case WLDAP32_LDAP_OPT_REFERRAL_CALLBACK:
-    case WLDAP32_LDAP_OPT_REFERRAL_HOP_LIMIT:
-    case WLDAP32_LDAP_OPT_ROOTDSE_CACHE:
-    case WLDAP32_LDAP_OPT_SASL_METHOD:
-    case WLDAP32_LDAP_OPT_SECURITY_CONTEXT:
-    case WLDAP32_LDAP_OPT_SEND_TIMEOUT:
-    case WLDAP32_LDAP_OPT_SERVER_CERTIFICATE:
-    case WLDAP32_LDAP_OPT_SERVER_CONTROLS:
-    case WLDAP32_LDAP_OPT_SERVER_ERROR:
-    case WLDAP32_LDAP_OPT_SERVER_EXT_ERROR:
-    case WLDAP32_LDAP_OPT_SIGN:
-    case WLDAP32_LDAP_OPT_SSL:
-    case WLDAP32_LDAP_OPT_SSL_INFO:
-    case WLDAP32_LDAP_OPT_SSPI_FLAGS:
-    case WLDAP32_LDAP_OPT_TCP_KEEPALIVE:
+    case LDAP_OPT_CACHE_ENABLE:
+    case LDAP_OPT_CACHE_FN_PTRS:
+    case LDAP_OPT_CACHE_STRATEGY:
+    case LDAP_OPT_IO_FN_PTRS:
+    case LDAP_OPT_REBIND_ARG:
+    case LDAP_OPT_REBIND_FN:
+    case LDAP_OPT_RESTART:
+    case LDAP_OPT_THREAD_FN_PTRS:
+        return LDAP_LOCAL_ERROR;
+
+    case LDAP_OPT_AREC_EXCLUSIVE:
+    case LDAP_OPT_AUTO_RECONNECT:
+    case LDAP_OPT_CLIENT_CERTIFICATE:
+    case LDAP_OPT_DNSDOMAIN_NAME:
+    case LDAP_OPT_ENCRYPT:
+    case LDAP_OPT_ERROR_STRING:
+    case LDAP_OPT_FAST_CONCURRENT_BIND:
+    case LDAP_OPT_GETDSNAME_FLAGS:
+    case LDAP_OPT_HOST_NAME:
+    case LDAP_OPT_HOST_REACHABLE:
+    case LDAP_OPT_PING_KEEP_ALIVE:
+    case LDAP_OPT_PING_LIMIT:
+    case LDAP_OPT_PING_WAIT_TIME:
+    case LDAP_OPT_PROMPT_CREDENTIALS:
+    case LDAP_OPT_REF_DEREF_CONN_PER_MSG:
+    case LDAP_OPT_REFERRAL_CALLBACK:
+    case LDAP_OPT_REFERRAL_HOP_LIMIT:
+    case LDAP_OPT_ROOTDSE_CACHE:
+    case LDAP_OPT_SASL_METHOD:
+    case LDAP_OPT_SECURITY_CONTEXT:
+    case LDAP_OPT_SEND_TIMEOUT:
+    case LDAP_OPT_SERVER_CERTIFICATE:
+    case LDAP_OPT_SERVER_CONTROLS:
+    case LDAP_OPT_SERVER_ERROR:
+    case LDAP_OPT_SERVER_EXT_ERROR:
+    case LDAP_OPT_SIGN:
+    case LDAP_OPT_SSL:
+    case LDAP_OPT_SSL_INFO:
+    case LDAP_OPT_SSPI_FLAGS:
+    case LDAP_OPT_TCP_KEEPALIVE:
         FIXME( "Unsupported option: 0x%02x\n", option );
-        return WLDAP32_LDAP_NOT_SUPPORTED;
+        return LDAP_NOT_SUPPORTED;
 
     default:
         FIXME( "Unknown option: 0x%02x\n", option );
-        return WLDAP32_LDAP_LOCAL_ERROR;
+        return LDAP_LOCAL_ERROR;
     }
 }
 
@@ -161,34 +166,34 @@ ULONG CDECL ldap_get_optionA( WLDAP32_LDAP *ld, int option, void *value )
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_get_optionW( WLDAP32_LDAP *ld, int option, void *value )
+ULONG CDECL ldap_get_optionW( LDAP *ld, int option, void *value )
 {
     ULONG ret;
 
     TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
 
-    if (!ld || !value) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !value) return LDAP_PARAM_ERROR;
 
     switch (option)
     {
-    case WLDAP32_LDAP_OPT_API_FEATURE_INFO:
+    case LDAP_OPT_API_FEATURE_INFO:
     {
         LDAPAPIFeatureInfoU featureU;
         LDAPAPIFeatureInfoW *featureW = value;
 
-        if (!featureW->ldapaif_name) return WLDAP32_LDAP_PARAM_ERROR;
+        if (!featureW->ldapaif_name) return LDAP_PARAM_ERROR;
 
         featureU.ldapaif_info_version = featureW->ldapaif_info_version;
-        if (!(featureU.ldapaif_name = strWtoU( featureW->ldapaif_name ))) return WLDAP32_LDAP_NO_MEMORY;
+        if (!(featureU.ldapaif_name = strWtoU( featureW->ldapaif_name ))) return LDAP_NO_MEMORY;
         featureU.ldapaif_version = 0;
 
-        ret = map_error( ldap_funcs->ldap_get_option( ld->ld, option, &featureU ) );
+        ret = map_error( ldap_funcs->fn_ldap_get_option( CTX(ld), option, &featureU ) );
 
-        if (ret == WLDAP32_LDAP_SUCCESS) featureW->ldapaif_version = featureU.ldapaif_version;
+        if (ret == LDAP_SUCCESS) featureW->ldapaif_version = featureU.ldapaif_version;
         free( featureU.ldapaif_name );
         return ret;
     }
-    case WLDAP32_LDAP_OPT_API_INFO:
+    case LDAP_OPT_API_INFO:
     {
         LDAPAPIInfoU infoU;
         LDAPAPIInfoW *infoW = value;
@@ -196,82 +201,82 @@ ULONG CDECL ldap_get_optionW( WLDAP32_LDAP *ld, int option, void *value )
         memset( &infoU, 0, sizeof(infoU) );
         infoU.ldapai_info_version = infoW->ldapai_info_version;
 
-        ret = map_error( ldap_funcs->ldap_get_option( ld->ld, option, &infoU ) );
-        if (ret == WLDAP32_LDAP_SUCCESS)
+        ret = map_error( ldap_funcs->fn_ldap_get_option( CTX(ld), option, &infoU ) );
+        if (ret == LDAP_SUCCESS)
         {
             infoW->ldapai_api_version = infoU.ldapai_api_version;
             infoW->ldapai_protocol_version = infoU.ldapai_protocol_version;
 
             if (infoU.ldapai_extensions && !(infoW->ldapai_extensions = strarrayUtoW( infoU.ldapai_extensions )))
-                return WLDAP32_LDAP_NO_MEMORY;
+                return LDAP_NO_MEMORY;
             if (infoU.ldapai_vendor_name && !(infoW->ldapai_vendor_name = strUtoW( infoU.ldapai_vendor_name )))
             {
-                ldap_funcs->ldap_memvfree( (void **)infoU.ldapai_extensions );
-                return WLDAP32_LDAP_NO_MEMORY;
+                ldap_funcs->fn_ldap_memvfree( (void **)infoU.ldapai_extensions );
+                return LDAP_NO_MEMORY;
             }
             infoW->ldapai_vendor_version = infoU.ldapai_vendor_version;
 
-            ldap_funcs->ldap_memvfree( (void **)infoU.ldapai_extensions );
-            ldap_funcs->ldap_memfree( infoU.ldapai_vendor_name );
+            ldap_funcs->fn_ldap_memvfree( (void **)infoU.ldapai_extensions );
+            ldap_funcs->fn_ldap_memfree( infoU.ldapai_vendor_name );
         }
         return ret;
     }
 
-    case WLDAP32_LDAP_OPT_DEREF:
-    case WLDAP32_LDAP_OPT_DESC:
-    case WLDAP32_LDAP_OPT_ERROR_NUMBER:
-    case WLDAP32_LDAP_OPT_PROTOCOL_VERSION:
-    case WLDAP32_LDAP_OPT_REFERRALS:
-    case WLDAP32_LDAP_OPT_SIZELIMIT:
-    case WLDAP32_LDAP_OPT_TIMELIMIT:
-        return map_error( ldap_funcs->ldap_get_option( ld->ld, option, value ));
-
-    case WLDAP32_LDAP_OPT_CACHE_ENABLE:
-    case WLDAP32_LDAP_OPT_CACHE_FN_PTRS:
-    case WLDAP32_LDAP_OPT_CACHE_STRATEGY:
-    case WLDAP32_LDAP_OPT_IO_FN_PTRS:
-    case WLDAP32_LDAP_OPT_REBIND_ARG:
-    case WLDAP32_LDAP_OPT_REBIND_FN:
-    case WLDAP32_LDAP_OPT_RESTART:
-    case WLDAP32_LDAP_OPT_THREAD_FN_PTRS:
-        return WLDAP32_LDAP_LOCAL_ERROR;
-
-    case WLDAP32_LDAP_OPT_AREC_EXCLUSIVE:
-    case WLDAP32_LDAP_OPT_AUTO_RECONNECT:
-    case WLDAP32_LDAP_OPT_CLIENT_CERTIFICATE:
-    case WLDAP32_LDAP_OPT_DNSDOMAIN_NAME:
-    case WLDAP32_LDAP_OPT_ENCRYPT:
-    case WLDAP32_LDAP_OPT_ERROR_STRING:
-    case WLDAP32_LDAP_OPT_FAST_CONCURRENT_BIND:
-    case WLDAP32_LDAP_OPT_GETDSNAME_FLAGS:
-    case WLDAP32_LDAP_OPT_HOST_NAME:
-    case WLDAP32_LDAP_OPT_HOST_REACHABLE:
-    case WLDAP32_LDAP_OPT_PING_KEEP_ALIVE:
-    case WLDAP32_LDAP_OPT_PING_LIMIT:
-    case WLDAP32_LDAP_OPT_PING_WAIT_TIME:
-    case WLDAP32_LDAP_OPT_PROMPT_CREDENTIALS:
-    case WLDAP32_LDAP_OPT_REF_DEREF_CONN_PER_MSG:
-    case WLDAP32_LDAP_OPT_REFERRAL_CALLBACK:
-    case WLDAP32_LDAP_OPT_REFERRAL_HOP_LIMIT:
-    case WLDAP32_LDAP_OPT_ROOTDSE_CACHE:
-    case WLDAP32_LDAP_OPT_SASL_METHOD:
-    case WLDAP32_LDAP_OPT_SECURITY_CONTEXT:
-    case WLDAP32_LDAP_OPT_SEND_TIMEOUT:
-    case WLDAP32_LDAP_OPT_SERVER_CERTIFICATE:
-    case WLDAP32_LDAP_OPT_SERVER_CONTROLS:
-    case WLDAP32_LDAP_OPT_SERVER_ERROR:
-    case WLDAP32_LDAP_OPT_SERVER_EXT_ERROR:
-    case WLDAP32_LDAP_OPT_SIGN:
-    case WLDAP32_LDAP_OPT_SSL:
-    case WLDAP32_LDAP_OPT_SSL_INFO:
-    case WLDAP32_LDAP_OPT_SSPI_FLAGS:
-    case WLDAP32_LDAP_OPT_TCP_KEEPALIVE:
+    case LDAP_OPT_DEREF:
+    case LDAP_OPT_DESC:
+    case LDAP_OPT_ERROR_NUMBER:
+    case LDAP_OPT_PROTOCOL_VERSION:
+    case LDAP_OPT_REFERRALS:
+    case LDAP_OPT_SIZELIMIT:
+    case LDAP_OPT_TIMELIMIT:
+        return map_error( ldap_funcs->fn_ldap_get_option( CTX(ld), option, value ));
+
+    case LDAP_OPT_CACHE_ENABLE:
+    case LDAP_OPT_CACHE_FN_PTRS:
+    case LDAP_OPT_CACHE_STRATEGY:
+    case LDAP_OPT_IO_FN_PTRS:
+    case LDAP_OPT_REBIND_ARG:
+    case LDAP_OPT_REBIND_FN:
+    case LDAP_OPT_RESTART:
+    case LDAP_OPT_THREAD_FN_PTRS:
+        return LDAP_LOCAL_ERROR;
+
+    case LDAP_OPT_AREC_EXCLUSIVE:
+    case LDAP_OPT_AUTO_RECONNECT:
+    case LDAP_OPT_CLIENT_CERTIFICATE:
+    case LDAP_OPT_DNSDOMAIN_NAME:
+    case LDAP_OPT_ENCRYPT:
+    case LDAP_OPT_ERROR_STRING:
+    case LDAP_OPT_FAST_CONCURRENT_BIND:
+    case LDAP_OPT_GETDSNAME_FLAGS:
+    case LDAP_OPT_HOST_NAME:
+    case LDAP_OPT_HOST_REACHABLE:
+    case LDAP_OPT_PING_KEEP_ALIVE:
+    case LDAP_OPT_PING_LIMIT:
+    case LDAP_OPT_PING_WAIT_TIME:
+    case LDAP_OPT_PROMPT_CREDENTIALS:
+    case LDAP_OPT_REF_DEREF_CONN_PER_MSG:
+    case LDAP_OPT_REFERRAL_CALLBACK:
+    case LDAP_OPT_REFERRAL_HOP_LIMIT:
+    case LDAP_OPT_ROOTDSE_CACHE:
+    case LDAP_OPT_SASL_METHOD:
+    case LDAP_OPT_SECURITY_CONTEXT:
+    case LDAP_OPT_SEND_TIMEOUT:
+    case LDAP_OPT_SERVER_CERTIFICATE:
+    case LDAP_OPT_SERVER_CONTROLS:
+    case LDAP_OPT_SERVER_ERROR:
+    case LDAP_OPT_SERVER_EXT_ERROR:
+    case LDAP_OPT_SIGN:
+    case LDAP_OPT_SSL:
+    case LDAP_OPT_SSL_INFO:
+    case LDAP_OPT_SSPI_FLAGS:
+    case LDAP_OPT_TCP_KEEPALIVE:
         FIXME( "Unsupported option: 0x%02x\n", option );
-        return WLDAP32_LDAP_NOT_SUPPORTED;
+        return LDAP_NOT_SUPPORTED;
 
     default:
         FIXME( "Unknown option: 0x%02x\n", option );
-        return WLDAP32_LDAP_LOCAL_ERROR;
+        return LDAP_LOCAL_ERROR;
     }
 }
 
@@ -280,114 +285,115 @@ ULONG CDECL ldap_get_optionW( WLDAP32_LDAP *ld, int option, void *value )
  *
  * See ldap_set_optionW.
  */
-ULONG CDECL ldap_set_optionA( WLDAP32_LDAP *ld, int option, void *value )
+ULONG CDECL ldap_set_optionA( LDAP *ld, int option, void *value )
 {
     ULONG ret;
 
     TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     switch (option)
     {
-    case WLDAP32_LDAP_OPT_SERVER_CONTROLS:
+    case LDAP_OPT_SERVER_CONTROLS:
     {
         LDAPControlW **ctrlsW;
-        if (!(ctrlsW = controlarrayAtoW( value ))) return WLDAP32_LDAP_NO_MEMORY;
+        if (!(ctrlsW = controlarrayAtoW( value ))) return LDAP_NO_MEMORY;
         ret = ldap_set_optionW( ld, option, ctrlsW );
         controlarrayfreeW( ctrlsW );
         return ret;
     }
-    case WLDAP32_LDAP_OPT_DEREF:
-    case WLDAP32_LDAP_OPT_DESC:
-    case WLDAP32_LDAP_OPT_ERROR_NUMBER:
-    case WLDAP32_LDAP_OPT_PROTOCOL_VERSION:
-    case WLDAP32_LDAP_OPT_REFERRALS:
-    case WLDAP32_LDAP_OPT_SIZELIMIT:
-    case WLDAP32_LDAP_OPT_TIMELIMIT:
+    case LDAP_OPT_DEREF:
+    case LDAP_OPT_DESC:
+    case LDAP_OPT_ERROR_NUMBER:
+    case LDAP_OPT_PROTOCOL_VERSION:
+    case LDAP_OPT_REFERRALS:
+    case LDAP_OPT_SIZELIMIT:
+    case LDAP_OPT_TIMELIMIT:
         return ldap_set_optionW( ld, option, value );
 
-    case WLDAP32_LDAP_OPT_CACHE_ENABLE:
-    case WLDAP32_LDAP_OPT_CACHE_FN_PTRS:
-    case WLDAP32_LDAP_OPT_CACHE_STRATEGY:
-    case WLDAP32_LDAP_OPT_IO_FN_PTRS:
-    case WLDAP32_LDAP_OPT_REBIND_ARG:
-    case WLDAP32_LDAP_OPT_REBIND_FN:
-    case WLDAP32_LDAP_OPT_RESTART:
-    case WLDAP32_LDAP_OPT_THREAD_FN_PTRS:
-        return WLDAP32_LDAP_LOCAL_ERROR;
-
-    case WLDAP32_LDAP_OPT_API_FEATURE_INFO:
-    case WLDAP32_LDAP_OPT_API_INFO:
-        return WLDAP32_LDAP_UNWILLING_TO_PERFORM;
-
-    case WLDAP32_LDAP_OPT_AREC_EXCLUSIVE:
-    case WLDAP32_LDAP_OPT_AUTO_RECONNECT:
-    case WLDAP32_LDAP_OPT_CLIENT_CERTIFICATE:
-    case WLDAP32_LDAP_OPT_DNSDOMAIN_NAME:
-    case WLDAP32_LDAP_OPT_ENCRYPT:
-    case WLDAP32_LDAP_OPT_ERROR_STRING:
-    case WLDAP32_LDAP_OPT_FAST_CONCURRENT_BIND:
-    case WLDAP32_LDAP_OPT_GETDSNAME_FLAGS:
-    case WLDAP32_LDAP_OPT_HOST_NAME:
-    case WLDAP32_LDAP_OPT_HOST_REACHABLE:
-    case WLDAP32_LDAP_OPT_PING_KEEP_ALIVE:
-    case WLDAP32_LDAP_OPT_PING_LIMIT:
-    case WLDAP32_LDAP_OPT_PING_WAIT_TIME:
-    case WLDAP32_LDAP_OPT_PROMPT_CREDENTIALS:
-    case WLDAP32_LDAP_OPT_REF_DEREF_CONN_PER_MSG:
-    case WLDAP32_LDAP_OPT_REFERRAL_CALLBACK:
-    case WLDAP32_LDAP_OPT_REFERRAL_HOP_LIMIT:
-    case WLDAP32_LDAP_OPT_ROOTDSE_CACHE:
-    case WLDAP32_LDAP_OPT_SASL_METHOD:
-    case WLDAP32_LDAP_OPT_SECURITY_CONTEXT:
-    case WLDAP32_LDAP_OPT_SEND_TIMEOUT:
-    case WLDAP32_LDAP_OPT_SERVER_CERTIFICATE:
-    case WLDAP32_LDAP_OPT_SERVER_ERROR:
-    case WLDAP32_LDAP_OPT_SERVER_EXT_ERROR:
-    case WLDAP32_LDAP_OPT_SIGN:
-    case WLDAP32_LDAP_OPT_SSL:
-    case WLDAP32_LDAP_OPT_SSL_INFO:
-    case WLDAP32_LDAP_OPT_SSPI_FLAGS:
-    case WLDAP32_LDAP_OPT_TCP_KEEPALIVE:
+    case LDAP_OPT_CACHE_ENABLE:
+    case LDAP_OPT_CACHE_FN_PTRS:
+    case LDAP_OPT_CACHE_STRATEGY:
+    case LDAP_OPT_IO_FN_PTRS:
+    case LDAP_OPT_REBIND_ARG:
+    case LDAP_OPT_REBIND_FN:
+    case LDAP_OPT_RESTART:
+    case LDAP_OPT_THREAD_FN_PTRS:
+        return LDAP_LOCAL_ERROR;
+
+    case LDAP_OPT_API_FEATURE_INFO:
+    case LDAP_OPT_API_INFO:
+        return LDAP_UNWILLING_TO_PERFORM;
+
+    case LDAP_OPT_AREC_EXCLUSIVE:
+    case LDAP_OPT_AUTO_RECONNECT:
+    case LDAP_OPT_CLIENT_CERTIFICATE:
+    case LDAP_OPT_DNSDOMAIN_NAME:
+    case LDAP_OPT_ENCRYPT:
+    case LDAP_OPT_ERROR_STRING:
+    case LDAP_OPT_FAST_CONCURRENT_BIND:
+    case LDAP_OPT_GETDSNAME_FLAGS:
+    case LDAP_OPT_HOST_NAME:
+    case LDAP_OPT_HOST_REACHABLE:
+    case LDAP_OPT_PING_KEEP_ALIVE:
+    case LDAP_OPT_PING_LIMIT:
+    case LDAP_OPT_PING_WAIT_TIME:
+    case LDAP_OPT_PROMPT_CREDENTIALS:
+    case LDAP_OPT_REF_DEREF_CONN_PER_MSG:
+    case LDAP_OPT_REFERRAL_CALLBACK:
+    case LDAP_OPT_REFERRAL_HOP_LIMIT:
+    case LDAP_OPT_ROOTDSE_CACHE:
+    case LDAP_OPT_SASL_METHOD:
+    case LDAP_OPT_SECURITY_CONTEXT:
+    case LDAP_OPT_SEND_TIMEOUT:
+    case LDAP_OPT_SERVER_CERTIFICATE:
+    case LDAP_OPT_SERVER_ERROR:
+    case LDAP_OPT_SERVER_EXT_ERROR:
+    case LDAP_OPT_SIGN:
+    case LDAP_OPT_SSL:
+    case LDAP_OPT_SSL_INFO:
+    case LDAP_OPT_SSPI_FLAGS:
+    case LDAP_OPT_TCP_KEEPALIVE:
         FIXME( "Unsupported option: 0x%02x\n", option );
-        return WLDAP32_LDAP_NOT_SUPPORTED;
+        return LDAP_NOT_SUPPORTED;
 
     default:
         FIXME( "Unknown option: 0x%02x\n", option );
-        return WLDAP32_LDAP_LOCAL_ERROR;
+        return LDAP_LOCAL_ERROR;
     }
 }
 
-static BOOL query_supported_server_ctrls( WLDAP32_LDAP *ld )
+static BOOL query_supported_server_ctrls( LDAP *ld )
 {
     char *attrs[] = { (char *)"supportedControl", NULL };
     void *res, *entry;
     ULONG ret;
 
-    if (ld->ld_server_ctrls) return TRUE;
+    if (SERVER_CTRLS(ld)) return TRUE;
 
-    ret = map_error( ldap_funcs->ldap_search_ext_s( ld->ld, (char *)"", WLDAP32_LDAP_SCOPE_BASE,
-                                                    (char *)"(objectClass=*)", attrs, FALSE, NULL, NULL, NULL, 0, &res ) );
-    if (ret != WLDAP32_LDAP_SUCCESS) return FALSE;
+    ret = map_error( ldap_funcs->fn_ldap_search_ext_s( CTX(ld), (char *)"", LDAP_SCOPE_BASE, (char *)"(objectClass=*)",
+                                                       attrs, FALSE, NULL, NULL, NULL, 0, &res ) );
+    if (ret != LDAP_SUCCESS) return FALSE;
 
-    entry = ldap_funcs->ldap_first_entry( ld->ld, res );
+    entry = ldap_funcs->fn_ldap_first_entry( CTX(ld), res );
     if (entry)
     {
         ULONG count, i;
+        struct bervalU **ctrls = SERVER_CTRLS(ld);
 
-        ld->ld_server_ctrls = ldap_funcs->ldap_get_values_len( ld->ld, entry, attrs[0] );
-        count = ldap_funcs->ldap_count_values_len( ld->ld_server_ctrls );
+        *(struct bervalU ***)&SERVER_CTRLS(ld) = ldap_funcs->fn_ldap_get_values_len( CTX(ld), entry, attrs[0] );
+        count = ldap_funcs->fn_ldap_count_values_len( SERVER_CTRLS(ld) );
         for (i = 0; i < count; i++)
-            TRACE("%u: %s\n", i, debugstr_an( ld->ld_server_ctrls[i]->bv_val, ld->ld_server_ctrls[i]->bv_len ));
+            TRACE("%u: %s\n", i, debugstr_an( ctrls[i]->bv_val, ctrls[i]->bv_len ));
     }
 
-    ldap_funcs->ldap_msgfree( res );
+    ldap_funcs->fn_ldap_msgfree( res );
 
-    return ld->ld_server_ctrls != NULL;
+    return SERVER_CTRLS(ld) != NULL;
 }
 
-static BOOL is_supported_server_ctrls( WLDAP32_LDAP *ld, LDAPControlU **ctrls )
+static BOOL is_supported_server_ctrls( LDAP *ld, LDAPControlU **ctrls )
 {
     ULONG user_count, server_count, i, n, supported = 0;
 
@@ -395,7 +401,7 @@ static BOOL is_supported_server_ctrls( WLDAP32_LDAP *ld, LDAPControlU **ctrls )
         return TRUE; /* can't verify, let the server handle it on next query */
 
     user_count = controlarraylenU( ctrls );
-    server_count = ldap_funcs->ldap_count_values_len( ld->ld_server_ctrls );
+    server_count = ldap_funcs->fn_ldap_count_values_len( SERVER_CTRLS(ld) );
 
     for (n = 0; n < user_count; n++)
     {
@@ -403,7 +409,8 @@ static BOOL is_supported_server_ctrls( WLDAP32_LDAP *ld, LDAPControlU **ctrls )
 
         for (i = 0; i < server_count; i++)
         {
-            if (!strncmp( ctrls[n]->ldctl_oid, ld->ld_server_ctrls[i]->bv_val, ld->ld_server_ctrls[i]->bv_len))
+            struct bervalU **server_ctrls = SERVER_CTRLS(ld);
+            if (!strncmp( ctrls[n]->ldctl_oid, server_ctrls[i]->bv_val, server_ctrls[i]->bv_len))
             {
                 supported++;
                 break;
@@ -431,95 +438,95 @@ static BOOL is_supported_server_ctrls( WLDAP32_LDAP *ld, LDAPControlU **ctrls )
  * NOTES
  *  Set value to LDAP_OPT_ON or LDAP_OPT_OFF for on/off options.
  */
-ULONG CDECL ldap_set_optionW( WLDAP32_LDAP *ld, int option, void *value )
+ULONG CDECL ldap_set_optionW( LDAP *ld, int option, void *value )
 {
     ULONG ret;
 
     TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     switch (option)
     {
-    case WLDAP32_LDAP_OPT_SERVER_CONTROLS:
+    case LDAP_OPT_SERVER_CONTROLS:
     {
         LDAPControlU **ctrlsU;
 
-        if (!(ctrlsU = controlarrayWtoU( value ))) return WLDAP32_LDAP_NO_MEMORY;
+        if (!(ctrlsU = controlarrayWtoU( value ))) return LDAP_NO_MEMORY;
 
         if (!is_supported_server_ctrls( ld, ctrlsU ))
-            ret = WLDAP32_LDAP_PARAM_ERROR;
+            ret = LDAP_PARAM_ERROR;
         else
-            ret = map_error( ldap_funcs->ldap_set_option( ld->ld, option, ctrlsU ) );
+            ret = map_error( ldap_funcs->fn_ldap_set_option( CTX(ld), option, ctrlsU ) );
         controlarrayfreeU( ctrlsU );
         return ret;
     }
-    case WLDAP32_LDAP_OPT_REFERRALS:
+    case LDAP_OPT_REFERRALS:
     {
-        void *openldap_referral = WLDAP32_LDAP_OPT_ON;
-        if (value == WLDAP32_LDAP_OPT_OFF)
-            openldap_referral = WLDAP32_LDAP_OPT_OFF;
+        void *openldap_referral = LDAP_OPT_ON;
+        if (value == LDAP_OPT_OFF)
+            openldap_referral = LDAP_OPT_OFF;
         else
             FIXME("upgrading referral value %p to LDAP_OPT_ON (OpenLDAP lacks sufficient granularity)\n", value);
-        return map_error( ldap_funcs->ldap_set_option( ld->ld, option, openldap_referral ) );
+        return map_error( ldap_funcs->fn_ldap_set_option( CTX(ld), option, openldap_referral ) );
         break;
     }
-    case WLDAP32_LDAP_OPT_DEREF:
-    case WLDAP32_LDAP_OPT_DESC:
-    case WLDAP32_LDAP_OPT_ERROR_NUMBER:
-    case WLDAP32_LDAP_OPT_PROTOCOL_VERSION:
-    case WLDAP32_LDAP_OPT_SIZELIMIT:
-    case WLDAP32_LDAP_OPT_TIMELIMIT:
-        return map_error( ldap_funcs->ldap_set_option( ld->ld, option, value ));
-
-    case WLDAP32_LDAP_OPT_CACHE_ENABLE:
-    case WLDAP32_LDAP_OPT_CACHE_FN_PTRS:
-    case WLDAP32_LDAP_OPT_CACHE_STRATEGY:
-    case WLDAP32_LDAP_OPT_IO_FN_PTRS:
-    case WLDAP32_LDAP_OPT_REBIND_ARG:
-    case WLDAP32_LDAP_OPT_REBIND_FN:
-    case WLDAP32_LDAP_OPT_RESTART:
-    case WLDAP32_LDAP_OPT_THREAD_FN_PTRS:
-        return WLDAP32_LDAP_LOCAL_ERROR;
-
-    case WLDAP32_LDAP_OPT_API_FEATURE_INFO:
-    case WLDAP32_LDAP_OPT_API_INFO:
-        return WLDAP32_LDAP_UNWILLING_TO_PERFORM;
-
-    case WLDAP32_LDAP_OPT_AREC_EXCLUSIVE:
-    case WLDAP32_LDAP_OPT_AUTO_RECONNECT:
-    case WLDAP32_LDAP_OPT_CLIENT_CERTIFICATE:
-    case WLDAP32_LDAP_OPT_DNSDOMAIN_NAME:
-    case WLDAP32_LDAP_OPT_ENCRYPT:
-    case WLDAP32_LDAP_OPT_ERROR_STRING:
-    case WLDAP32_LDAP_OPT_FAST_CONCURRENT_BIND:
-    case WLDAP32_LDAP_OPT_GETDSNAME_FLAGS:
-    case WLDAP32_LDAP_OPT_HOST_NAME:
-    case WLDAP32_LDAP_OPT_HOST_REACHABLE:
-    case WLDAP32_LDAP_OPT_PING_KEEP_ALIVE:
-    case WLDAP32_LDAP_OPT_PING_LIMIT:
-    case WLDAP32_LDAP_OPT_PING_WAIT_TIME:
-    case WLDAP32_LDAP_OPT_PROMPT_CREDENTIALS:
-    case WLDAP32_LDAP_OPT_REF_DEREF_CONN_PER_MSG:
-    case WLDAP32_LDAP_OPT_REFERRAL_CALLBACK:
-    case WLDAP32_LDAP_OPT_REFERRAL_HOP_LIMIT:
-    case WLDAP32_LDAP_OPT_ROOTDSE_CACHE:
-    case WLDAP32_LDAP_OPT_SASL_METHOD:
-    case WLDAP32_LDAP_OPT_SECURITY_CONTEXT:
-    case WLDAP32_LDAP_OPT_SEND_TIMEOUT:
-    case WLDAP32_LDAP_OPT_SERVER_CERTIFICATE:
-    case WLDAP32_LDAP_OPT_SERVER_ERROR:
-    case WLDAP32_LDAP_OPT_SERVER_EXT_ERROR:
-    case WLDAP32_LDAP_OPT_SIGN:
-    case WLDAP32_LDAP_OPT_SSL:
-    case WLDAP32_LDAP_OPT_SSL_INFO:
-    case WLDAP32_LDAP_OPT_SSPI_FLAGS:
-    case WLDAP32_LDAP_OPT_TCP_KEEPALIVE:
+    case LDAP_OPT_DEREF:
+    case LDAP_OPT_DESC:
+    case LDAP_OPT_ERROR_NUMBER:
+    case LDAP_OPT_PROTOCOL_VERSION:
+    case LDAP_OPT_SIZELIMIT:
+    case LDAP_OPT_TIMELIMIT:
+        return map_error( ldap_funcs->fn_ldap_set_option( CTX(ld), option, value ));
+
+    case LDAP_OPT_CACHE_ENABLE:
+    case LDAP_OPT_CACHE_FN_PTRS:
+    case LDAP_OPT_CACHE_STRATEGY:
+    case LDAP_OPT_IO_FN_PTRS:
+    case LDAP_OPT_REBIND_ARG:
+    case LDAP_OPT_REBIND_FN:
+    case LDAP_OPT_RESTART:
+    case LDAP_OPT_THREAD_FN_PTRS:
+        return LDAP_LOCAL_ERROR;
+
+    case LDAP_OPT_API_FEATURE_INFO:
+    case LDAP_OPT_API_INFO:
+        return LDAP_UNWILLING_TO_PERFORM;
+
+    case LDAP_OPT_AREC_EXCLUSIVE:
+    case LDAP_OPT_AUTO_RECONNECT:
+    case LDAP_OPT_CLIENT_CERTIFICATE:
+    case LDAP_OPT_DNSDOMAIN_NAME:
+    case LDAP_OPT_ENCRYPT:
+    case LDAP_OPT_ERROR_STRING:
+    case LDAP_OPT_FAST_CONCURRENT_BIND:
+    case LDAP_OPT_GETDSNAME_FLAGS:
+    case LDAP_OPT_HOST_NAME:
+    case LDAP_OPT_HOST_REACHABLE:
+    case LDAP_OPT_PING_KEEP_ALIVE:
+    case LDAP_OPT_PING_LIMIT:
+    case LDAP_OPT_PING_WAIT_TIME:
+    case LDAP_OPT_PROMPT_CREDENTIALS:
+    case LDAP_OPT_REF_DEREF_CONN_PER_MSG:
+    case LDAP_OPT_REFERRAL_CALLBACK:
+    case LDAP_OPT_REFERRAL_HOP_LIMIT:
+    case LDAP_OPT_ROOTDSE_CACHE:
+    case LDAP_OPT_SASL_METHOD:
+    case LDAP_OPT_SECURITY_CONTEXT:
+    case LDAP_OPT_SEND_TIMEOUT:
+    case LDAP_OPT_SERVER_CERTIFICATE:
+    case LDAP_OPT_SERVER_ERROR:
+    case LDAP_OPT_SERVER_EXT_ERROR:
+    case LDAP_OPT_SIGN:
+    case LDAP_OPT_SSL:
+    case LDAP_OPT_SSL_INFO:
+    case LDAP_OPT_SSPI_FLAGS:
+    case LDAP_OPT_TCP_KEEPALIVE:
         FIXME( "Unsupported option: 0x%02x\n", option );
-        return WLDAP32_LDAP_NOT_SUPPORTED;
+        return LDAP_NOT_SUPPORTED;
 
     default:
         FIXME( "Unknown option: 0x%02x\n", option );
-        return WLDAP32_LDAP_LOCAL_ERROR;
+        return LDAP_LOCAL_ERROR;
     }
 }
diff --git a/dlls/wldap32/page.c b/dlls/wldap32/page.c
index f7d1c4dab94..9ba41160b4c 100644
--- a/dlls/wldap32/page.c
+++ b/dlls/wldap32/page.c
@@ -23,6 +23,8 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
+#include "winber.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -31,25 +33,25 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
 
 #define LDAP_MAXINT (2^31)
 
-static struct WLDAP32_berval null_cookieW = { 0, NULL };
+static struct berval null_cookieW = { 0, NULL };
 
 /***********************************************************************
  *      ldap_create_page_controlA     (WLDAP32.@)
  *
  * See ldap_create_page_controlW.
  */
-ULONG CDECL ldap_create_page_controlA( WLDAP32_LDAP *ld, ULONG pagesize,
-    struct WLDAP32_berval *cookie, UCHAR critical, LDAPControlA **control )
+ULONG CDECL ldap_create_page_controlA( LDAP *ld, ULONG pagesize, struct berval *cookie, UCHAR critical,
+    LDAPControlA **control )
 {
     ULONG ret;
     LDAPControlW *controlW = NULL;
 
     TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld, pagesize, cookie, critical, control );
 
-    if (!ld || !control || pagesize > LDAP_MAXINT) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !control || pagesize > LDAP_MAXINT) return LDAP_PARAM_ERROR;
 
     ret = ldap_create_page_controlW( ld, pagesize, cookie, critical, &controlW );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    if (ret == LDAP_SUCCESS)
     {
         *control = controlWtoA( controlW );
         ldap_control_freeW( controlW );
@@ -58,52 +60,52 @@ ULONG CDECL ldap_create_page_controlA( WLDAP32_LDAP *ld, ULONG pagesize,
 }
 
 /* create a page control by hand */
-static ULONG create_page_control( ULONG pagesize, struct WLDAP32_berval *cookie, UCHAR critical, LDAPControlW **control )
+static ULONG create_page_control( ULONG pagesize, struct berval *cookie, UCHAR critical, LDAPControlW **control )
 {
     LDAPControlW *ctrl;
-    WLDAP32_BerElement *ber;
-    struct WLDAP32_berval *berval, *vec[2];
+    BerElement *ber;
+    struct berval *berval, *vec[2];
     int ret, len;
     char *val;
 
-    if (!(ber = WLDAP32_ber_alloc_t( WLDAP32_LBER_USE_DER ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (!(ber = ber_alloc_t( LBER_USE_DER ))) return LDAP_NO_MEMORY;
 
     vec[1] = NULL;
     if (cookie)
         vec[0] = cookie;
     else
         vec[0] = &null_cookieW;
-    len = WLDAP32_ber_printf( ber, (char *)"{iV}", pagesize, vec );
+    len = ber_printf( ber, (char *)"{iV}", pagesize, vec );
 
-    ret = WLDAP32_ber_flatten( ber, &berval );
-    WLDAP32_ber_free( ber, 1 );
+    ret = ber_flatten( ber, &berval );
+    ber_free( ber, 1 );
 
-    if (len == WLDAP32_LBER_ERROR) return WLDAP32_LDAP_ENCODING_ERROR;
-    if (ret == -1) return WLDAP32_LDAP_NO_MEMORY;
+    if (len == LBER_ERROR) return LDAP_ENCODING_ERROR;
+    if (ret == -1) return LDAP_NO_MEMORY;
 
     /* copy the berval so it can be properly freed by the caller */
-    if (!(val = malloc( berval->bv_len ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (!(val = malloc( berval->bv_len ))) return LDAP_NO_MEMORY;
 
     len = berval->bv_len;
     memcpy( val, berval->bv_val, len );
-    WLDAP32_ber_bvfree( berval );
+    ber_bvfree( berval );
 
     if (!(ctrl = malloc( sizeof(*ctrl) )))
     {
         free( val );
-        return WLDAP32_LDAP_NO_MEMORY;
+        return LDAP_NO_MEMORY;
     }
     if (!(ctrl->ldctl_oid = strAtoW( LDAP_PAGED_RESULT_OID_STRING )))
     {
         free( ctrl );
-        return WLDAP32_LDAP_NO_MEMORY;
+        return LDAP_NO_MEMORY;
     }
     ctrl->ldctl_value.bv_len = len;
     ctrl->ldctl_value.bv_val = val;
     ctrl->ldctl_iscritical   = critical;
 
     *control = ctrl;
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -124,25 +126,25 @@ static ULONG create_page_control( ULONG pagesize, struct WLDAP32_berval *cookie,
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_create_page_controlW( WLDAP32_LDAP *ld, ULONG pagesize, struct WLDAP32_berval *cookie,
-    UCHAR critical, LDAPControlW **control )
+ULONG CDECL ldap_create_page_controlW( LDAP *ld, ULONG pagesize, struct berval *cookie, UCHAR critical,
+    LDAPControlW **control )
 {
     TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld, pagesize, cookie, critical, control );
 
-    if (!ld || !control || pagesize > LDAP_MAXINT) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !control || pagesize > LDAP_MAXINT) return LDAP_PARAM_ERROR;
     return create_page_control( pagesize, cookie, critical, control );
 }
 
-ULONG CDECL ldap_get_next_page( WLDAP32_LDAP *ld, LDAPSearch *search, ULONG pagesize, ULONG *message )
+ULONG CDECL ldap_get_next_page( LDAP *ld, LDAPSearch *search, ULONG pagesize, ULONG *message )
 {
     FIXME( "(%p, %p, 0x%08x, %p)\n", ld, search, pagesize, message );
 
     if (!ld) return ~0u;
-    return WLDAP32_LDAP_NOT_SUPPORTED;
+    return LDAP_NOT_SUPPORTED;
 }
 
-ULONG CDECL ldap_get_next_page_s( WLDAP32_LDAP *ld, LDAPSearch *search, struct l_timeval *timeout, ULONG pagesize,
-    ULONG *count, WLDAP32_LDAPMessage **results )
+ULONG CDECL ldap_get_next_page_s( LDAP *ld, LDAPSearch *search, struct l_timeval *timeout, ULONG pagesize,
+    ULONG *count, LDAPMessage **results )
 {
     ULONG ret;
 
@@ -155,7 +157,7 @@ ULONG CDECL ldap_get_next_page_s( WLDAP32_LDAP *ld, LDAPSearch *search, struct l
         /* end of paged results */
         *count = 0;
         *results = NULL;
-        return WLDAP32_LDAP_NO_RESULTS_RETURNED;
+        return LDAP_NO_RESULTS_RETURNED;
     }
 
     if (search->serverctrls[0])
@@ -166,41 +168,41 @@ ULONG CDECL ldap_get_next_page_s( WLDAP32_LDAP *ld, LDAPSearch *search, struct l
 
     TRACE("search->cookie: %s\n", search->cookie ? debugstr_an(search->cookie->bv_val, search->cookie->bv_len) : "NULL");
     ret = ldap_create_page_controlW( ld, pagesize, search->cookie, 1, &search->serverctrls[0] );
-    if (ret != WLDAP32_LDAP_SUCCESS) return ret;
+    if (ret != LDAP_SUCCESS) return ret;
 
     ret = ldap_search_ext_sW( ld, search->dn, search->scope, search->filter, search->attrs, search->attrsonly,
                               search->serverctrls, search->clientctrls,
                               search->timeout.tv_sec ? &search->timeout : NULL, search->sizelimit, results );
-    if (ret != WLDAP32_LDAP_SUCCESS) return ret;
+    if (ret != LDAP_SUCCESS) return ret;
 
     return ldap_get_paged_count( ld, search, count, *results );
 }
 
-ULONG CDECL ldap_get_paged_count( WLDAP32_LDAP *ld, LDAPSearch *search, ULONG *count, WLDAP32_LDAPMessage *results )
+ULONG CDECL ldap_get_paged_count( LDAP *ld, LDAPSearch *search, ULONG *count, LDAPMessage *results )
 {
     ULONG ret;
     LDAPControlW **server_ctrls = NULL;
 
     TRACE( "(%p, %p, %p, %p)\n", ld, search, count, results );
 
-    if (!ld || !count || !results) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !count || !results) return LDAP_PARAM_ERROR;
 
     *count = 0;
 
     ret = ldap_parse_resultW( ld, results, NULL, NULL, NULL, NULL, &server_ctrls, 0 );
-    if (ret != WLDAP32_LDAP_SUCCESS) return ret;
+    if (ret != LDAP_SUCCESS) return ret;
 
     if (!server_ctrls) /* assume end of paged results */
     {
         search->cookie = &null_cookieW;
-        return WLDAP32_LDAP_SUCCESS;
+        return LDAP_SUCCESS;
     }
 
     free( search->cookie );
     search->cookie = NULL;
 
     ret = ldap_parse_page_controlW( ld, server_ctrls, count, &search->cookie );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    if (ret == LDAP_SUCCESS)
         TRACE("new search->cookie: %s, count %u\n", debugstr_an(search->cookie->bv_val, search->cookie->bv_len), *count);
 
     ldap_controls_freeW( server_ctrls );
@@ -210,17 +212,16 @@ ULONG CDECL ldap_get_paged_count( WLDAP32_LDAP *ld, LDAPSearch *search, ULONG *c
 /***********************************************************************
  *      ldap_parse_page_controlA      (WLDAP32.@)
  */
-ULONG CDECL ldap_parse_page_controlA( WLDAP32_LDAP *ld, LDAPControlA **ctrls, ULONG *count,
-    struct WLDAP32_berval **cookie )
+ULONG CDECL ldap_parse_page_controlA( LDAP *ld, LDAPControlA **ctrls, ULONG *count, struct berval **cookie )
 {
     ULONG ret;
     LDAPControlW **ctrlsW = NULL;
 
     TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
 
-    if (!ld || !ctrls || !count || !cookie) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !ctrls || !count || !cookie) return LDAP_PARAM_ERROR;
 
-    if (!(ctrlsW = controlarrayAtoW( ctrls ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (!(ctrlsW = controlarrayAtoW( ctrls ))) return LDAP_NO_MEMORY;
     ret = ldap_parse_page_controlW( ld, ctrlsW, count, cookie );
     controlarrayfreeW( ctrlsW );
     return ret;
@@ -229,42 +230,41 @@ ULONG CDECL ldap_parse_page_controlA( WLDAP32_LDAP *ld, LDAPControlA **ctrls, UL
 /***********************************************************************
  *      ldap_parse_page_controlW      (WLDAP32.@)
  */
-ULONG CDECL ldap_parse_page_controlW( WLDAP32_LDAP *ld, LDAPControlW **ctrls, ULONG *count,
-    struct WLDAP32_berval **cookie )
+ULONG CDECL ldap_parse_page_controlW( LDAP *ld, LDAPControlW **ctrls, ULONG *count, struct berval **cookie )
 {
     ULONG ret;
     LDAPControlW *control = NULL;
-    WLDAP32_BerElement *ber;
-    struct WLDAP32_berval *vec[2];
+    BerElement *ber;
+    struct berval *vec[2];
     int tag;
     ULONG i;
 
     TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
 
-    if (!ld || !ctrls || !count || !cookie) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !ctrls || !count || !cookie) return LDAP_PARAM_ERROR;
 
     for (i = 0; ctrls[i]; i++)
     {
         if (!lstrcmpW( LDAP_PAGED_RESULT_OID_STRING_W, ctrls[i]->ldctl_oid ))
             control = ctrls[i];
     }
-    if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
+    if (!control) return LDAP_CONTROL_NOT_FOUND;
 
-    if (!(ber = WLDAP32_ber_init( &control->ldctl_value ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (!(ber = ber_init( &control->ldctl_value ))) return LDAP_NO_MEMORY;
 
     vec[0] = *cookie;
     vec[1] = 0;
-    tag = WLDAP32_ber_scanf( ber, (char *)"{iV}", count, vec );
-    if (tag == WLDAP32_LBER_ERROR)
-        ret = WLDAP32_LDAP_DECODING_ERROR;
+    tag = ber_scanf( ber, (char *)"{iV}", count, vec );
+    if (tag == LBER_ERROR)
+        ret = LDAP_DECODING_ERROR;
     else
-        ret = WLDAP32_LDAP_SUCCESS;
+        ret = LDAP_SUCCESS;
 
-    WLDAP32_ber_free( ber, 1 );
+    ber_free( ber, 1 );
     return ret;
 }
 
-ULONG CDECL ldap_search_abandon_page( WLDAP32_LDAP *ld, LDAPSearch *search )
+ULONG CDECL ldap_search_abandon_page( LDAP *ld, LDAPSearch *search )
 {
     LDAPControlW **ctrls;
 
@@ -284,10 +284,10 @@ ULONG CDECL ldap_search_abandon_page( WLDAP32_LDAP *ld, LDAPSearch *search )
     if (search->cookie && search->cookie != &null_cookieW) free( search->cookie );
     free( search );
 
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
-LDAPSearch * CDECL ldap_search_init_pageA( WLDAP32_LDAP *ld, char *dn, ULONG scope, char *filter, char **attrs,
+LDAPSearch * CDECL ldap_search_init_pageA( LDAP *ld, char *dn, ULONG scope, char *filter, char **attrs,
     ULONG attrsonly, LDAPControlA **serverctrls, LDAPControlA **clientctrls, ULONG timelimit, ULONG sizelimit,
     LDAPSortKeyA **sortkeys )
 {
@@ -296,7 +296,7 @@ LDAPSearch * CDECL ldap_search_init_pageA( WLDAP32_LDAP *ld, char *dn, ULONG sco
     return NULL;
 }
 
-LDAPSearch * CDECL ldap_search_init_pageW( WLDAP32_LDAP *ld, WCHAR *dn, ULONG scope, WCHAR *filter, WCHAR **attrs,
+LDAPSearch * CDECL ldap_search_init_pageW( LDAP *ld, WCHAR *dn, ULONG scope, WCHAR *filter, WCHAR **attrs,
     ULONG attrsonly, LDAPControlW **serverctrls, LDAPControlW **clientctrls, ULONG timelimit, ULONG sizelimit,
     LDAPSortKeyW **sortkeys )
 {
@@ -308,7 +308,7 @@ LDAPSearch * CDECL ldap_search_init_pageW( WLDAP32_LDAP *ld, WCHAR *dn, ULONG sc
 
     if (!(search = calloc( 1, sizeof(*search) )))
     {
-        ld->ld_errno = WLDAP32_LDAP_NO_MEMORY;
+        ld->ld_errno = LDAP_NO_MEMORY;
         return NULL;
     }
 
@@ -345,6 +345,6 @@ LDAPSearch * CDECL ldap_search_init_pageW( WLDAP32_LDAP *ld, WCHAR *dn, ULONG sc
 
 fail:
     ldap_search_abandon_page( ld, search );
-    ld->ld_errno = WLDAP32_LDAP_NO_MEMORY;
+    ld->ld_errno = LDAP_NO_MEMORY;
     return NULL;
 }
diff --git a/dlls/wldap32/parse.c b/dlls/wldap32/parse.c
index 1b699435223..b4745546110 100644
--- a/dlls/wldap32/parse.c
+++ b/dlls/wldap32/parse.c
@@ -22,6 +22,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -33,23 +34,23 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *
  * See ldap_parse_extended_resultW.
  */
-ULONG CDECL ldap_parse_extended_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result, char **oid,
-    struct WLDAP32_berval **data, BOOLEAN free )
+ULONG CDECL ldap_parse_extended_resultA( LDAP *ld, LDAPMessage *result, char **oid, struct berval **data,
+    BOOLEAN free )
 {
     ULONG ret;
     WCHAR *oidW = NULL;
 
     TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
-    if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
+    if (!ld) return LDAP_PARAM_ERROR;
+    if (!result) return LDAP_NO_RESULTS_RETURNED;
 
     ret = ldap_parse_extended_resultW( ld, result, &oidW, data, free );
     if (oid && oidW)
     {
         char *str;
         if ((str = strWtoA( oidW ))) *oid = str;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
+        else ret = LDAP_NO_MEMORY;
         ldap_memfreeW( oidW );
     }
     return ret;
@@ -75,8 +76,8 @@ ULONG CDECL ldap_parse_extended_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *
  *  Free the OID and result data with ldap_memfree. Pass a nonzero
  *  value for 'free' or call ldap_msgfree to free the result message.
  */
-ULONG CDECL ldap_parse_extended_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
-    WCHAR **oid, struct WLDAP32_berval **data, BOOLEAN free )
+ULONG CDECL ldap_parse_extended_resultW( LDAP *ld, LDAPMessage *result, WCHAR **oid, struct berval **data,
+    BOOLEAN free )
 {
     ULONG ret;
     char *oidU = NULL;
@@ -84,23 +85,23 @@ ULONG CDECL ldap_parse_extended_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *
 
     TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
-    if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
+    if (!ld) return LDAP_PARAM_ERROR;
+    if (!result) return LDAP_NO_RESULTS_RETURNED;
 
-    ret = map_error( ldap_funcs->ldap_parse_extended_result( ld->ld, result, &oidU, &dataU, free ) );
+    ret = map_error( ldap_funcs->fn_ldap_parse_extended_result( CTX(ld), result, &oidU, &dataU, free ) );
     if (oid && oidU)
     {
         WCHAR *str;
         if ((str = strUtoW( oidU ))) *oid = str;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
-        ldap_funcs->ldap_memfree( oidU );
+        else ret = LDAP_NO_MEMORY;
+        ldap_funcs->fn_ldap_memfree( oidU );
     }
     if (data && dataU)
     {
-        struct WLDAP32_berval *bv;
+        struct berval *bv;
         if ((bv = bervalUtoW( dataU ))) *data = bv;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
-        ldap_funcs->ber_bvfree( dataU );
+        else ret = LDAP_NO_MEMORY;
+        ldap_funcs->fn_ber_bvfree( dataU );
     }
 
     return ret;
@@ -111,7 +112,7 @@ ULONG CDECL ldap_parse_extended_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *
  *
  * See ldap_parse_referenceW.
  */
-ULONG CDECL ldap_parse_referenceA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message, char ***referrals )
+ULONG CDECL ldap_parse_referenceA( LDAP *ld, LDAPMessage *message, char ***referrals )
 {
     ULONG ret;
     WCHAR **referralsW = NULL;
@@ -125,7 +126,7 @@ ULONG CDECL ldap_parse_referenceA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *messag
     {
         char **ref;
         if ((ref = strarrayWtoA( referralsW ))) *referrals = ref;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
+        else ret = LDAP_NO_MEMORY;
         ldap_value_freeW( referralsW );
     }
     return ret;
@@ -148,7 +149,7 @@ ULONG CDECL ldap_parse_referenceA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *messag
  * NOTES
  *  Free the referrals with ldap_value_free.
  */
-ULONG CDECL ldap_parse_referenceW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message, WCHAR ***referrals )
+ULONG CDECL ldap_parse_referenceW( LDAP *ld, LDAPMessage *message, WCHAR ***referrals )
 {
     ULONG ret;
     char **referralsU = NULL;
@@ -157,13 +158,13 @@ ULONG CDECL ldap_parse_referenceW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *messag
 
     if (!ld) return ~0u;
 
-    ret = map_error( ldap_funcs->ldap_parse_reference( ld->ld, message, &referralsU, NULL, 0 ) );
+    ret = map_error( ldap_funcs->fn_ldap_parse_reference( CTX(ld), message, &referralsU, NULL, 0 ) );
     if (referralsU)
     {
         WCHAR **ref;
         if ((ref = strarrayUtoW( referralsU ))) *referrals = ref;
-        else ret = WLDAP32_LDAP_NO_MEMORY;
-        ldap_funcs->ldap_memfree( referralsU );
+        else ret = LDAP_NO_MEMORY;
+        ldap_funcs->fn_ldap_memfree( referralsU );
     }
     return ret;
 }
@@ -173,8 +174,8 @@ ULONG CDECL ldap_parse_referenceW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *messag
  *
  * See ldap_parse_resultW.
  */
-ULONG CDECL ldap_parse_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result, ULONG *retcode, char **matched,
-    char **error, char ***referrals, LDAPControlA ***serverctrls, BOOLEAN free )
+ULONG CDECL ldap_parse_resultA( LDAP *ld, LDAPMessage *result, ULONG *retcode, char **matched, char **error,
+    char ***referrals, LDAPControlA ***serverctrls, BOOLEAN free )
 {
     ULONG ret;
     WCHAR *matchedW = NULL, *errorW = NULL, **referralsW = NULL;
@@ -183,7 +184,7 @@ ULONG CDECL ldap_parse_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result, U
     TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode, matched, error, referrals, serverctrls,
            free );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     ret = ldap_parse_resultW( ld, result, retcode, &matchedW, &errorW, &referralsW, &serverctrlsW, free );
 
@@ -224,8 +225,8 @@ ULONG CDECL ldap_parse_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result, U
  *  ldap_controls_free. Pass a nonzero value for 'free' or call
  *  ldap_msgfree to free the result message.
  */
-ULONG CDECL ldap_parse_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result, ULONG *retcode, WCHAR **matched,
-    WCHAR **error, WCHAR ***referrals, LDAPControlW ***serverctrls, BOOLEAN free )
+ULONG CDECL ldap_parse_resultW( LDAP *ld, LDAPMessage *result, ULONG *retcode, WCHAR **matched, WCHAR **error,
+    WCHAR ***referrals, LDAPControlW ***serverctrls, BOOLEAN free )
 {
     ULONG ret;
     char *matchedU = NULL, *errorU = NULL, **referralsU = NULL;
@@ -234,20 +235,20 @@ ULONG CDECL ldap_parse_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result, U
     TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode, matched, error, referrals, serverctrls,
            free );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
-    ret = map_error( ldap_funcs->ldap_parse_result( ld->ld, result->Request, (int *)retcode, &matchedU, &errorU,
-                                                    &referralsU, &serverctrlsU, free ) );
+    ret = map_error( ldap_funcs->fn_ldap_parse_result( CTX(ld), MSG(result), (int *)retcode, &matchedU, &errorU,
+                                                       &referralsU, &serverctrlsU, free ) );
 
     if (matched) *matched = strUtoW( matchedU );
     if (error) *error = strUtoW( errorU );
     if (referrals) *referrals = strarrayUtoW( referralsU );
     if (serverctrls) *serverctrls = controlarrayUtoW( serverctrlsU );
 
-    ldap_funcs->ldap_memfree( matchedU );
-    ldap_funcs->ldap_memfree( errorU );
-    ldap_funcs->ldap_memvfree( (void **)referralsU );
-    ldap_funcs->ldap_controls_free( serverctrlsU );
+    ldap_funcs->fn_ldap_memfree( matchedU );
+    ldap_funcs->fn_ldap_memfree( errorU );
+    ldap_funcs->fn_ldap_memvfree( (void **)referralsU );
+    ldap_funcs->fn_ldap_controls_free( serverctrlsU );
     return ret;
 }
 
@@ -256,7 +257,7 @@ ULONG CDECL ldap_parse_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result, U
  *
  * See ldap_parse_sort_controlW.
  */
-ULONG CDECL ldap_parse_sort_controlA( WLDAP32_LDAP *ld, LDAPControlA **control, ULONG *result, char **attr )
+ULONG CDECL ldap_parse_sort_controlA( LDAP *ld, LDAPControlA **control, ULONG *result, char **attr )
 {
     ULONG ret;
     WCHAR *attrW = NULL;
@@ -264,9 +265,9 @@ ULONG CDECL ldap_parse_sort_controlA( WLDAP32_LDAP *ld, LDAPControlA **control,
 
     TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
-    if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
-    if (!(controlW = controlarrayAtoW( control ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (!ld) return LDAP_PARAM_ERROR;
+    if (!control) return LDAP_CONTROL_NOT_FOUND;
+    if (!(controlW = controlarrayAtoW( control ))) return LDAP_NO_MEMORY;
 
     ret = ldap_parse_sort_controlW( ld, controlW, result, &attrW );
 
@@ -293,7 +294,7 @@ ULONG CDECL ldap_parse_sort_controlA( WLDAP32_LDAP *ld, LDAPControlA **control,
  * NOTES
  *  If the function fails, free the failing attribute with ldap_memfree.
  */
-ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, LDAPControlW **control, ULONG *result, WCHAR **attr )
+ULONG CDECL ldap_parse_sort_controlW( LDAP *ld, LDAPControlW **control, ULONG *result, WCHAR **attr )
 {
     ULONG ret;
     char *attrU = NULL;
@@ -303,9 +304,9 @@ ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, LDAPControlW **control,
 
     TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
-    if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
-    if (!(controlU = controlarrayWtoU( control ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (!ld) return LDAP_PARAM_ERROR;
+    if (!control) return LDAP_CONTROL_NOT_FOUND;
+    if (!(controlU = controlarrayWtoU( control ))) return LDAP_NO_MEMORY;
 
     for (i = 0; controlU[i]; i++)
     {
@@ -315,11 +316,11 @@ ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, LDAPControlW **control,
     if (!sortcontrol)
     {
         controlarrayfreeU( controlU );
-        return WLDAP32_LDAP_CONTROL_NOT_FOUND;
+        return LDAP_CONTROL_NOT_FOUND;
     }
 
-    ret = map_error( ldap_funcs->ldap_parse_sortresponse_control( ld->ld, sortcontrol, &res, &attrU ) );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    ret = map_error( ldap_funcs->fn_ldap_parse_sortresponse_control( CTX(ld), sortcontrol, &res, &attrU ) );
+    if (ret == LDAP_SUCCESS)
     {
         WCHAR *str;
         if ((str = strUtoW( attrU )))
@@ -327,8 +328,8 @@ ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, LDAPControlW **control,
             *attr = str;
             *result = res;
         }
-        else ret = WLDAP32_LDAP_NO_MEMORY;
-        ldap_funcs->ldap_memfree( attrU );
+        else ret = LDAP_NO_MEMORY;
+        ldap_funcs->fn_ldap_memfree( attrU );
     }
 
     controlarrayfreeU( controlU );
@@ -340,8 +341,8 @@ ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, LDAPControlW **control,
  *
  * See ldap_parse_vlv_controlW.
  */
-int CDECL ldap_parse_vlv_controlA( WLDAP32_LDAP *ld, LDAPControlA **control, ULONG *targetpos, ULONG *listcount,
-    struct WLDAP32_berval **context, int *errcode )
+int CDECL ldap_parse_vlv_controlA( LDAP *ld, LDAPControlA **control, ULONG *targetpos, ULONG *listcount,
+    struct berval **context, int *errcode )
 {
     int ret;
     LDAPControlW **controlW = NULL;
@@ -350,7 +351,7 @@ int CDECL ldap_parse_vlv_controlA( WLDAP32_LDAP *ld, LDAPControlA **control, ULO
 
     if (!ld) return ~0u;
 
-    if (control && !(controlW = controlarrayAtoW( control ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (control && !(controlW = controlarrayAtoW( control ))) return LDAP_NO_MEMORY;
     ret = ldap_parse_vlv_controlW( ld, controlW, targetpos, listcount, context, errcode );
     controlarrayfreeW( controlW );
     return ret;
@@ -376,8 +377,8 @@ int CDECL ldap_parse_vlv_controlA( WLDAP32_LDAP *ld, LDAPControlA **control, ULO
  * NOTES
  *  Free the server context with ber_bvfree.
  */
-int CDECL ldap_parse_vlv_controlW( WLDAP32_LDAP *ld, LDAPControlW **control, ULONG *targetpos, ULONG *listcount,
-    struct WLDAP32_berval **context, int *errcode )
+int CDECL ldap_parse_vlv_controlW( LDAP *ld, LDAPControlW **control, ULONG *targetpos, ULONG *listcount,
+    struct berval **context, int *errcode )
 {
     int ret, pos, count;
     LDAPControlU **controlU, *vlvcontrolU = NULL;
@@ -388,7 +389,7 @@ int CDECL ldap_parse_vlv_controlW( WLDAP32_LDAP *ld, LDAPControlW **control, ULO
 
     if (!ld || !control) return ~0u;
 
-    if (!(controlU = controlarrayWtoU( control ))) return WLDAP32_LDAP_NO_MEMORY;
+    if (!(controlU = controlarrayWtoU( control ))) return LDAP_NO_MEMORY;
 
     for (i = 0; controlU[i]; i++)
     {
@@ -398,21 +399,22 @@ int CDECL ldap_parse_vlv_controlW( WLDAP32_LDAP *ld, LDAPControlW **control, ULO
     if (!vlvcontrolU)
     {
         controlarrayfreeU( controlU );
-        return WLDAP32_LDAP_CONTROL_NOT_FOUND;
+        return LDAP_CONTROL_NOT_FOUND;
     }
 
-    ret = map_error( ldap_funcs->ldap_parse_vlvresponse_control( ld->ld, vlvcontrolU, &pos, &count, &ctxU, errcode ) );
-    if (ret == WLDAP32_LDAP_SUCCESS)
+    ret = map_error( ldap_funcs->fn_ldap_parse_vlvresponse_control( CTX(ld), vlvcontrolU, &pos, &count, &ctxU,
+                                                                    errcode ) );
+    if (ret == LDAP_SUCCESS)
     {
-        struct WLDAP32_berval *bv;
+        struct berval *bv;
         if ((bv = bervalUtoW( ctxU )))
         {
             *context = bv;
             *targetpos = pos;
             *listcount = count;
         }
-        else ret = WLDAP32_LDAP_NO_MEMORY;
-        ldap_funcs->ber_bvfree( ctxU );
+        else ret = LDAP_NO_MEMORY;
+        ldap_funcs->fn_ber_bvfree( ctxU );
     }
 
     controlarrayfreeU( controlU );
diff --git a/dlls/wldap32/rename.c b/dlls/wldap32/rename.c
index b5e06f3f7dd..8d8951f214b 100644
--- a/dlls/wldap32/rename.c
+++ b/dlls/wldap32/rename.c
@@ -22,6 +22,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -33,17 +34,17 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *
  *  See ldap_rename_extW.
  */
-ULONG CDECL ldap_rename_extA( WLDAP32_LDAP *ld, char *dn, char *newrdn, char *newparent, int delete,
+ULONG CDECL ldap_rename_extA( LDAP *ld, char *dn, char *newrdn, char *newparent, int delete,
     LDAPControlA **serverctrls, LDAPControlA **clientctrls, ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *newrdnW = NULL, *newparentW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p, %p)\n", ld, debugstr_a(dn), debugstr_a(newrdn), debugstr_a(newparent),
            delete, serverctrls, clientctrls, message );
 
-    if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !message) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (newrdn && !(newrdnW = strAtoW( newrdn ))) goto exit;
@@ -86,17 +87,17 @@ exit:
  *  the operation. Cancel the operation by calling ldap_abandon
  *  with the message ID.
  */
-ULONG CDECL ldap_rename_extW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *newrdn, WCHAR *newparent, int delete,
+ULONG CDECL ldap_rename_extW( LDAP *ld, WCHAR *dn, WCHAR *newrdn, WCHAR *newparent, int delete,
     LDAPControlW **serverctrls, LDAPControlW **clientctrls, ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *dnU = NULL, *newrdnU = NULL, *newparentU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
 
     TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p, %p)\n", ld, debugstr_w(dn), debugstr_w(newrdn), debugstr_w(newparent),
            delete, serverctrls, clientctrls, message );
 
-    if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !message) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (newrdn && !(newrdnU = strWtoU( newrdn ))) goto exit;
@@ -104,8 +105,8 @@ ULONG CDECL ldap_rename_extW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *newrdn, WCHAR
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_rename( ld->ld, dnU, newrdnU, newparentU, delete, serverctrlsU, clientctrlsU,
-                                              message ) );
+    ret = map_error( ldap_funcs->fn_ldap_rename( CTX(ld), dnU, newrdnU, newparentU, delete, serverctrlsU, clientctrlsU,
+                                                 message ) );
 exit:
     free( dnU );
     free( newrdnU );
@@ -120,17 +121,17 @@ exit:
  *
  *  See ldap_rename_ext_sW.
  */
-ULONG CDECL ldap_rename_ext_sA( WLDAP32_LDAP *ld, char *dn, char *newrdn, char *newparent, int delete,
+ULONG CDECL ldap_rename_ext_sA( LDAP *ld, char *dn, char *newrdn, char *newparent, int delete,
     LDAPControlA **serverctrls, LDAPControlA **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *dnW = NULL, *newrdnW = NULL, *newparentW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p)\n", ld, debugstr_a(dn), debugstr_a(newrdn), debugstr_a(newparent),
            delete, serverctrls, clientctrls );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnW = strAtoW( dn ))) goto exit;
     if (newrdn && !(newrdnW = strAtoW( newrdn ))) goto exit;
@@ -166,17 +167,17 @@ exit:
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL ldap_rename_ext_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *newrdn, WCHAR *newparent, int delete,
+ULONG CDECL ldap_rename_ext_sW( LDAP *ld, WCHAR *dn, WCHAR *newrdn, WCHAR *newparent, int delete,
     LDAPControlW **serverctrls, LDAPControlW **clientctrls )
 {
-    ULONG ret = WLDAP32_LDAP_PARAM_ERROR;
+    ULONG ret = LDAP_PARAM_ERROR;
     char *dnU = NULL, *newrdnU = NULL, *newparentU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
 
     TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p)\n", ld, debugstr_w(dn), debugstr_w(newrdn), debugstr_w(newparent),
            delete, serverctrls, clientctrls );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (dn && !(dnU = strWtoU( dn ))) goto exit;
     if (newrdn && !(newrdnU = strWtoU( newrdn ))) goto exit;
@@ -184,8 +185,8 @@ ULONG CDECL ldap_rename_ext_sW( WLDAP32_LDAP *ld, WCHAR *dn, WCHAR *newrdn, WCHA
     if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
     if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
 
-    ret = map_error( ldap_funcs->ldap_rename_s( ld->ld, dnU, newrdnU, newparentU, delete, serverctrlsU,
-                                                clientctrlsU ) );
+    ret = map_error( ldap_funcs->fn_ldap_rename_s( CTX(ld), dnU, newrdnU, newparentU, delete, serverctrlsU,
+                                                   clientctrlsU ) );
 exit:
     free( dnU );
     free( newrdnU );
diff --git a/dlls/wldap32/search.c b/dlls/wldap32/search.c
index 7a496e02af3..af5b4ab63d3 100644
--- a/dlls/wldap32/search.c
+++ b/dlls/wldap32/search.c
@@ -23,6 +23,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -34,9 +35,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *
  * See ldap_searchW.
  */
-ULONG CDECL ldap_searchA( WLDAP32_LDAP *ld, char *base, ULONG scope, char *filter, char **attrs, ULONG attrsonly )
+ULONG CDECL ldap_searchA( LDAP *ld, char *base, ULONG scope, char *filter, char **attrs, ULONG attrsonly )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
 
     TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld, debugstr_a(base), scope, debugstr_a(filter), attrs, attrsonly );
@@ -79,13 +80,13 @@ exit:
  *  the operation. Cancel the operation by calling ldap_abandon
  *  with the message ID.
  */
-ULONG CDECL ldap_searchW( WLDAP32_LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs, ULONG attrsonly )
+ULONG CDECL ldap_searchW( LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs, ULONG attrsonly )
 {
     ULONG ret, msg;
     TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld, debugstr_w(base), scope, debugstr_w(filter), attrs, attrsonly );
 
     ret = ldap_search_extW( ld, base, scope, filter, attrs, attrsonly, NULL, NULL, 0, 0, &msg );
-    if (ret == WLDAP32_LDAP_SUCCESS) return msg;
+    if (ret == LDAP_SUCCESS) return msg;
     return ~0u;
 }
 
@@ -94,17 +95,17 @@ ULONG CDECL ldap_searchW( WLDAP32_LDAP *ld, WCHAR *base, ULONG scope, WCHAR *fil
  *
  * See ldap_search_extW.
  */
-ULONG CDECL ldap_search_extA( WLDAP32_LDAP *ld, char *base, ULONG scope, char *filter, char **attrs, ULONG attrsonly,
+ULONG CDECL ldap_search_extA( LDAP *ld, char *base, ULONG scope, char *filter, char **attrs, ULONG attrsonly,
     LDAPControlA **serverctrls, LDAPControlA **clientctrls, ULONG timelimit, ULONG sizelimit, ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, 0x%08x, 0x%08x, %p)\n", ld, debugstr_a(base), scope,
            debugstr_a(filter), attrs, attrsonly, serverctrls, clientctrls, timelimit, sizelimit, message );
 
-    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld) return LDAP_PARAM_ERROR;
 
     if (base && !(baseW = strAtoW( base ))) goto exit;
     if (filter && !(filterW = strAtoW( filter ))) goto exit;
@@ -152,11 +153,11 @@ exit:
  *  the operation. Cancel the operation by calling ldap_abandon
  *  with the message ID.
  */
-ULONG CDECL ldap_search_extW( WLDAP32_LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs,
+ULONG CDECL ldap_search_extW( LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs,
     ULONG attrsonly, LDAPControlW **serverctrls, LDAPControlW **clientctrls, ULONG timelimit, ULONG sizelimit,
     ULONG *message )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
     struct timevalU timevalU;
@@ -175,9 +176,8 @@ ULONG CDECL ldap_search_extW( WLDAP32_LDAP *ld, WCHAR *base, ULONG scope, WCHAR
     timevalU.tv_sec = timelimit;
     timevalU.tv_usec = 0;
 
-    ret = map_error( ldap_funcs->ldap_search_ext( ld->ld, baseU, scope, filterU, attrsU, attrsonly,
-                                                  serverctrlsU, clientctrlsU, timelimit ? &timevalU : NULL, sizelimit,
-                                                  message ) );
+    ret = map_error( ldap_funcs->fn_ldap_search_ext( CTX(ld), baseU, scope, filterU, attrsU, attrsonly, serverctrlsU,
+                                                     clientctrlsU, timelimit ? &timevalU : NULL, sizelimit, message ) );
 exit:
     free( baseU );
     free( filterU );
@@ -192,18 +192,18 @@ exit:
  *
  * See ldap_search_ext_sW.
  */
-ULONG CDECL ldap_search_ext_sA( WLDAP32_LDAP *ld, char *base, ULONG scope, char *filter, char **attrs,
+ULONG CDECL ldap_search_ext_sA( LDAP *ld, char *base, ULONG scope, char *filter, char **attrs,
     ULONG attrsonly, LDAPControlA **serverctrls, LDAPControlA **clientctrls, struct l_timeval *timeout,
-    ULONG sizelimit, WLDAP32_LDAPMessage **res )
+    ULONG sizelimit, LDAPMessage **res )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
 
     TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n", ld, debugstr_a(base), scope,
            debugstr_a(filter), attrs, attrsonly, serverctrls, clientctrls, timeout, sizelimit, res );
 
-    if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !res) return LDAP_PARAM_ERROR;
 
     if (base && !(baseW = strAtoW( base ))) goto exit;
     if (filter && !(filterW = strAtoW( filter ))) goto exit;
@@ -249,11 +249,11 @@ exit:
  * NOTES
  *  Call ldap_msgfree to free the results.
  */
-ULONG CDECL ldap_search_ext_sW( WLDAP32_LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs,
+ULONG CDECL ldap_search_ext_sW( LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs,
     ULONG attrsonly, LDAPControlW **serverctrls, LDAPControlW **clientctrls, struct l_timeval *timeout,
-    ULONG sizelimit, WLDAP32_LDAPMessage **res )
+    ULONG sizelimit, LDAPMessage **res )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
     LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
     struct timevalU timevalU;
@@ -262,7 +262,7 @@ ULONG CDECL ldap_search_ext_sW( WLDAP32_LDAP *ld, WCHAR *base, ULONG scope, WCHA
     TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p, %p, 0x%08x, %p)\n", ld, debugstr_w(base), scope,
            debugstr_w(filter), attrs, attrsonly, serverctrls, clientctrls, timeout, sizelimit, res );
 
-    if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !res) return LDAP_PARAM_ERROR;
 
     if (base && !(baseU = strWtoU( base ))) goto exit;
     if (filter && !(filterU = strWtoU( filter ))) goto exit;
@@ -276,20 +276,20 @@ ULONG CDECL ldap_search_ext_sW( WLDAP32_LDAP *ld, WCHAR *base, ULONG scope, WCHA
         timevalU.tv_usec = timeout->tv_usec;
     }
 
-    ret = map_error( ldap_funcs->ldap_search_ext_s( ld->ld, baseU, scope, filterU, attrsU, attrsonly, serverctrlsU,
-                                                    clientctrlsU, timeout ? &timevalU : NULL, sizelimit, &msgU ) );
+    ret = map_error( ldap_funcs->fn_ldap_search_ext_s( CTX(ld), baseU, scope, filterU, attrsU, attrsonly, serverctrlsU,
+                                                       clientctrlsU, timeout ? &timevalU : NULL, sizelimit, &msgU ) );
     if (msgU)
     {
-        WLDAP32_LDAPMessage *msg = calloc( 1, sizeof(*msg) );
+        LDAPMessage *msg = calloc( 1, sizeof(*msg) );
         if (msg)
         {
-            msg->Request = msgU;
+            MSG(msg) = msgU;
             *res = msg;
         }
         else
         {
-            ldap_funcs->ldap_msgfree( msgU );
-            ret = WLDAP32_LDAP_NO_MEMORY;
+            ldap_funcs->fn_ldap_msgfree( msgU );
+            ret = LDAP_NO_MEMORY;
         }
     }
 
@@ -307,16 +307,16 @@ exit:
  *
  * See ldap_search_sW.
  */
-ULONG CDECL ldap_search_sA( WLDAP32_LDAP *ld, char *base, ULONG scope, char *filter, char **attrs, ULONG attrsonly,
-    WLDAP32_LDAPMessage **res )
+ULONG CDECL ldap_search_sA( LDAP *ld, char *base, ULONG scope, char *filter, char **attrs, ULONG attrsonly,
+    LDAPMessage **res )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
 
     TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p)\n", ld, debugstr_a(base), scope, debugstr_a(filter), attrs,
            attrsonly, res );
 
-    if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !res) return LDAP_PARAM_ERROR;
 
     if (base && !(baseW = strAtoW( base ))) goto exit;
     if (filter && !(filterW = strAtoW( filter ))) goto exit;
@@ -353,8 +353,8 @@ exit:
  * NOTES
  *  Call ldap_msgfree to free the results.
  */
-ULONG CDECL ldap_search_sW( WLDAP32_LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs, ULONG attrsonly,
-    WLDAP32_LDAPMessage **res )
+ULONG CDECL ldap_search_sW( LDAP *ld, WCHAR *base, ULONG scope, WCHAR *filter, WCHAR **attrs, ULONG attrsonly,
+    LDAPMessage **res )
 {
     TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p)\n", ld, debugstr_w(base), scope, debugstr_w(filter), attrs,
            attrsonly, res );
@@ -366,16 +366,16 @@ ULONG CDECL ldap_search_sW( WLDAP32_LDAP *ld, WCHAR *base, ULONG scope, WCHAR *f
  *
  * See ldap_search_stW.
  */
-ULONG CDECL ldap_search_stA( WLDAP32_LDAP *ld, const PCHAR base, ULONG scope, const PCHAR filter, char **attrs,
-    ULONG attrsonly, struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
+ULONG CDECL ldap_search_stA( LDAP *ld, const PCHAR base, ULONG scope, const PCHAR filter, char **attrs,
+    ULONG attrsonly, struct l_timeval *timeout, LDAPMessage **res )
 {
-    ULONG ret = WLDAP32_LDAP_NO_MEMORY;
+    ULONG ret = LDAP_NO_MEMORY;
     WCHAR *baseW = NULL, *filterW = NULL, **attrsW = NULL;
 
     TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p)\n", ld, debugstr_a(base), scope, debugstr_a(filter), attrs,
            attrsonly, timeout, res );
 
-    if (!ld || !res) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!ld || !res) return LDAP_PARAM_ERROR;
 
     if (base && !(baseW = strAtoW( base ))) goto exit;
     if (filter && !(filterW = strAtoW( filter ))) goto exit;
@@ -413,8 +413,8 @@ exit:
  * NOTES
  *  Call ldap_msgfree to free the results.
  */
-ULONG CDECL ldap_search_stW( WLDAP32_LDAP *ld, const PWCHAR base, ULONG scope, const PWCHAR filter, WCHAR **attrs,
-    ULONG attrsonly, struct l_timeval *timeout, WLDAP32_LDAPMessage **res )
+ULONG CDECL ldap_search_stW( LDAP *ld, const PWCHAR base, ULONG scope, const PWCHAR filter, WCHAR **attrs,
+    ULONG attrsonly, struct l_timeval *timeout, LDAPMessage **res )
 {
     TRACE( "(%p, %s, 0x%08x, %s, %p, 0x%08x, %p, %p)\n", ld, debugstr_w(base), scope, debugstr_w(filter), attrs,
            attrsonly, timeout, res );
diff --git a/dlls/wldap32/value.c b/dlls/wldap32/value.c
index b2111557afb..d7fc1902bde 100644
--- a/dlls/wldap32/value.c
+++ b/dlls/wldap32/value.c
@@ -23,6 +23,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
+#include "winldap.h"
 
 #include "wine/debug.h"
 #include "winldap_private.h"
@@ -45,10 +46,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
  *  Call ldap_count_values_len with the result of a call to
  *  ldap_get_values_len.
  */
-ULONG CDECL WLDAP32_ldap_count_values_len( struct WLDAP32_berval **values )
+ULONG CDECL ldap_count_values_len( struct berval **values )
 {
     ULONG ret = 0;
-    struct WLDAP32_berval **ptr = values;
+    struct berval **ptr = values;
 
     TRACE( "(%p)\n", values );
 
@@ -107,7 +108,7 @@ ULONG CDECL ldap_count_valuesW( WCHAR **values )
  *
  * See ldap_get_valuesW.
  */
-char ** CDECL ldap_get_valuesA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, char *attr )
+char ** CDECL ldap_get_valuesA( LDAP *ld, LDAPMessage *entry, char *attr )
 {
     char **ret;
     WCHAR *attrW = NULL, **retW;
@@ -186,7 +187,7 @@ static char **bv2str_array( struct bervalU **bv )
  *  ldap_first_entry or ldap_next_entry. Free the returned
  *  array with a call to ldap_value_freeW.
  */
-WCHAR ** CDECL ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, WCHAR *attr )
+WCHAR ** CDECL ldap_get_valuesW( LDAP *ld, LDAPMessage *entry, WCHAR *attr )
 {
     WCHAR **ret = NULL;
     char *attrU, **retU;
@@ -196,12 +197,12 @@ WCHAR ** CDECL ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, W
 
     if (!ld || !entry || !attr || !(attrU = strWtoU( attr ))) return NULL;
 
-    if ((bv = ldap_funcs->ldap_get_values_len( ld->ld, entry->Request, attrU )))
+    if ((bv = ldap_funcs->fn_ldap_get_values_len( CTX(ld), MSG(entry), attrU )))
     {
         retU = bv2str_array( bv );
         ret = strarrayUtoW( retU );
 
-        ldap_funcs->ldap_value_free_len( bv );
+        ldap_funcs->fn_ldap_value_free_len( bv );
         strarrayfreeU( retU );
     }
 
@@ -214,10 +215,10 @@ WCHAR ** CDECL ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, W
  *
  * See ldap_get_values_lenW.
  */
-struct WLDAP32_berval ** CDECL ldap_get_values_lenA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message, char *attr )
+struct berval ** CDECL ldap_get_values_lenA( LDAP *ld, LDAPMessage *message, char *attr )
 {
     WCHAR *attrW;
-    struct WLDAP32_berval **ret;
+    struct berval **ret;
 
     TRACE( "(%p, %p, %s)\n", ld, message, debugstr_a(attr) );
 
@@ -248,17 +249,17 @@ struct WLDAP32_berval ** CDECL ldap_get_values_lenA( WLDAP32_LDAP *ld, WLDAP32_L
  *  ldap_first_entry or ldap_next_entry. Free the returned
  *  array with a call to ldap_value_free_len.
  */
-struct WLDAP32_berval ** CDECL ldap_get_values_lenW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message, WCHAR *attr )
+struct berval ** CDECL ldap_get_values_lenW( LDAP *ld, LDAPMessage *message, WCHAR *attr )
 {
     char *attrU = NULL;
     struct bervalU **retU;
-    struct WLDAP32_berval **ret = NULL;
+    struct berval **ret = NULL;
 
     TRACE( "(%p, %p, %s)\n", ld, message, debugstr_w(attr) );
 
     if (!ld || !message || !attr || !(attrU = strWtoU( attr ))) return NULL;
 
-    if ((retU = ldap_funcs->ldap_get_values_len( ld->ld, message->Request, attrU )))
+    if ((retU = ldap_funcs->fn_ldap_get_values_len( CTX(ld), MSG(message), attrU )))
     {
         ret = bvarrayUtoW( retU );
         bvarrayfreeU( retU );
@@ -280,12 +281,12 @@ struct WLDAP32_berval ** CDECL ldap_get_values_lenW( WLDAP32_LDAP *ld, WLDAP32_L
  *  Success: LDAP_SUCCESS
  *  Failure: An LDAP error code.
  */
-ULONG CDECL WLDAP32_ldap_value_free_len( struct WLDAP32_berval **values )
+ULONG CDECL ldap_value_free_len( struct berval **values )
 {
     TRACE( "(%p)\n", values );
 
     bvarrayfreeW( values );
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -298,7 +299,7 @@ ULONG CDECL ldap_value_freeA( char **values )
     TRACE( "(%p)\n", values );
 
     strarrayfreeA( values );
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
 
 /***********************************************************************
@@ -318,5 +319,5 @@ ULONG CDECL ldap_value_freeW( WCHAR **values )
     TRACE( "(%p)\n", values );
 
     strarrayfreeW( values );
-    return WLDAP32_LDAP_SUCCESS;
+    return LDAP_SUCCESS;
 }
diff --git a/dlls/wldap32/winldap_private.h b/dlls/wldap32/winldap_private.h
index 0d528471b0c..b8b6daf5a50 100644
--- a/dlls/wldap32/winldap_private.h
+++ b/dlls/wldap32/winldap_private.h
@@ -16,10 +16,6 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- *
- * This is an internal version of winldap.h where constants, types and
- * functions are prefixed with WLDAP32_ whenever they conflict with
- * native headers.
  */
 
 #include <assert.h>
@@ -28,475 +24,24 @@
 #include "winnls.h"
 #include "libldap.h"
 
-#define WLDAP32_LBER_ERROR (~0L)
-
-#define WLDAP32_LDAP_VERSION1   1
-#define WLDAP32_LDAP_VERSION2   2
-#define WLDAP32_LDAP_VERSION3   3
-
-#define WLDAP32_LDAP_OPT_ON  ((void *)1)
-#define WLDAP32_LDAP_OPT_OFF ((void *)0)
-
-#define WLDAP32_LDAP_SCOPE_BASE     0x00
-#define WLDAP32_LDAP_SCOPE_ONELEVEL 0x01
-#define WLDAP32_LDAP_SCOPE_SUBTREE  0x02
-
-#define WLDAP32_LBER_USE_DER 0x01
-
-typedef enum {
-    WLDAP32_LDAP_SUCCESS                 =   0x00,
-    WLDAP32_LDAP_UNWILLING_TO_PERFORM    =   0x35,
-    WLDAP32_LDAP_SERVER_DOWN             =   0x51,
-    WLDAP32_LDAP_LOCAL_ERROR             =   0x52,
-    WLDAP32_LDAP_ENCODING_ERROR          =   0x53,
-    WLDAP32_LDAP_DECODING_ERROR          =   0x54,
-    WLDAP32_LDAP_TIMEOUT                 =   0x55,
-    WLDAP32_LDAP_AUTH_UNKNOWN            =   0x56,
-    WLDAP32_LDAP_FILTER_ERROR            =   0x57,
-    WLDAP32_LDAP_USER_CANCELLED          =   0x58,
-    WLDAP32_LDAP_PARAM_ERROR             =   0x59,
-    WLDAP32_LDAP_NO_MEMORY               =   0x5a,
-    WLDAP32_LDAP_CONNECT_ERROR           =   0x5b,
-    WLDAP32_LDAP_NOT_SUPPORTED           =   0x5c,
-    WLDAP32_LDAP_NO_RESULTS_RETURNED     =   0x5e,
-    WLDAP32_LDAP_CONTROL_NOT_FOUND       =   0x5d,
-    WLDAP32_LDAP_MORE_RESULTS_TO_RETURN  =   0x5f,
-
-    WLDAP32_LDAP_CLIENT_LOOP             =   0x60,
-    WLDAP32_LDAP_REFERRAL_LIMIT_EXCEEDED =   0x61
-} LDAP_RETCODE;
-
-typedef struct berelement
-{
-    PCHAR opaque;
-} WLDAP32_BerElement;
-
-#define WLDAP32_LDAP_OPT_API_INFO               0x00
-#define WLDAP32_LDAP_OPT_DESC                   0x01
-#define WLDAP32_LDAP_OPT_DEREF                  0x02
-#define WLDAP32_LDAP_OPT_SIZELIMIT              0x03
-#define WLDAP32_LDAP_OPT_TIMELIMIT              0x04
-#define WLDAP32_LDAP_OPT_THREAD_FN_PTRS         0x05
-#define WLDAP32_LDAP_OPT_REBIND_FN              0x06
-#define WLDAP32_LDAP_OPT_REBIND_ARG             0x07
-#define WLDAP32_LDAP_OPT_REFERRALS              0x08
-#define WLDAP32_LDAP_OPT_RESTART                0x09
-#define WLDAP32_LDAP_OPT_SSL                    0x0a
-#define WLDAP32_LDAP_OPT_IO_FN_PTRS             0x0b
-#define WLDAP32_LDAP_OPT_CACHE_FN_PTRS          0x0d
-#define WLDAP32_LDAP_OPT_CACHE_STRATEGY         0x0e
-#define WLDAP32_LDAP_OPT_CACHE_ENABLE           0x0f
-#define WLDAP32_LDAP_OPT_REFERRAL_HOP_LIMIT     0x10
-#define WLDAP32_LDAP_OPT_VERSION                0x11
-#define WLDAP32_LDAP_OPT_PROTOCOL_VERSION       WLDAP32_LDAP_OPT_VERSION
-#define WLDAP32_LDAP_OPT_SERVER_CONTROLS        0x12
-#define WLDAP32_LDAP_OPT_API_FEATURE_INFO       0x15
-#define WLDAP32_LDAP_OPT_HOST_NAME              0x30
-#define WLDAP32_LDAP_OPT_ERROR_NUMBER           0x31
-#define WLDAP32_LDAP_OPT_ERROR_STRING           0x32
-#define WLDAP32_LDAP_OPT_SERVER_ERROR           0x33
-#define WLDAP32_LDAP_OPT_SERVER_EXT_ERROR       0x34
-#define WLDAP32_LDAP_OPT_PING_KEEP_ALIVE        0x36
-#define WLDAP32_LDAP_OPT_PING_WAIT_TIME         0x37
-#define WLDAP32_LDAP_OPT_PING_LIMIT             0x38
-#define WLDAP32_LDAP_OPT_DNSDOMAIN_NAME         0x3b
-#define WLDAP32_LDAP_OPT_GETDSNAME_FLAGS        0x3d
-#define WLDAP32_LDAP_OPT_HOST_REACHABLE         0x3e
-#define WLDAP32_LDAP_OPT_PROMPT_CREDENTIALS     0x3f
-#define WLDAP32_LDAP_OPT_TCP_KEEPALIVE          0x40
-#define WLDAP32_LDAP_OPT_FAST_CONCURRENT_BIND   0x41
-#define WLDAP32_LDAP_OPT_SEND_TIMEOUT           0x42
-#define WLDAP32_LDAP_OPT_REFERRAL_CALLBACK      0x70
-#define WLDAP32_LDAP_OPT_CLIENT_CERTIFICATE     0x80
-#define WLDAP32_LDAP_OPT_SERVER_CERTIFICATE     0x81
-#define WLDAP32_LDAP_OPT_AUTO_RECONNECT         0x91
-#define WLDAP32_LDAP_OPT_SSPI_FLAGS             0x92
-#define WLDAP32_LDAP_OPT_SSL_INFO               0x93
-#define WLDAP32_LDAP_OPT_REF_DEREF_CONN_PER_MSG 0x94
-#define WLDAP32_LDAP_OPT_TLS                    WLDAP32_LDAP_OPT_SSL
-#define WLDAP32_LDAP_OPT_TLS_INFO               WLDAP32_LDAP_OPT_SSL_INFO
-#define WLDAP32_LDAP_OPT_SIGN                   0x95
-#define WLDAP32_LDAP_OPT_ENCRYPT                0x96
-#define WLDAP32_LDAP_OPT_SASL_METHOD            0x97
-#define WLDAP32_LDAP_OPT_AREC_EXCLUSIVE         0x98
-#define WLDAP32_LDAP_OPT_SECURITY_CONTEXT       0x99
-#define WLDAP32_LDAP_OPT_ROOTDSE_CACHE          0x9a
-
-#define WLDAP32_LDAP_AUTH_SIMPLE         0x80
-#define WLDAP32_LDAP_AUTH_SASL           0x83
-#define WLDAP32_LDAP_AUTH_NEGOTIATE     0x486
-
-typedef struct WLDAP32_berval
-{
-    ULONG bv_len;
-    PCHAR bv_val;
-} LDAP_BERVAL, *PLDAP_BERVAL, BERVAL, *PBERVAL, WLDAP32_BerValue;
-
-typedef struct wldap32
-{
-    struct
-    {
-        UINT_PTR sb_sd;
-        UCHAR Reserved1[41];
-        ULONG_PTR sb_naddr;
-        UCHAR Reserved2[24];
-    } ld_sb;
-
-    PCHAR ld_host;
-    ULONG ld_version;
-    UCHAR ld_lberoptions;
-    ULONG ld_deref;
-    ULONG ld_timelimit;
-    ULONG ld_sizelimit;
-    ULONG ld_errno;
-    PCHAR ld_matched;
-    PCHAR ld_error;
-    ULONG ld_msgid;
-    UCHAR Reserved3[25];
-    ULONG ld_cldaptries;
-    ULONG ld_cldaptimeout;
-    ULONG ld_refhoplimit;
-    ULONG ld_options;
-    /* internal LDAP context */
-    struct bervalU **ld_server_ctrls;
-    void *ld;
-} WLDAP32_LDAP, *WLDAP32_PLDAP;
-
-typedef struct ldapmodA {
-    ULONG mod_op;
-    PCHAR mod_type;
-    union {
-        PCHAR *modv_strvals;
-        struct WLDAP32_berval **modv_bvals;
-    } mod_vals;
-} LDAPModA, *PLDAPModA;
-
-typedef struct ldapmodW {
-    ULONG mod_op;
-    PWCHAR mod_type;
-    union {
-        PWCHAR *modv_strvals;
-        struct WLDAP32_berval **modv_bvals;
-    } mod_vals;
-} LDAPModW, *PLDAPModW;
-
-typedef struct l_timeval
-{
-    LONG tv_sec;
-    LONG tv_usec;
-} LDAP_TIMEVAL, *PLDAP_TIMEVAL;
-
-typedef struct ldapmsg
-{
-    ULONG lm_msgid;
-    ULONG lm_msgtype;
-
-    PVOID lm_ber;
-
-    struct ldapmsg *lm_chain;
-    struct ldapmsg *lm_next;
-    ULONG lm_time;
-
-    WLDAP32_PLDAP Connection;
-    PVOID Request;
-    ULONG lm_returncode;
-    USHORT lm_referral;
-    BOOLEAN lm_chased;
-    BOOLEAN lm_eom;
-    BOOLEAN ConnectionReferenced;
-} WLDAP32_LDAPMessage, *WLDAP32_PLDAPMessage;
-
-#define LAPI_MAJOR_VER1     1
-#define LAPI_MINOR_VER1     1
-
-typedef struct ldap_version_info
-{
-    ULONG lv_size;
-    ULONG lv_major;
-    ULONG lv_minor;
-} LDAP_VERSION_INFO, *PLDAP_VERSION_INFO;
-
-#define LDAP_PAGED_RESULT_OID_STRING "1.2.840.113556.1.4.319"
-#define LDAP_SERVER_RESP_SORT_OID "1.2.840.113556.1.4.474"
-#define LDAP_CONTROL_VLVRESPONSE "2.16.840.1.113730.3.4.10"
-
-#define LDAP_PAGED_RESULT_OID_STRING_W L"1.2.840.113556.1.4.319"
-#define LDAP_SERVER_RESP_SORT_OID_W L"1.2.840.113556.1.4.474"
-#define LDAP_CONTROL_VLVRESPONSE_W L"2.16.840.1.113730.3.4.10"
-
-typedef struct ldapcontrolA
-{
-    PCHAR ldctl_oid;
-    struct WLDAP32_berval ldctl_value;
-    BOOLEAN ldctl_iscritical;
-} LDAPControlA, *PLDAPControlA;
-
-typedef struct ldapcontrolW
-{
-    PWCHAR ldctl_oid;
-    struct WLDAP32_berval ldctl_value;
-    BOOLEAN ldctl_iscritical;
-} LDAPControlW, *PLDAPControlW;
-
-typedef struct WLDAP32_ldapvlvinfo
-{
-    int ldvlv_version;
-    ULONG ldvlv_before_count;
-    ULONG ldvlv_after_count;
-    ULONG ldvlv_offset;
-    ULONG ldvlv_count;
-    PBERVAL ldvlv_attrvalue;
-    PBERVAL ldvlv_context;
-    VOID *ldvlv_extradata;
-} WLDAP32_LDAPVLVInfo, *WLDAP32_PLDAPVLVInfo;
-
 typedef struct ldapsearch
 {
-    WCHAR *dn, *filter, **attrs;
-    ULONG scope, attrsonly;
+    WCHAR *dn;
+    WCHAR *filter;
+    WCHAR **attrs;
+    ULONG scope;
+    ULONG attrsonly;
     LDAPControlW **serverctrls;
     LDAPControlW **clientctrls;
     struct l_timeval timeout;
     ULONG sizelimit;
-    struct WLDAP32_berval *cookie;
-} LDAPSearch, *PLDAPSearch;
-
-typedef struct ldapsortkeyA
-{
-    PCHAR sk_attrtype;
-    PCHAR sk_matchruleoid;
-    BOOLEAN sk_reverseorder;
-} LDAPSortKeyA, *PLDAPSortKeyA;
-
-typedef struct ldapsortkeyW
-{
-    PWCHAR sk_attrtype;
-    PWCHAR sk_matchruleoid;
-    BOOLEAN sk_reverseorder;
-} LDAPSortKeyW, *PLDAPSortKeyW;
-
-typedef struct ldapapiinfoA
-{
-    int ldapai_info_version;
-    int ldapai_api_version;
-    int ldapai_protocol_version;
-    char **ldapai_extensions;
-    char *ldapai_vendor_name;
-    int ldapai_vendor_version;
-} LDAPAPIInfoA;
-
-typedef struct ldapapiinfoW
-{
-    int ldapai_info_version;
-    int ldapai_api_version;
-    int ldapai_protocol_version;
-    PWCHAR *ldapai_extensions;
-    PWCHAR ldapai_vendor_name;
-    int ldapai_vendor_version;
-} LDAPAPIInfoW;
-
-typedef struct ldap_apifeature_infoA
-{
-    int ldapaif_info_version;
-    char *ldapaif_name;
-    int ldapaif_version;
-} LDAPAPIFeatureInfoA;
-
-typedef struct ldap_apifeature_infoW
-{
-    int ldapaif_info_version;
-    PWCHAR ldapaif_name;
-    int ldapaif_version;
-} LDAPAPIFeatureInfoW;
-
-WLDAP32_BerElement * CDECL WLDAP32_ber_alloc_t(int);
-void CDECL WLDAP32_ber_bvfree(BERVAL *);
-int CDECL WLDAP32_ber_flatten(WLDAP32_BerElement *, BERVAL **);
-void CDECL WLDAP32_ber_free(WLDAP32_BerElement *, int);
-WLDAP32_BerElement * CDECL WLDAP32_ber_init(BERVAL *);
-int WINAPIV WLDAP32_ber_printf(WLDAP32_BerElement *, char *, ...);
-ULONG WINAPIV WLDAP32_ber_scanf(WLDAP32_BerElement *, char *, ...);
-
-WLDAP32_LDAP * CDECL cldap_openA(PCHAR,ULONG);
-WLDAP32_LDAP * CDECL cldap_openW(PWCHAR,ULONG);
-ULONG CDECL WLDAP32_ldap_abandon(WLDAP32_LDAP*,ULONG);
-ULONG CDECL ldap_addA(WLDAP32_LDAP*,PCHAR,LDAPModA*[]);
-ULONG CDECL ldap_addW(WLDAP32_LDAP*,PWCHAR,LDAPModW*[]);
-ULONG CDECL ldap_add_extA(WLDAP32_LDAP*,PCHAR,LDAPModA*[],PLDAPControlA*,PLDAPControlA*,ULONG*);
-ULONG CDECL ldap_add_extW(WLDAP32_LDAP*,PWCHAR,LDAPModW*[],PLDAPControlW*,PLDAPControlW*,ULONG*);
-ULONG CDECL ldap_add_ext_sA(WLDAP32_LDAP*,PCHAR,LDAPModA*[],PLDAPControlA*,PLDAPControlA*);
-ULONG CDECL ldap_add_ext_sW(WLDAP32_LDAP*,PWCHAR,LDAPModW*[],PLDAPControlW*,PLDAPControlW*);
-ULONG CDECL ldap_add_sA(WLDAP32_LDAP*,PCHAR,LDAPModA*[]);
-ULONG CDECL ldap_add_sW(WLDAP32_LDAP*,PWCHAR,LDAPModW*[]);
-ULONG CDECL ldap_bindA(WLDAP32_LDAP*,PCHAR,PCHAR,ULONG);
-ULONG CDECL ldap_bindW(WLDAP32_LDAP*,PWCHAR,PWCHAR,ULONG);
-ULONG CDECL ldap_bind_sA(WLDAP32_LDAP*,PCHAR,PCHAR,ULONG);
-ULONG CDECL ldap_bind_sW(WLDAP32_LDAP*,PWCHAR,PWCHAR,ULONG);
-ULONG CDECL ldap_check_filterA(WLDAP32_LDAP*,PCHAR);
-ULONG CDECL ldap_check_filterW(WLDAP32_LDAP*,PWCHAR);
-ULONG CDECL ldap_cleanup(HANDLE);
-ULONG CDECL ldap_close_extended_op(WLDAP32_LDAP*,ULONG);
-ULONG CDECL ldap_compareA(WLDAP32_LDAP*,PCHAR,PCHAR,PCHAR);
-ULONG CDECL ldap_compareW(WLDAP32_LDAP*,PWCHAR,PWCHAR,PWCHAR);
-ULONG CDECL ldap_compare_extA(WLDAP32_LDAP*,PCHAR,PCHAR,PCHAR,struct WLDAP32_berval*,PLDAPControlA*,PLDAPControlA*,ULONG*);
-ULONG CDECL ldap_compare_extW(WLDAP32_LDAP*,PWCHAR,PWCHAR,PWCHAR,struct WLDAP32_berval*,PLDAPControlW*,PLDAPControlW*,ULONG*);
-ULONG CDECL ldap_compare_ext_sA(WLDAP32_LDAP*,PCHAR,PCHAR,PCHAR,struct WLDAP32_berval*,PLDAPControlA*,PLDAPControlA*);
-ULONG CDECL ldap_compare_ext_sW(WLDAP32_LDAP*,PWCHAR,PWCHAR,PWCHAR,struct WLDAP32_berval*,PLDAPControlW*,PLDAPControlW*);
-ULONG CDECL ldap_compare_sA(WLDAP32_LDAP*,PCHAR,PCHAR,PCHAR);
-ULONG CDECL ldap_compare_sW(WLDAP32_LDAP*,PWCHAR,PWCHAR,PWCHAR);
-ULONG CDECL ldap_connect(WLDAP32_LDAP*,LDAP_TIMEVAL*);
-WLDAP32_LDAP * CDECL ldap_conn_from_msg(WLDAP32_LDAP*,WLDAP32_LDAPMessage*);
-ULONG CDECL ldap_control_freeA(LDAPControlA*);
-ULONG CDECL ldap_control_freeW(LDAPControlW*);
-ULONG CDECL ldap_controls_freeA(LDAPControlA**);
-ULONG CDECL ldap_controls_freeW(LDAPControlW**);
-ULONG CDECL WLDAP32_ldap_count_entries(WLDAP32_LDAP*,WLDAP32_LDAPMessage*);
-ULONG CDECL WLDAP32_ldap_count_references(WLDAP32_LDAP*,WLDAP32_LDAPMessage*);
-ULONG CDECL ldap_count_valuesA(PCHAR*);
-ULONG CDECL ldap_count_valuesW(PWCHAR*);
-ULONG CDECL WLDAP32_ldap_count_values_len(PBERVAL*);
-ULONG CDECL ldap_create_page_controlA(WLDAP32_PLDAP,ULONG,struct WLDAP32_berval*,UCHAR,PLDAPControlA*);
-ULONG CDECL ldap_create_page_controlW(WLDAP32_PLDAP,ULONG,struct WLDAP32_berval*,UCHAR,PLDAPControlW*);
-ULONG CDECL ldap_create_sort_controlA(WLDAP32_PLDAP,PLDAPSortKeyA*,UCHAR,PLDAPControlA*);
-ULONG CDECL ldap_create_sort_controlW(WLDAP32_PLDAP,PLDAPSortKeyW*,UCHAR,PLDAPControlW*);
-INT CDECL ldap_create_vlv_controlA(WLDAP32_LDAP*,WLDAP32_LDAPVLVInfo*,UCHAR,LDAPControlA**);
-INT CDECL ldap_create_vlv_controlW(WLDAP32_LDAP*,WLDAP32_LDAPVLVInfo*,UCHAR,LDAPControlW**);
-ULONG CDECL ldap_deleteA(WLDAP32_LDAP*,PCHAR);
-ULONG CDECL ldap_deleteW(WLDAP32_LDAP*,PWCHAR);
-ULONG CDECL ldap_delete_extA(WLDAP32_LDAP*,PCHAR,PLDAPControlA*,PLDAPControlA*,ULONG*);
-ULONG CDECL ldap_delete_extW(WLDAP32_LDAP*,PWCHAR,PLDAPControlW*,PLDAPControlW*,ULONG*);
-ULONG CDECL ldap_delete_ext_sA(WLDAP32_LDAP*,PCHAR,PLDAPControlA*,PLDAPControlA*);
-ULONG CDECL ldap_delete_ext_sW(WLDAP32_LDAP*,PWCHAR,PLDAPControlW*,PLDAPControlW*);
-ULONG CDECL ldap_delete_sA(WLDAP32_LDAP*,PCHAR);
-ULONG CDECL ldap_delete_sW(WLDAP32_LDAP*,PWCHAR);
-PCHAR CDECL ldap_dn2ufnA(PCHAR);
-PWCHAR CDECL ldap_dn2ufnW(PWCHAR);
-ULONG CDECL ldap_encode_sort_controlA(WLDAP32_PLDAP,PLDAPSortKeyA*,PLDAPControlA,BOOLEAN);
-ULONG CDECL ldap_encode_sort_controlW(WLDAP32_PLDAP,PLDAPSortKeyW*,PLDAPControlW,BOOLEAN);
-PCHAR CDECL ldap_err2stringA(ULONG);
-PWCHAR CDECL ldap_err2stringW(ULONG);
-ULONG CDECL ldap_escape_filter_elementA(PCHAR,ULONG,PCHAR,ULONG);
-ULONG CDECL ldap_escape_filter_elementW(PCHAR,ULONG,PWCHAR,ULONG);
-PCHAR * CDECL ldap_explode_dnA(PCHAR,ULONG);
-PWCHAR * CDECL ldap_explode_dnW(PWCHAR,ULONG);
-ULONG CDECL ldap_extended_operationA(WLDAP32_LDAP*,PCHAR,struct WLDAP32_berval*,PLDAPControlA*,PLDAPControlA*,ULONG*);
-ULONG CDECL ldap_extended_operationW(WLDAP32_LDAP*,PWCHAR,struct WLDAP32_berval*,PLDAPControlW*,PLDAPControlW*,ULONG*);
-ULONG CDECL ldap_extended_operation_sA(WLDAP32_LDAP*,PCHAR,struct WLDAP32_berval*,PLDAPControlA*, PLDAPControlA*,
-    PCHAR*,struct WLDAP32_berval**);
-ULONG CDECL ldap_extended_operation_sW(WLDAP32_LDAP*,PWCHAR,struct WLDAP32_berval*,PLDAPControlW*, PLDAPControlW*,
-    PWCHAR*,struct WLDAP32_berval**);
-PCHAR CDECL ldap_first_attributeA(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,WLDAP32_BerElement**);
-PWCHAR CDECL ldap_first_attributeW(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,WLDAP32_BerElement**);
-WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_first_entry(WLDAP32_LDAP*,WLDAP32_LDAPMessage*);
-WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_first_reference(WLDAP32_LDAP*,WLDAP32_LDAPMessage*);
-ULONG CDECL ldap_free_controlsA(LDAPControlA**);
-ULONG CDECL ldap_free_controlsW(LDAPControlW**);
-PCHAR CDECL ldap_get_dnA(WLDAP32_LDAP*,WLDAP32_LDAPMessage*);
-PWCHAR CDECL ldap_get_dnW(WLDAP32_LDAP*,WLDAP32_LDAPMessage*);
-ULONG CDECL ldap_get_next_page(WLDAP32_LDAP*,PLDAPSearch,ULONG,ULONG*);
-ULONG CDECL ldap_get_next_page_s(WLDAP32_LDAP*,PLDAPSearch,struct l_timeval*,ULONG,ULONG*,WLDAP32_LDAPMessage**);
-ULONG CDECL ldap_get_optionA(WLDAP32_LDAP*,int,void*);
-ULONG CDECL ldap_get_optionW(WLDAP32_LDAP*,int,void*);
-ULONG CDECL ldap_get_paged_count(WLDAP32_LDAP*,PLDAPSearch,ULONG*,WLDAP32_LDAPMessage*);
-PCHAR * CDECL ldap_get_valuesA(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,PCHAR);
-PWCHAR * CDECL ldap_get_valuesW(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,PWCHAR);
-PBERVAL * CDECL ldap_get_values_lenA(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,PCHAR);
-PBERVAL * CDECL ldap_get_values_lenW(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,PWCHAR);
-WLDAP32_LDAP * CDECL ldap_initA(const PCHAR,ULONG);
-WLDAP32_LDAP * CDECL ldap_initW(const PWCHAR,ULONG);
-void CDECL ldap_memfreeA(PCHAR);
-void CDECL ldap_memfreeW(PWCHAR);
-ULONG CDECL ldap_modifyA(WLDAP32_LDAP*,PCHAR,LDAPModA*[]);
-ULONG CDECL ldap_modifyW(WLDAP32_LDAP*,PWCHAR,LDAPModW*[]);
-ULONG CDECL ldap_modify_extA(WLDAP32_LDAP*,PCHAR,LDAPModA*[],PLDAPControlA*,PLDAPControlA*,ULONG*);
-ULONG CDECL ldap_modify_extW(WLDAP32_LDAP*,PWCHAR,LDAPModW*[],PLDAPControlW*,PLDAPControlW*,ULONG*);
-ULONG CDECL ldap_modify_ext_sA(WLDAP32_LDAP*,PCHAR,LDAPModA*[],PLDAPControlA*,PLDAPControlA*);
-ULONG CDECL ldap_modify_ext_sW(WLDAP32_LDAP*,PWCHAR,LDAPModW*[],PLDAPControlW*,PLDAPControlW*);
-ULONG CDECL ldap_modify_sA(WLDAP32_LDAP*,PCHAR,LDAPModA*[]);
-ULONG CDECL ldap_modify_sW(WLDAP32_LDAP*,PWCHAR,LDAPModW*[]);
-ULONG CDECL ldap_modrdnA(WLDAP32_LDAP*,PCHAR,PCHAR);
-ULONG CDECL ldap_modrdnW(WLDAP32_LDAP*,PWCHAR,PWCHAR);
-ULONG CDECL ldap_modrdn2A(WLDAP32_LDAP*,PCHAR,PCHAR,INT);
-ULONG CDECL ldap_modrdn2W(WLDAP32_LDAP*,PWCHAR,PWCHAR,INT);
-ULONG CDECL ldap_modrdn2_sA(WLDAP32_LDAP*,PCHAR,PCHAR,INT);
-ULONG CDECL ldap_modrdn2_sW(WLDAP32_LDAP*,PWCHAR,PWCHAR,INT);
-ULONG CDECL ldap_modrdn_sA(WLDAP32_LDAP*,PCHAR,PCHAR);
-ULONG CDECL ldap_modrdn_sW(WLDAP32_LDAP*,PWCHAR,PWCHAR);
-ULONG CDECL WLDAP32_ldap_msgfree(WLDAP32_LDAPMessage*);
-PCHAR CDECL ldap_next_attributeA(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,WLDAP32_BerElement*);
-PWCHAR CDECL ldap_next_attributeW(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,WLDAP32_BerElement*);
-WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_next_entry(WLDAP32_LDAP*,WLDAP32_LDAPMessage*);
-WLDAP32_LDAPMessage * CDECL WLDAP32_ldap_next_reference(WLDAP32_LDAP*,WLDAP32_LDAPMessage*);
-WLDAP32_LDAP * CDECL ldap_openA(PCHAR,ULONG);
-WLDAP32_LDAP * CDECL ldap_openW(PWCHAR,ULONG);
-ULONG CDECL ldap_parse_extended_resultA(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,PCHAR*,struct WLDAP32_berval**,BOOLEAN);
-ULONG CDECL ldap_parse_extended_resultW(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,PWCHAR*,struct WLDAP32_berval**,BOOLEAN);
-ULONG CDECL ldap_parse_page_controlA(WLDAP32_LDAP*,PLDAPControlA*,ULONG*,struct WLDAP32_berval**);
-ULONG CDECL ldap_parse_page_controlW(WLDAP32_LDAP*,PLDAPControlW*,ULONG*,struct WLDAP32_berval**);
-ULONG CDECL ldap_parse_referenceA(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,PCHAR**);
-ULONG CDECL ldap_parse_referenceW(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,PWCHAR**);
-ULONG CDECL ldap_parse_resultA(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,ULONG*,PCHAR*,PCHAR*,PCHAR**,PLDAPControlA**,BOOLEAN);
-ULONG CDECL ldap_parse_resultW(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,ULONG*,PWCHAR*,PWCHAR*,PWCHAR**,PLDAPControlW**,BOOLEAN);
-ULONG CDECL ldap_parse_sort_controlA(WLDAP32_LDAP*,PLDAPControlA*,ULONG*,PCHAR*);
-ULONG CDECL ldap_parse_sort_controlW(WLDAP32_LDAP*,PLDAPControlW*,ULONG*,PWCHAR*);
-int CDECL ldap_parse_vlv_controlA(WLDAP32_LDAP*,LDAPControlA**,ULONG*,ULONG*,struct WLDAP32_berval**,INT*);
-int CDECL ldap_parse_vlv_controlW(WLDAP32_LDAP*,LDAPControlW**,ULONG*,ULONG*,struct WLDAP32_berval**,INT*);
-void CDECL WLDAP32_ldap_perror(WLDAP32_LDAP*,const PCHAR);
-ULONG CDECL ldap_rename_extA(WLDAP32_LDAP*,PCHAR,PCHAR,PCHAR,INT,PLDAPControlA*,PLDAPControlA*,ULONG*);
-ULONG CDECL ldap_rename_extW(WLDAP32_LDAP*,PWCHAR,PWCHAR,PWCHAR,INT,PLDAPControlW*,PLDAPControlW*,ULONG*);
-ULONG CDECL ldap_rename_ext_sA(WLDAP32_LDAP*,PCHAR,PCHAR,PCHAR,INT,PLDAPControlA*,PLDAPControlA*);
-ULONG CDECL ldap_rename_ext_sW(WLDAP32_LDAP*,PWCHAR,PWCHAR,PWCHAR,INT,PLDAPControlW*,PLDAPControlW*);
-ULONG CDECL WLDAP32_ldap_result(WLDAP32_LDAP*,ULONG,ULONG,struct l_timeval*,WLDAP32_LDAPMessage**);
-ULONG CDECL WLDAP32_ldap_result2error(WLDAP32_LDAP*,WLDAP32_LDAPMessage*,ULONG);
-ULONG CDECL ldap_sasl_bindA(WLDAP32_LDAP*,const PSTR,const PSTR,const BERVAL*,PLDAPControlA*,PLDAPControlA*,int*);
-ULONG CDECL ldap_sasl_bindW(WLDAP32_LDAP*,const PWSTR,const PWSTR,const BERVAL*,PLDAPControlW*,PLDAPControlW*,int*);
-ULONG CDECL ldap_sasl_bind_sA(WLDAP32_LDAP*,const PSTR,const PSTR,const BERVAL*,PLDAPControlA*,PLDAPControlA*,PBERVAL*);
-ULONG CDECL ldap_sasl_bind_sW(WLDAP32_LDAP*,const PWSTR,const PWSTR,const BERVAL*,PLDAPControlW*,PLDAPControlW*,PBERVAL*);
-ULONG CDECL ldap_search_abandon_page(WLDAP32_PLDAP,PLDAPSearch);
-ULONG CDECL ldap_searchA(WLDAP32_LDAP*,PCHAR,ULONG,PCHAR,PCHAR[],ULONG);
-ULONG CDECL ldap_searchW(WLDAP32_LDAP*,PWCHAR,ULONG,PWCHAR,PWCHAR[],ULONG);
-ULONG CDECL ldap_search_extA(WLDAP32_LDAP*,PCHAR,ULONG,PCHAR,PCHAR[],ULONG,PLDAPControlA*,
-    PLDAPControlA*,ULONG,ULONG,ULONG*);
-ULONG CDECL ldap_search_extW(WLDAP32_LDAP*,PWCHAR,ULONG,PWCHAR,PWCHAR[],ULONG,PLDAPControlW*,
-    PLDAPControlW*,ULONG,ULONG,ULONG*);
-ULONG CDECL ldap_search_ext_sA(WLDAP32_LDAP*,PCHAR,ULONG,PCHAR,PCHAR[],ULONG,PLDAPControlA*,
-    PLDAPControlA*,struct l_timeval*,ULONG,WLDAP32_LDAPMessage**);
-ULONG CDECL ldap_search_ext_sW(WLDAP32_LDAP*,PWCHAR,ULONG,PWCHAR,PWCHAR[],ULONG,PLDAPControlW*,
-    PLDAPControlW*,struct l_timeval*,ULONG,WLDAP32_LDAPMessage**);
-PLDAPSearch CDECL ldap_search_init_pageA(WLDAP32_PLDAP,PCHAR,ULONG,PCHAR,PCHAR[],ULONG,PLDAPControlA*,
-    PLDAPControlA*,ULONG,ULONG,PLDAPSortKeyA*);
-PLDAPSearch CDECL ldap_search_init_pageW(WLDAP32_PLDAP,PWCHAR,ULONG,PWCHAR,PWCHAR[],ULONG,PLDAPControlW*,
-    PLDAPControlW*,ULONG,ULONG, PLDAPSortKeyW*);
-ULONG CDECL ldap_search_sA(WLDAP32_LDAP*,PCHAR,ULONG,PCHAR,PCHAR[],ULONG,WLDAP32_LDAPMessage**);
-ULONG CDECL ldap_search_sW(WLDAP32_LDAP*,PWCHAR,ULONG,PWCHAR,PWCHAR[],ULONG,WLDAP32_LDAPMessage**);
-ULONG CDECL ldap_search_stA(WLDAP32_LDAP*,const PCHAR,ULONG,const PCHAR,PCHAR[],ULONG,
-    struct l_timeval*,WLDAP32_LDAPMessage**);
-ULONG CDECL ldap_search_stW(WLDAP32_LDAP*,const PWCHAR,ULONG,const PWCHAR,PWCHAR[],ULONG,
-    struct l_timeval*,WLDAP32_LDAPMessage**);
-ULONG CDECL ldap_set_optionA(WLDAP32_LDAP*,int,void*);
-ULONG CDECL ldap_set_optionW(WLDAP32_LDAP*,int,void*);
-ULONG CDECL ldap_simple_bindA(WLDAP32_LDAP*,PCHAR,PCHAR);
-ULONG CDECL ldap_simple_bindW(WLDAP32_LDAP*,PWCHAR,PWCHAR);
-ULONG CDECL ldap_simple_bind_sA(WLDAP32_LDAP*,PCHAR,PCHAR);
-ULONG CDECL ldap_simple_bind_sW(WLDAP32_LDAP*,PWCHAR,PWCHAR);
-WLDAP32_LDAP * CDECL ldap_sslinitA(PCHAR,ULONG,int);
-WLDAP32_LDAP * CDECL ldap_sslinitW(PWCHAR,ULONG,int);
-ULONG CDECL ldap_start_tls_sA(WLDAP32_PLDAP,PULONG,WLDAP32_LDAPMessage**,PLDAPControlA*,PLDAPControlA*);
-ULONG CDECL ldap_start_tls_sW(WLDAP32_PLDAP,PULONG,WLDAP32_LDAPMessage**,PLDAPControlW*,PLDAPControlW*);
-ULONG CDECL ldap_startup(PLDAP_VERSION_INFO,HANDLE*);
-BOOLEAN CDECL ldap_stop_tls_s(WLDAP32_PLDAP);
-ULONG CDECL ldap_ufn2dnA(PCHAR,PCHAR*);
-ULONG CDECL ldap_ufn2dnW(PWCHAR,PWCHAR*);
-ULONG CDECL WLDAP32_ldap_unbind(WLDAP32_LDAP*);
-ULONG CDECL WLDAP32_ldap_unbind_s(WLDAP32_LDAP*);
-ULONG CDECL ldap_value_freeA(PCHAR*);
-ULONG CDECL ldap_value_freeW(PWCHAR*);
-ULONG CDECL WLDAP32_ldap_value_free_len(struct WLDAP32_berval**);
-
-ULONG CDECL LdapGetLastError(void);
-ULONG CDECL LdapMapErrorToWin32(ULONG);
-int CDECL LdapUnicodeToUTF8(LPCWSTR,int,LPSTR,int);
-int CDECL LdapUTF8ToUnicode(LPCSTR,int,LPWSTR,int);
+    struct berval *cookie;
+} LDAPSearch;
+
+#define CTX(ld) (*(void **)ld->Reserved3)
+#define SERVER_CTRLS(ld) (*(void **)(ld->Reserved3 + sizeof(void *)))
+#define MSG(entry) (entry->Request)
+#define BER(ber) (ber->opaque)
 
 ULONG map_error( int ) DECLSPEC_HIDDEN;
 
@@ -572,9 +117,9 @@ static inline WCHAR *strnAtoW( const char *str, DWORD in_len, DWORD *out_len )
     return ret;
 }
 
-static inline DWORD bvarraylenW( struct WLDAP32_berval **bv )
+static inline DWORD bvarraylenW( struct berval **bv )
 {
-    struct WLDAP32_berval **p = bv;
+    struct berval **p = bv;
     while (*p) p++;
     return p - bv;
 }
@@ -657,8 +202,6 @@ static inline char **strarrayWtoA( WCHAR **strarray )
     return strarrayA;
 }
 
-#define WLDAP32_LDAP_MOD_BVALUES    0x80
-
 static inline DWORD modarraylenW( LDAPModW **modarray )
 {
     LDAPModW **p = modarray;
@@ -666,7 +209,7 @@ static inline DWORD modarraylenW( LDAPModW **modarray )
     return p - modarray;
 }
 
-static inline struct bervalU *bervalWtoU( const struct WLDAP32_berval *bv )
+static inline struct bervalU *bervalWtoU( const struct berval *bv )
 {
     struct bervalU *berval;
     DWORD size = sizeof(*berval) + bv->bv_len;
@@ -689,9 +232,9 @@ static inline DWORD bvarraylenU( struct bervalU **bv )
     return p - bv;
 }
 
-static inline struct WLDAP32_berval *bervalUtoW( const struct bervalU *bv )
+static inline struct berval *bervalUtoW( const struct bervalU *bv )
 {
-    struct WLDAP32_berval *berval;
+    struct berval *berval;
     DWORD size = sizeof(*berval) + bv->bv_len;
 
     assert( bv->bv_len <= ~0u );
@@ -707,9 +250,9 @@ static inline struct WLDAP32_berval *bervalUtoW( const struct bervalU *bv )
     return berval;
 }
 
-static inline struct WLDAP32_berval **bvarrayUtoW( struct bervalU **bv )
+static inline struct berval **bvarrayUtoW( struct bervalU **bv )
 {
-    struct WLDAP32_berval **berval = NULL;
+    struct berval **berval = NULL;
     DWORD size;
 
     if (bv)
@@ -718,7 +261,7 @@ static inline struct WLDAP32_berval **bvarrayUtoW( struct bervalU **bv )
         if ((berval = malloc( size )))
         {
             struct bervalU **p = bv;
-            struct WLDAP32_berval **q = berval;
+            struct berval **q = berval;
 
             while (*p) *q++ = bervalUtoW( *p++ );
             *q = NULL;
@@ -732,7 +275,7 @@ static inline void bvfreeU( struct bervalU *berval )
     free( berval );
 }
 
-static inline struct bervalU **bvarrayWtoU( struct WLDAP32_berval **bv )
+static inline struct bervalU **bvarrayWtoU( struct berval **bv )
 {
     struct bervalU **berval = NULL;
     DWORD size;
@@ -742,7 +285,7 @@ static inline struct bervalU **bvarrayWtoU( struct WLDAP32_berval **bv )
         size = sizeof(*berval) * (bvarraylenW( bv ) + 1);
         if ((berval = malloc( size )))
         {
-            struct WLDAP32_berval **p = bv;
+            struct berval **p = bv;
             struct bervalU **q = berval;
 
             while (*p) *q++ = bervalWtoU( *p++ );
@@ -761,7 +304,7 @@ static inline LDAPModU *modWtoU( const LDAPModW *mod )
         modU->mod_op = mod->mod_op;
         modU->mod_type = strWtoU( mod->mod_type );
 
-        if (mod->mod_op & WLDAP32_LDAP_MOD_BVALUES)
+        if (mod->mod_op & LDAP_MOD_BVALUES)
             modU->mod_vals.modv_bvals = bvarrayWtoU( mod->mod_vals.modv_bvals );
         else
             modU->mod_vals.modv_strvals = strarrayWtoU( mod->mod_vals.modv_strvals );
@@ -808,7 +351,7 @@ static inline void strarrayfreeU( char **strarray )
 
 static inline void modfreeU( LDAPModU *mod )
 {
-    if (mod->mod_op & WLDAP32_LDAP_MOD_BVALUES)
+    if (mod->mod_op & LDAP_MOD_BVALUES)
         bvarrayfreeU( mod->mod_vals.modv_bvals );
     else
         strarrayfreeU( mod->mod_vals.modv_strvals );
@@ -832,9 +375,9 @@ static inline DWORD modarraylenA( LDAPModA **modarray )
     return p - modarray;
 }
 
-static inline struct WLDAP32_berval *bervalWtoW( const struct WLDAP32_berval *bv )
+static inline struct berval *bervalWtoW( const struct berval *bv )
 {
-    struct WLDAP32_berval *berval;
+    struct berval *berval;
     DWORD size = sizeof(*berval) + bv->bv_len;
 
     if ((berval = malloc( size )))
@@ -848,9 +391,9 @@ static inline struct WLDAP32_berval *bervalWtoW( const struct WLDAP32_berval *bv
     return berval;
 }
 
-static inline struct WLDAP32_berval **bvarrayWtoW( struct WLDAP32_berval **bv )
+static inline struct berval **bvarrayWtoW( struct berval **bv )
 {
-    struct WLDAP32_berval **berval = NULL;
+    struct berval **berval = NULL;
     DWORD size;
 
     if (bv)
@@ -858,8 +401,8 @@ static inline struct WLDAP32_berval **bvarrayWtoW( struct WLDAP32_berval **bv )
         size = sizeof(*berval) * (bvarraylenW( bv ) + 1);
         if ((berval = malloc( size )))
         {
-            struct WLDAP32_berval **p = bv;
-            struct WLDAP32_berval **q = berval;
+            struct berval **p = bv;
+            struct berval **q = berval;
 
             while (*p) *q++ = bervalWtoW( *p++ );
             *q = NULL;
@@ -904,7 +447,7 @@ static inline LDAPModW *modAtoW( const LDAPModA *mod )
         modW->mod_op = mod->mod_op;
         modW->mod_type = strAtoW( mod->mod_type );
 
-        if (mod->mod_op & WLDAP32_LDAP_MOD_BVALUES)
+        if (mod->mod_op & LDAP_MOD_BVALUES)
             modW->mod_vals.modv_bvals = bvarrayWtoW( mod->mod_vals.modv_bvals );
         else
             modW->mod_vals.modv_strvals = strarrayAtoW( mod->mod_vals.modv_strvals );
@@ -932,9 +475,9 @@ static inline LDAPModW **modarrayAtoW( LDAPModA **modarray )
     return modarrayW;
 }
 
-static inline void bvarrayfreeW( struct WLDAP32_berval **bv )
+static inline void bvarrayfreeW( struct berval **bv )
 {
-    struct WLDAP32_berval **p = bv;
+    struct berval **p = bv;
     while (*p) free( *p++ );
     free( bv );
 }
@@ -951,7 +494,7 @@ static inline void strarrayfreeW( WCHAR **strarray )
 
 static inline void modfreeW( LDAPModW *mod )
 {
-    if (mod->mod_op & WLDAP32_LDAP_MOD_BVALUES)
+    if (mod->mod_op & LDAP_MOD_BVALUES)
         bvarrayfreeW( mod->mod_vals.modv_bvals );
     else
         strarrayfreeW( mod->mod_vals.modv_strvals );
@@ -1467,7 +1010,7 @@ static inline void sortkeyarrayfreeU( LDAPSortKeyU **sortkeyarray )
     }
 }
 
-static inline LDAPVLVInfoU *vlvinfoWtoU( const WLDAP32_LDAPVLVInfo *info )
+static inline LDAPVLVInfoU *vlvinfoWtoU( const LDAPVLVInfo *info )
 {
     LDAPVLVInfoU *infoU;
 
diff --git a/dlls/wldap32/wldap32.spec b/dlls/wldap32/wldap32.spec
index 8a8e29fc198..63271615eb8 100644
--- a/dlls/wldap32/wldap32.spec
+++ b/dlls/wldap32/wldap32.spec
@@ -1,20 +1,20 @@
- 10 cdecl ldap_abandon(ptr long) WLDAP32_ldap_abandon
+ 10 cdecl ldap_abandon(ptr long)
  11 cdecl ldap_add(ptr str ptr) ldap_addA
  12 cdecl ldap_get_optionW(ptr long ptr)
- 13 cdecl ldap_unbind(ptr) WLDAP32_ldap_unbind
+ 13 cdecl ldap_unbind(ptr)
  14 cdecl ldap_set_optionW(ptr long ptr)
  16 cdecl LdapGetLastError()
  17 cdecl cldap_open(str long) cldap_openA
  18 cdecl LdapMapErrorToWin32(long)
  19 cdecl ldap_compare(ptr str str str) ldap_compareA
  20 cdecl ldap_delete(ptr str) ldap_deleteA
- 21 cdecl ldap_result2error(ptr ptr long) WLDAP32_ldap_result2error
+ 21 cdecl ldap_result2error(ptr ptr long)
  22 cdecl ldap_err2string(long) ldap_err2stringA
  23 cdecl ldap_modify(ptr str ptr) ldap_modifyA
  24 cdecl ldap_modrdn(ptr str ptr) ldap_modrdnA
  25 cdecl ldap_open(str long) ldap_openA
- 26 cdecl ldap_first_entry(ptr ptr) WLDAP32_ldap_first_entry
- 27 cdecl ldap_next_entry(ptr ptr) WLDAP32_ldap_next_entry
+ 26 cdecl ldap_first_entry(ptr ptr)
+ 27 cdecl ldap_next_entry(ptr ptr)
  28 cdecl cldap_openW(wstr long)
  29 cdecl LdapUTF8ToUnicode(str long ptr long)
  30 cdecl ldap_get_dn(ptr ptr) ldap_get_dnA
@@ -23,17 +23,17 @@
  33 cdecl ldap_next_attribute(ptr ptr ptr) ldap_next_attributeA
  34 cdecl ldap_get_values(ptr ptr str) ldap_get_valuesA
  35 cdecl ldap_get_values_len(ptr ptr str) ldap_get_values_lenA
- 36 cdecl ldap_count_entries(ptr ptr) WLDAP32_ldap_count_entries
+ 36 cdecl ldap_count_entries(ptr ptr)
  37 cdecl ldap_count_values(ptr) ldap_count_valuesA
  38 cdecl ldap_value_free(ptr) ldap_value_freeA
  39 cdecl ldap_explode_dn(str long) ldap_explode_dnA
- 40 cdecl ldap_result(ptr long long ptr ptr) WLDAP32_ldap_result
- 41 cdecl ldap_msgfree(ptr) WLDAP32_ldap_msgfree
+ 40 cdecl ldap_result(ptr long long ptr ptr)
+ 41 cdecl ldap_msgfree(ptr)
  42 cdecl ldap_addW(ptr wstr ptr)
  43 cdecl ldap_search(ptr str long str ptr long) ldap_searchA
  44 cdecl ldap_add_s(ptr str ptr) ldap_add_sA
  45 cdecl ldap_bind_s(ptr str str long) ldap_bind_sA
- 46 cdecl ldap_unbind_s(ptr) WLDAP32_ldap_unbind_s
+ 46 cdecl ldap_unbind_s(ptr)
  47 cdecl ldap_delete_s(ptr str) ldap_delete_sA
  48 cdecl ldap_modify_s(ptr str ptr) ldap_modify_sA
  49 cdecl ldap_modrdn_s(ptr str ptr) ldap_modrdn_sA
@@ -41,7 +41,7 @@
  51 cdecl ldap_search_st(ptr str long str ptr long ptr ptr) ldap_search_stA
  52 cdecl ldap_compare_s(ptr str str str) ldap_compare_sA
  53 cdecl LdapUnicodeToUTF8(wstr long ptr long)
- 54 cdecl ber_bvfree(ptr) WLDAP32_ber_bvfree
+ 54 cdecl ber_bvfree(ptr)
  55 cdecl cldap_openA(str long)
  56 cdecl ldap_addA(ptr str ptr)
  57 cdecl ldap_add_ext(ptr str ptr ptr ptr ptr) ldap_add_extA
@@ -64,12 +64,12 @@
  74 cdecl ldap_close_extended_op(ptr long)
  75 cdecl ldap_compareA(ptr str str str)
  76 cdecl ldap_compareW(ptr wstr wstr wstr)
- 77 cdecl ldap_count_values_len(ptr) WLDAP32_ldap_count_values_len
+ 77 cdecl ldap_count_values_len(ptr)
  78 cdecl ldap_compare_ext(ptr str str str ptr ptr ptr ptr) ldap_compare_extA
- 79 cdecl ldap_value_free_len(ptr) WLDAP32_ldap_value_free_len
+ 79 cdecl ldap_value_free_len(ptr)
  80 cdecl ldap_compare_extA(ptr str str str ptr ptr ptr ptr)
  81 cdecl ldap_compare_extW(ptr wstr wstr wstr ptr ptr ptr ptr)
- 82 cdecl ldap_perror(ptr ptr) WLDAP32_ldap_perror
+ 82 cdecl ldap_perror(ptr ptr)
  83 cdecl ldap_compare_ext_s(ptr str str str ptr ptr ptr) ldap_compare_ext_sA
  84 cdecl ldap_compare_ext_sA(ptr str str str ptr ptr ptr)
  85 cdecl ldap_compare_ext_sW(ptr wstr wstr wstr ptr ptr ptr)
@@ -82,7 +82,7 @@
  92 cdecl ldap_controls_free(ptr) ldap_controls_freeA
  93 cdecl ldap_controls_freeA(ptr)
  94 cdecl ldap_controls_freeW(ptr)
- 95 cdecl ldap_count_references(ptr ptr) WLDAP32_ldap_count_references
+ 95 cdecl ldap_count_references(ptr ptr)
  96 cdecl ldap_count_valuesA(ptr)
  97 cdecl ldap_count_valuesW(ptr)
  98 cdecl ldap_create_page_control(ptr long ptr long ptr) ldap_create_page_controlA
@@ -115,7 +115,7 @@
 125 cdecl ldap_extended_operationW(ptr wstr ptr ptr ptr ptr)
 126 cdecl ldap_first_attributeA(ptr ptr ptr)
 127 cdecl ldap_first_attributeW(ptr ptr ptr)
-128 cdecl ldap_first_reference(ptr ptr) WLDAP32_ldap_first_reference
+128 cdecl ldap_first_reference(ptr ptr)
 129 cdecl ldap_free_controls(ptr) ldap_free_controlsA
 130 cdecl ldap_free_controlsA(ptr)
 131 cdecl ldap_free_controlsW(ptr)
@@ -155,7 +155,7 @@
 165 cdecl ldap_modrdn_sW(ptr wstr ptr)
 166 cdecl ldap_next_attributeA(ptr ptr ptr)
 167 cdecl ldap_next_attributeW(ptr ptr ptr)
-168 cdecl ldap_next_reference(ptr ptr) WLDAP32_ldap_next_reference
+168 cdecl ldap_next_reference(ptr ptr)
 169 cdecl ldap_openA(str long)
 170 cdecl ldap_openW(wstr long)
 171 cdecl ldap_parse_page_control(ptr ptr ptr ptr) ldap_parse_page_controlA
@@ -215,18 +215,18 @@
 230 cdecl ldap_check_filterA(ptr str)
 231 cdecl ldap_check_filterW(ptr wstr)
 232 cdecl ldap_dn2ufnA(str)
-300 cdecl ber_init(ptr) WLDAP32_ber_init
-301 cdecl ber_free(ptr long) WLDAP32_ber_free
-302 cdecl ber_bvecfree(ptr) WLDAP32_ber_bvecfree
-303 cdecl ber_bvdup(ptr) WLDAP32_ber_bvdup
-304 cdecl ber_alloc_t(long) WLDAP32_ber_alloc_t
-305 cdecl ber_skip_tag(ptr ptr) WLDAP32_ber_skip_tag
-306 cdecl ber_peek_tag(ptr ptr) WLDAP32_ber_peek_tag
-307 cdecl ber_first_element(ptr ptr ptr) WLDAP32_ber_first_element
-308 cdecl ber_next_element(ptr ptr ptr) WLDAP32_ber_next_element
-309 cdecl ber_flatten(ptr ptr) WLDAP32_ber_flatten
-310 varargs ber_printf(ptr str) WLDAP32_ber_printf
-311 varargs ber_scanf(ptr str) WLDAP32_ber_scanf
+300 cdecl ber_init(ptr)
+301 cdecl ber_free(ptr long)
+302 cdecl ber_bvecfree(ptr)
+303 cdecl ber_bvdup(ptr)
+304 cdecl ber_alloc_t(long)
+305 cdecl ber_skip_tag(ptr ptr)
+306 cdecl ber_peek_tag(ptr ptr)
+307 cdecl ber_first_element(ptr ptr ptr)
+308 cdecl ber_next_element(ptr ptr ptr)
+309 cdecl ber_flatten(ptr ptr)
+310 varargs ber_printf(ptr str)
+311 varargs ber_scanf(ptr str)
 312 cdecl ldap_conn_from_msg(ptr ptr)
 313 cdecl ldap_sasl_bindW(ptr wstr wstr ptr ptr ptr ptr)
 314 cdecl ldap_sasl_bind_sW(ptr wstr wstr ptr ptr ptr ptr)
diff --git a/include/winber.h b/include/winber.h
index 372cc321269..65d9d50c789 100644
--- a/include/winber.h
+++ b/include/winber.h
@@ -34,7 +34,7 @@ ULONG CDECL ber_first_element( BerElement *, ULONG *, char ** );
 int CDECL ber_flatten( BerElement *, BERVAL ** );
 void CDECL ber_free( BerElement *, int );
 BerElement * CDECL ber_init( BERVAL * );
-ULONG CDECL ber_next_element( BerElement *, ULONG *, char ** );
+ULONG CDECL ber_next_element( BerElement *, ULONG *, char * );
 ULONG CDECL ber_peek_tag( BerElement *, ULONG * );
 int WINAPIV ber_printf( BerElement *, char *, ... );
 ULONG WINAPIV ber_scanf( BerElement *, char *, ... );
diff --git a/include/winldap.h b/include/winldap.h
index 2cc29ef693c..5e744b25baf 100644
--- a/include/winldap.h
+++ b/include/winldap.h
@@ -293,6 +293,14 @@ typedef struct berval
     PCHAR bv_val;
 } LDAP_BERVAL, *PLDAP_BERVAL, BERVAL, *PBERVAL, BerValue;
 
+#define LDAP_PAGED_RESULT_OID_STRING "1.2.840.113556.1.4.319"
+#define LDAP_SERVER_RESP_SORT_OID "1.2.840.113556.1.4.474"
+#define LDAP_CONTROL_VLVRESPONSE "2.16.840.1.113730.3.4.10"
+
+#define LDAP_PAGED_RESULT_OID_STRING_W L"1.2.840.113556.1.4.319"
+#define LDAP_SERVER_RESP_SORT_OID_W L"1.2.840.113556.1.4.474"
+#define LDAP_CONTROL_VLVRESPONSE_W L"2.16.840.1.113730.3.4.10"
+
 typedef struct ldapcontrolA
 {
     PCHAR ldctl_oid;
@@ -586,7 +594,7 @@ ULONG CDECL ldap_simple_bind_sW(LDAP*,PWCHAR,PWCHAR);
 #define    ldap_simple_bind_s WINELIB_NAME_AW(ldap_simple_bind_s)
 ULONG CDECL ldap_search_abandon_page(PLDAP,PLDAPSearch);
 ULONG CDECL ldap_searchA(LDAP*,PCHAR,ULONG,PCHAR,PCHAR[],ULONG);
-ULONG CDECL ldap_searchW(LDAP*,PWCHAR,ULONG,PWCHAR,PCHAR[],ULONG);
+ULONG CDECL ldap_searchW(LDAP*,PWCHAR,ULONG,PWCHAR,PWCHAR[],ULONG);
 #define    ldap_search WINELIB_NAME_AW(ldap_search)
 ULONG CDECL ldap_search_extA(LDAP*,PCHAR,ULONG,PCHAR,PCHAR[],ULONG,PLDAPControlA*,
     PLDAPControlA*,ULONG,ULONG,ULONG*);
-- 
2.30.2




More information about the wine-devel mailing list