Win32 API 日本語リファレンス
ホームNetworking.Ldap › ldap_bindW

ldap_bindW

関数
指定方式でLDAPサーバーに非同期バインドする(Unicode版)。
DLLWLDAP32.dll文字セットUnicode (-W)呼出規約cdecl対応OSWindows Vista 以降

シグネチャ

// WLDAP32.dll  (Unicode / -W)
#include <windows.h>

DWORD ldap_bindW(
    LDAP* ld,
    LPWSTR dn,   // optional
    LPWSTR cred,   // optional
    DWORD method
);

パラメーター

名前方向
ldLDAP*inout
dnLPWSTRinoptional
credLPWSTRinoptional
methodDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

// WLDAP32.dll  (Unicode / -W)
#include <windows.h>

DWORD ldap_bindW(
    LDAP* ld,
    LPWSTR dn,   // optional
    LPWSTR cred,   // optional
    DWORD method
);
[DllImport("WLDAP32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_bindW(
    IntPtr ld,   // LDAP* in/out
    [MarshalAs(UnmanagedType.LPWStr)] string dn,   // LPWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string cred,   // LPWSTR optional
    uint method   // DWORD
);
<DllImport("WLDAP32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_bindW(
    ld As IntPtr,   ' LDAP* in/out
    <MarshalAs(UnmanagedType.LPWStr)> dn As String,   ' LPWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> cred As String,   ' LPWSTR optional
    method As UInteger   ' DWORD
) As UInteger
End Function
' ld : LDAP* in/out
' dn : LPWSTR optional
' cred : LPWSTR optional
' method : DWORD
Declare PtrSafe Function ldap_bindW Lib "wldap32" ( _
    ByVal ld As LongPtr, _
    ByVal dn As LongPtr, _
    ByVal cred As LongPtr, _
    ByVal method As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ldap_bindW = ctypes.cdll.wldap32.ldap_bindW
ldap_bindW.restype = wintypes.DWORD
ldap_bindW.argtypes = [
    ctypes.c_void_p,  # ld : LDAP* in/out
    wintypes.LPCWSTR,  # dn : LPWSTR optional
    wintypes.LPCWSTR,  # cred : LPWSTR optional
    wintypes.DWORD,  # method : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WLDAP32.dll')
ldap_bindW = Fiddle::Function.new(
  lib['ldap_bindW'],
  [
    Fiddle::TYPE_VOIDP,  # ld : LDAP* in/out
    Fiddle::TYPE_VOIDP,  # dn : LPWSTR optional
    Fiddle::TYPE_VOIDP,  # cred : LPWSTR optional
    -Fiddle::TYPE_INT,  # method : DWORD
  ],
  -Fiddle::TYPE_INT, Fiddle::Function::CDECL)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wldap32")]
extern "C" {
    fn ldap_bindW(
        ld: *mut LDAP,  // LDAP* in/out
        dn: *mut u16,  // LPWSTR optional
        cred: *mut u16,  // LPWSTR optional
        method: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WLDAP32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern uint ldap_bindW(IntPtr ld, [MarshalAs(UnmanagedType.LPWStr)] string dn, [MarshalAs(UnmanagedType.LPWStr)] string cred, uint method);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_ldap_bindW' -Namespace Win32 -PassThru
# $api::ldap_bindW(ld, dn, cred, method)
#uselib "WLDAP32.dll"
#func global ldap_bindW "ldap_bindW" wptr, wptr, wptr, wptr
; ldap_bindW varptr(ld), dn, cred, method   ; 戻り値は stat
; ld : LDAP* in/out -> "wptr"
; dn : LPWSTR optional -> "wptr"
; cred : LPWSTR optional -> "wptr"
; method : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WLDAP32.dll"
#cfunc global ldap_bindW "ldap_bindW" var, wstr, wstr, int
; res = ldap_bindW(ld, dn, cred, method)
; ld : LDAP* in/out -> "var"
; dn : LPWSTR optional -> "wstr"
; cred : LPWSTR optional -> "wstr"
; method : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD ldap_bindW(LDAP* ld, LPWSTR dn, LPWSTR cred, DWORD method)
#uselib "WLDAP32.dll"
#cfunc global ldap_bindW "ldap_bindW" var, wstr, wstr, int
; res = ldap_bindW(ld, dn, cred, method)
; ld : LDAP* in/out -> "var"
; dn : LPWSTR optional -> "wstr"
; cred : LPWSTR optional -> "wstr"
; method : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
	procldap_bindW = wldap32.NewProc("ldap_bindW")
)

// ld (LDAP* in/out), dn (LPWSTR optional), cred (LPWSTR optional), method (DWORD)
r1, _, err := procldap_bindW.Call(
	uintptr(ld),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(dn))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(cred))),
	uintptr(method),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function ldap_bindW(
  ld: Pointer;   // LDAP* in/out
  dn: PWideChar;   // LPWSTR optional
  cred: PWideChar;   // LPWSTR optional
  method: DWORD   // DWORD
): DWORD; cdecl;
  external 'WLDAP32.dll' name 'ldap_bindW';
result := DllCall("WLDAP32\ldap_bindW"
    , "Ptr", ld   ; LDAP* in/out
    , "WStr", dn   ; LPWSTR optional
    , "WStr", cred   ; LPWSTR optional
    , "UInt", method   ; DWORD
    , "Cdecl UInt")   ; return: DWORD
●ldap_bindW(ld, dn, cred, method) = DLL("WLDAP32.dll", "dword ldap_bindW(void*, char*, char*, dword)")
# 呼び出し: ldap_bindW(ld, dn, cred, method)
# ld : LDAP* in/out -> "void*"
# dn : LPWSTR optional -> "char*"
# cred : LPWSTR optional -> "char*"
# method : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。