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

ldap_bind_sA

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

シグネチャ

// WLDAP32.dll  (ANSI / -A)
#include <windows.h>

DWORD ldap_bind_sA(
    LDAP* ld,
    LPSTR dn,   // optional
    LPSTR cred,   // optional
    DWORD method
);

パラメーター

名前方向
ldLDAP*inout
dnLPSTRinoptional
credLPSTRinoptional
methodDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

// WLDAP32.dll  (ANSI / -A)
#include <windows.h>

DWORD ldap_bind_sA(
    LDAP* ld,
    LPSTR dn,   // optional
    LPSTR cred,   // optional
    DWORD method
);
[DllImport("WLDAP32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_bind_sA(
    IntPtr ld,   // LDAP* in/out
    [MarshalAs(UnmanagedType.LPStr)] string dn,   // LPSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string cred,   // LPSTR optional
    uint method   // DWORD
);
<DllImport("WLDAP32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_bind_sA(
    ld As IntPtr,   ' LDAP* in/out
    <MarshalAs(UnmanagedType.LPStr)> dn As String,   ' LPSTR optional
    <MarshalAs(UnmanagedType.LPStr)> cred As String,   ' LPSTR optional
    method As UInteger   ' DWORD
) As UInteger
End Function
' ld : LDAP* in/out
' dn : LPSTR optional
' cred : LPSTR optional
' method : DWORD
Declare PtrSafe Function ldap_bind_sA Lib "wldap32" ( _
    ByVal ld As LongPtr, _
    ByVal dn As String, _
    ByVal cred As String, _
    ByVal method As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
	procldap_bind_sA = wldap32.NewProc("ldap_bind_sA")
)

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