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

ldap_simple_bind_sW

関数
DNとパスワードで同期的に簡易バインドする(Unicode版)。
DLLWLDAP32.dll文字セットUnicode (-W)呼出規約cdecl対応OSWindows Vista 以降

シグネチャ

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

DWORD ldap_simple_bind_sW(
    LDAP* ld,
    LPWSTR dn,   // optional
    LPWSTR passwd   // optional
);

パラメーター

名前方向説明
ldLDAP*inoutバインドを行う対象のLDAPセッションハンドル。
dnLPWSTRinoptional認証に使う識別名(DN、Unicode)。匿名バインドの場合はNULLを指定する。
passwdLPWSTRinoptional認証パスワード(Unicode)。同期的にバインドが完了するまで待機する。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD ldap_simple_bind_sW(
    LDAP* ld,
    LPWSTR dn,   // optional
    LPWSTR passwd   // optional
);
[DllImport("WLDAP32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_simple_bind_sW(
    IntPtr ld,   // LDAP* in/out
    [MarshalAs(UnmanagedType.LPWStr)] string dn,   // LPWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string passwd   // LPWSTR optional
);
<DllImport("WLDAP32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_simple_bind_sW(
    ld As IntPtr,   ' LDAP* in/out
    <MarshalAs(UnmanagedType.LPWStr)> dn As String,   ' LPWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> passwd As String   ' LPWSTR optional
) As UInteger
End Function
' ld : LDAP* in/out
' dn : LPWSTR optional
' passwd : LPWSTR optional
Declare PtrSafe Function ldap_simple_bind_sW Lib "wldap32" ( _
    ByVal ld As LongPtr, _
    ByVal dn As LongPtr, _
    ByVal passwd As LongPtr) 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_simple_bind_sW = ctypes.cdll.wldap32.ldap_simple_bind_sW
ldap_simple_bind_sW.restype = wintypes.DWORD
ldap_simple_bind_sW.argtypes = [
    ctypes.c_void_p,  # ld : LDAP* in/out
    wintypes.LPCWSTR,  # dn : LPWSTR optional
    wintypes.LPCWSTR,  # passwd : LPWSTR optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
	procldap_simple_bind_sW = wldap32.NewProc("ldap_simple_bind_sW")
)

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

extern "wldap32" fn ldap_simple_bind_sW(
    ld: [*c]LDAP, // LDAP* in/out
    dn: [*c]const u16, // LPWSTR optional
    passwd: [*c]const u16 // LPWSTR optional
) callconv(.c) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc ldap_simple_bind_sW(
    ld: ptr LDAP,  # LDAP* in/out
    dn: WideCString,  # LPWSTR optional
    passwd: WideCString  # LPWSTR optional
): uint32 {.importc: "ldap_simple_bind_sW", cdecl, dynlib: "WLDAP32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "wldap32");
extern(C)
uint ldap_simple_bind_sW(
    LDAP* ld,   // LDAP* in/out
    const(wchar)* dn,   // LPWSTR optional
    const(wchar)* passwd   // LPWSTR optional
);
ccall((:ldap_simple_bind_sW, "WLDAP32.dll"), UInt32,
      (Ptr{LDAP}, Cwstring, Cwstring),
      ld, dn, passwd)
# ld : LDAP* in/out -> Ptr{LDAP}
# dn : LPWSTR optional -> Cwstring
# passwd : LPWSTR optional -> Cwstring
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t ldap_simple_bind_sW(
    void* ld,
    const uint16_t* dn,
    const uint16_t* passwd);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ldap_simple_bind_sW(ld, dn, passwd)
-- ld : LDAP* in/out
-- dn : LPWSTR optional
-- passwd : LPWSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('WLDAP32.dll');
const ldap_simple_bind_sW = lib.func('__cdecl', 'ldap_simple_bind_sW', 'uint32_t', ['void *', 'str16', 'str16']);
// ldap_simple_bind_sW(ld, dn, passwd)
// ld : LDAP* in/out -> 'void *'
// dn : LPWSTR optional -> 'str16'
// passwd : LPWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WLDAP32.dll", {
  ldap_simple_bind_sW: { parameters: ["pointer", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.ldap_simple_bind_sW(ld, dn, passwd)
// ld : LDAP* in/out -> "pointer"
// dn : LPWSTR optional -> "buffer"
// passwd : LPWSTR optional -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t ldap_simple_bind_sW(
    void* ld,
    const uint16_t* dn,
    const uint16_t* passwd);
C, "WLDAP32.dll");
// $ffi->ldap_simple_bind_sW(ld, dn, passwd);
// ld : LDAP* in/out
// dn : LPWSTR optional
// passwd : LPWSTR optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Wldap32 extends Library {
    Wldap32 INSTANCE = Native.load("wldap32", Wldap32.class, W32APIOptions.UNICODE_OPTIONS);
    int ldap_simple_bind_sW(
        Pointer ld,   // LDAP* in/out
        WString dn,   // LPWSTR optional
        WString passwd   // LPWSTR optional
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("wldap32")]
lib LibWLDAP32
  fun ldap_simple_bind_sW = ldap_simple_bind_sW(
    ld : LDAP*,   # LDAP* in/out
    dn : UInt16*,   # LPWSTR optional
    passwd : UInt16*   # LPWSTR optional
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ldap_simple_bind_sWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>);
typedef ldap_simple_bind_sWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>);
final ldap_simple_bind_sW = DynamicLibrary.open('WLDAP32.dll')
    .lookupFunction<ldap_simple_bind_sWNative, ldap_simple_bind_sWDart>('ldap_simple_bind_sW');
// ld : LDAP* in/out -> Pointer<Void>
// dn : LPWSTR optional -> Pointer<Utf16>
// passwd : LPWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ldap_simple_bind_sW(
  ld: Pointer;   // LDAP* in/out
  dn: PWideChar;   // LPWSTR optional
  passwd: PWideChar   // LPWSTR optional
): DWORD; cdecl;
  external 'WLDAP32.dll' name 'ldap_simple_bind_sW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "ldap_simple_bind_sW"
  c_ldap_simple_bind_sW :: Ptr () -> CWString -> CWString -> IO Word32
-- ld : LDAP* in/out -> Ptr ()
-- dn : LPWSTR optional -> CWString
-- passwd : LPWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ldap_simple_bind_sw =
  foreign "ldap_simple_bind_sW"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* ld : LDAP* in/out -> (ptr void) *)
(* dn : LPWSTR optional -> (ptr uint16_t) *)
(* passwd : LPWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wldap32 (t "WLDAP32.dll"))
(cffi:use-foreign-library wldap32)

(cffi:defcfun ("ldap_simple_bind_sW" ldap-simple-bind-s-w :convention :cdecl) :uint32
  (ld :pointer)   ; LDAP* in/out
  (dn (:string :encoding :utf-16le))   ; LPWSTR optional
  (passwd (:string :encoding :utf-16le)))   ; LPWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ldap_simple_bind_sW = Win32::API::More->new('WLDAP32',
    'DWORD ldap_simple_bind_sW(LPVOID ld, LPCWSTR dn, LPCWSTR passwd)');
# my $ret = $ldap_simple_bind_sW->Call($ld, $dn, $passwd);
# ld : LDAP* in/out -> LPVOID
# dn : LPWSTR optional -> LPCWSTR
# passwd : LPWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型