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

ldap_search_extW

関数
制御付きで非同期にLDAP拡張検索する(Unicode版)。
DLLWLDAP32.dll文字セットUnicode (-W)呼出規約cdecl対応OSWindows Vista 以降

シグネチャ

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

DWORD ldap_search_extW(
    LDAP* ld,
    LPCWSTR base,   // optional
    DWORD scope,
    LPCWSTR filter,
    WORD** attrs,
    DWORD attrsonly,
    LDAPControlW** ServerControls,   // optional
    LDAPControlW** ClientControls,   // optional
    DWORD TimeLimit,
    DWORD SizeLimit,
    DWORD* MessageNumber
);

パラメーター

名前方向説明
ldLDAP*inout検索を実行する対象のLDAPセッションハンドル。
baseLPCWSTRinoptional検索の起点となるベースDN(Unicode)。この識別名を基準に探索する。
scopeDWORDin検索範囲を示すフラグ。LDAP_SCOPE_BASE/ONELEVEL/SUBTREEのいずれかを指定する。
filterLPCWSTRin検索フィルター文字列(Unicode)。RFC形式の検索条件を指定する。
attrsWORD**in取得する属性名のNULL終端配列。NULLで全属性を返す。
attrsonlyDWORDin属性名のみ取得するかのフラグ。非0で値を除き属性名だけを返す。
ServerControlsLDAPControlW**inoptionalサーバー側コントロールの配列(LDAPControlW*の配列)。不要ならNULL。
ClientControlsLDAPControlW**inoptionalクライアント側コントロールの配列(LDAPControlW*の配列)。不要ならNULL。
TimeLimitDWORDin検索の制限時間(秒)。0で無制限を意味する。
SizeLimitDWORDin返すエントリ数の上限。0で無制限を意味する。
MessageNumberDWORD*inout発行した非同期要求のメッセージIDを受け取るDWORD変数へのポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD ldap_search_extW(
    LDAP* ld,
    LPCWSTR base,   // optional
    DWORD scope,
    LPCWSTR filter,
    WORD** attrs,
    DWORD attrsonly,
    LDAPControlW** ServerControls,   // optional
    LDAPControlW** ClientControls,   // optional
    DWORD TimeLimit,
    DWORD SizeLimit,
    DWORD* MessageNumber
);
[DllImport("WLDAP32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_search_extW(
    IntPtr ld,   // LDAP* in/out
    [MarshalAs(UnmanagedType.LPWStr)] string base,   // LPCWSTR optional
    uint scope,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string filter,   // LPCWSTR
    IntPtr attrs,   // WORD**
    uint attrsonly,   // DWORD
    IntPtr ServerControls,   // LDAPControlW** optional
    IntPtr ClientControls,   // LDAPControlW** optional
    uint TimeLimit,   // DWORD
    uint SizeLimit,   // DWORD
    ref uint MessageNumber   // DWORD* in/out
);
<DllImport("WLDAP32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_search_extW(
    ld As IntPtr,   ' LDAP* in/out
    <MarshalAs(UnmanagedType.LPWStr)> base As String,   ' LPCWSTR optional
    scope As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> filter As String,   ' LPCWSTR
    attrs As IntPtr,   ' WORD**
    attrsonly As UInteger,   ' DWORD
    ServerControls As IntPtr,   ' LDAPControlW** optional
    ClientControls As IntPtr,   ' LDAPControlW** optional
    TimeLimit As UInteger,   ' DWORD
    SizeLimit As UInteger,   ' DWORD
    ByRef MessageNumber As UInteger   ' DWORD* in/out
) As UInteger
End Function
' ld : LDAP* in/out
' base : LPCWSTR optional
' scope : DWORD
' filter : LPCWSTR
' attrs : WORD**
' attrsonly : DWORD
' ServerControls : LDAPControlW** optional
' ClientControls : LDAPControlW** optional
' TimeLimit : DWORD
' SizeLimit : DWORD
' MessageNumber : DWORD* in/out
Declare PtrSafe Function ldap_search_extW Lib "wldap32" ( _
    ByVal ld As LongPtr, _
    ByVal base As LongPtr, _
    ByVal scope As Long, _
    ByVal filter As LongPtr, _
    ByVal attrs As LongPtr, _
    ByVal attrsonly As Long, _
    ByVal ServerControls As LongPtr, _
    ByVal ClientControls As LongPtr, _
    ByVal TimeLimit As Long, _
    ByVal SizeLimit As Long, _
    ByRef MessageNumber 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_search_extW = ctypes.cdll.wldap32.ldap_search_extW
ldap_search_extW.restype = wintypes.DWORD
ldap_search_extW.argtypes = [
    ctypes.c_void_p,  # ld : LDAP* in/out
    wintypes.LPCWSTR,  # base : LPCWSTR optional
    wintypes.DWORD,  # scope : DWORD
    wintypes.LPCWSTR,  # filter : LPCWSTR
    ctypes.c_void_p,  # attrs : WORD**
    wintypes.DWORD,  # attrsonly : DWORD
    ctypes.c_void_p,  # ServerControls : LDAPControlW** optional
    ctypes.c_void_p,  # ClientControls : LDAPControlW** optional
    wintypes.DWORD,  # TimeLimit : DWORD
    wintypes.DWORD,  # SizeLimit : DWORD
    ctypes.POINTER(wintypes.DWORD),  # MessageNumber : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
	procldap_search_extW = wldap32.NewProc("ldap_search_extW")
)

// ld (LDAP* in/out), base (LPCWSTR optional), scope (DWORD), filter (LPCWSTR), attrs (WORD**), attrsonly (DWORD), ServerControls (LDAPControlW** optional), ClientControls (LDAPControlW** optional), TimeLimit (DWORD), SizeLimit (DWORD), MessageNumber (DWORD* in/out)
r1, _, err := procldap_search_extW.Call(
	uintptr(ld),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(base))),
	uintptr(scope),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(filter))),
	uintptr(attrs),
	uintptr(attrsonly),
	uintptr(ServerControls),
	uintptr(ClientControls),
	uintptr(TimeLimit),
	uintptr(SizeLimit),
	uintptr(MessageNumber),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function ldap_search_extW(
  ld: Pointer;   // LDAP* in/out
  base: PWideChar;   // LPCWSTR optional
  scope: DWORD;   // DWORD
  filter: PWideChar;   // LPCWSTR
  attrs: Pointer;   // WORD**
  attrsonly: DWORD;   // DWORD
  ServerControls: Pointer;   // LDAPControlW** optional
  ClientControls: Pointer;   // LDAPControlW** optional
  TimeLimit: DWORD;   // DWORD
  SizeLimit: DWORD;   // DWORD
  MessageNumber: Pointer   // DWORD* in/out
): DWORD; cdecl;
  external 'WLDAP32.dll' name 'ldap_search_extW';
result := DllCall("WLDAP32\ldap_search_extW"
    , "Ptr", ld   ; LDAP* in/out
    , "WStr", base   ; LPCWSTR optional
    , "UInt", scope   ; DWORD
    , "WStr", filter   ; LPCWSTR
    , "Ptr", attrs   ; WORD**
    , "UInt", attrsonly   ; DWORD
    , "Ptr", ServerControls   ; LDAPControlW** optional
    , "Ptr", ClientControls   ; LDAPControlW** optional
    , "UInt", TimeLimit   ; DWORD
    , "UInt", SizeLimit   ; DWORD
    , "Ptr", MessageNumber   ; DWORD* in/out
    , "Cdecl UInt")   ; return: DWORD
●ldap_search_extW(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, TimeLimit, SizeLimit, MessageNumber) = DLL("WLDAP32.dll", "dword ldap_search_extW(void*, char*, dword, char*, void*, dword, void*, void*, dword, dword, void*)")
# 呼び出し: ldap_search_extW(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, TimeLimit, SizeLimit, MessageNumber)
# ld : LDAP* in/out -> "void*"
# base : LPCWSTR optional -> "char*"
# scope : DWORD -> "dword"
# filter : LPCWSTR -> "char*"
# attrs : WORD** -> "void*"
# attrsonly : DWORD -> "dword"
# ServerControls : LDAPControlW** optional -> "void*"
# ClientControls : LDAPControlW** optional -> "void*"
# TimeLimit : DWORD -> "dword"
# SizeLimit : DWORD -> "dword"
# MessageNumber : DWORD* in/out -> "void*"
# なでしこ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_search_extW(
    ld: [*c]LDAP, // LDAP* in/out
    base: [*c]const u16, // LPCWSTR optional
    scope: u32, // DWORD
    filter: [*c]const u16, // LPCWSTR
    attrs: [*c][*c]u16, // WORD**
    attrsonly: u32, // DWORD
    ServerControls: [*c][*c]LDAPControlW, // LDAPControlW** optional
    ClientControls: [*c][*c]LDAPControlW, // LDAPControlW** optional
    TimeLimit: u32, // DWORD
    SizeLimit: u32, // DWORD
    MessageNumber: [*c]u32 // DWORD* in/out
) callconv(.c) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc ldap_search_extW(
    ld: ptr LDAP,  # LDAP* in/out
    base: WideCString,  # LPCWSTR optional
    scope: uint32,  # DWORD
    filter: WideCString,  # LPCWSTR
    attrs: ptr uint16,  # WORD**
    attrsonly: uint32,  # DWORD
    ServerControls: ptr LDAPControlW,  # LDAPControlW** optional
    ClientControls: ptr LDAPControlW,  # LDAPControlW** optional
    TimeLimit: uint32,  # DWORD
    SizeLimit: uint32,  # DWORD
    MessageNumber: ptr uint32  # DWORD* in/out
): uint32 {.importc: "ldap_search_extW", cdecl, dynlib: "WLDAP32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "wldap32");
extern(C)
uint ldap_search_extW(
    LDAP* ld,   // LDAP* in/out
    const(wchar)* base,   // LPCWSTR optional
    uint scope,   // DWORD
    const(wchar)* filter,   // LPCWSTR
    ushort** attrs,   // WORD**
    uint attrsonly,   // DWORD
    LDAPControlW** ServerControls,   // LDAPControlW** optional
    LDAPControlW** ClientControls,   // LDAPControlW** optional
    uint TimeLimit,   // DWORD
    uint SizeLimit,   // DWORD
    uint* MessageNumber   // DWORD* in/out
);
ccall((:ldap_search_extW, "WLDAP32.dll"), UInt32,
      (Ptr{LDAP}, Cwstring, UInt32, Cwstring, Ptr{UInt16}, UInt32, Ptr{LDAPControlW}, Ptr{LDAPControlW}, UInt32, UInt32, Ptr{UInt32}),
      ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, TimeLimit, SizeLimit, MessageNumber)
# ld : LDAP* in/out -> Ptr{LDAP}
# base : LPCWSTR optional -> Cwstring
# scope : DWORD -> UInt32
# filter : LPCWSTR -> Cwstring
# attrs : WORD** -> Ptr{UInt16}
# attrsonly : DWORD -> UInt32
# ServerControls : LDAPControlW** optional -> Ptr{LDAPControlW}
# ClientControls : LDAPControlW** optional -> Ptr{LDAPControlW}
# TimeLimit : DWORD -> UInt32
# SizeLimit : DWORD -> UInt32
# MessageNumber : DWORD* in/out -> Ptr{UInt32}
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t ldap_search_extW(
    void* ld,
    const uint16_t* base,
    uint32_t scope,
    const uint16_t* filter,
    uint16_t** attrs,
    uint32_t attrsonly,
    void* ServerControls,
    void* ClientControls,
    uint32_t TimeLimit,
    uint32_t SizeLimit,
    uint32_t* MessageNumber);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ldap_search_extW(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, TimeLimit, SizeLimit, MessageNumber)
-- ld : LDAP* in/out
-- base : LPCWSTR optional
-- scope : DWORD
-- filter : LPCWSTR
-- attrs : WORD**
-- attrsonly : DWORD
-- ServerControls : LDAPControlW** optional
-- ClientControls : LDAPControlW** optional
-- TimeLimit : DWORD
-- SizeLimit : DWORD
-- MessageNumber : DWORD* in/out
-- 構造体/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_search_extW = lib.func('__cdecl', 'ldap_search_extW', 'uint32_t', ['void *', 'str16', 'uint32_t', 'str16', 'uint16_t *', 'uint32_t', 'void *', 'void *', 'uint32_t', 'uint32_t', 'uint32_t *']);
// ldap_search_extW(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, TimeLimit, SizeLimit, MessageNumber)
// ld : LDAP* in/out -> 'void *'
// base : LPCWSTR optional -> 'str16'
// scope : DWORD -> 'uint32_t'
// filter : LPCWSTR -> 'str16'
// attrs : WORD** -> 'uint16_t *'
// attrsonly : DWORD -> 'uint32_t'
// ServerControls : LDAPControlW** optional -> 'void *'
// ClientControls : LDAPControlW** optional -> 'void *'
// TimeLimit : DWORD -> 'uint32_t'
// SizeLimit : DWORD -> 'uint32_t'
// MessageNumber : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WLDAP32.dll", {
  ldap_search_extW: { parameters: ["pointer", "buffer", "u32", "buffer", "pointer", "u32", "pointer", "pointer", "u32", "u32", "pointer"], result: "u32" },
});
// lib.symbols.ldap_search_extW(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, TimeLimit, SizeLimit, MessageNumber)
// ld : LDAP* in/out -> "pointer"
// base : LPCWSTR optional -> "buffer"
// scope : DWORD -> "u32"
// filter : LPCWSTR -> "buffer"
// attrs : WORD** -> "pointer"
// attrsonly : DWORD -> "u32"
// ServerControls : LDAPControlW** optional -> "pointer"
// ClientControls : LDAPControlW** optional -> "pointer"
// TimeLimit : DWORD -> "u32"
// SizeLimit : DWORD -> "u32"
// MessageNumber : DWORD* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t ldap_search_extW(
    void* ld,
    const uint16_t* base,
    uint32_t scope,
    const uint16_t* filter,
    uint16_t** attrs,
    uint32_t attrsonly,
    void* ServerControls,
    void* ClientControls,
    uint32_t TimeLimit,
    uint32_t SizeLimit,
    uint32_t* MessageNumber);
C, "WLDAP32.dll");
// $ffi->ldap_search_extW(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, TimeLimit, SizeLimit, MessageNumber);
// ld : LDAP* in/out
// base : LPCWSTR optional
// scope : DWORD
// filter : LPCWSTR
// attrs : WORD**
// attrsonly : DWORD
// ServerControls : LDAPControlW** optional
// ClientControls : LDAPControlW** optional
// TimeLimit : DWORD
// SizeLimit : DWORD
// MessageNumber : DWORD* in/out
// 構造体/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_search_extW(
        Pointer ld,   // LDAP* in/out
        WString base,   // LPCWSTR optional
        int scope,   // DWORD
        WString filter,   // LPCWSTR
        Pointer attrs,   // WORD**
        int attrsonly,   // DWORD
        Pointer ServerControls,   // LDAPControlW** optional
        Pointer ClientControls,   // LDAPControlW** optional
        int TimeLimit,   // DWORD
        int SizeLimit,   // DWORD
        IntByReference MessageNumber   // DWORD* in/out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("wldap32")]
lib LibWLDAP32
  fun ldap_search_extW = ldap_search_extW(
    ld : LDAP*,   # LDAP* in/out
    base : UInt16*,   # LPCWSTR optional
    scope : UInt32,   # DWORD
    filter : UInt16*,   # LPCWSTR
    attrs : UInt16**,   # WORD**
    attrsonly : UInt32,   # DWORD
    ServerControls : LDAPControlW**,   # LDAPControlW** optional
    ClientControls : LDAPControlW**,   # LDAPControlW** optional
    TimeLimit : UInt32,   # DWORD
    SizeLimit : UInt32,   # DWORD
    MessageNumber : UInt32*   # DWORD* in/out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ldap_search_extWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Utf16>, Pointer<Uint16>, Uint32, Pointer<Void>, Pointer<Void>, Uint32, Uint32, Pointer<Uint32>);
typedef ldap_search_extWDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Uint16>, int, Pointer<Void>, Pointer<Void>, int, int, Pointer<Uint32>);
final ldap_search_extW = DynamicLibrary.open('WLDAP32.dll')
    .lookupFunction<ldap_search_extWNative, ldap_search_extWDart>('ldap_search_extW');
// ld : LDAP* in/out -> Pointer<Void>
// base : LPCWSTR optional -> Pointer<Utf16>
// scope : DWORD -> Uint32
// filter : LPCWSTR -> Pointer<Utf16>
// attrs : WORD** -> Pointer<Uint16>
// attrsonly : DWORD -> Uint32
// ServerControls : LDAPControlW** optional -> Pointer<Void>
// ClientControls : LDAPControlW** optional -> Pointer<Void>
// TimeLimit : DWORD -> Uint32
// SizeLimit : DWORD -> Uint32
// MessageNumber : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ldap_search_extW(
  ld: Pointer;   // LDAP* in/out
  base: PWideChar;   // LPCWSTR optional
  scope: DWORD;   // DWORD
  filter: PWideChar;   // LPCWSTR
  attrs: Pointer;   // WORD**
  attrsonly: DWORD;   // DWORD
  ServerControls: Pointer;   // LDAPControlW** optional
  ClientControls: Pointer;   // LDAPControlW** optional
  TimeLimit: DWORD;   // DWORD
  SizeLimit: DWORD;   // DWORD
  MessageNumber: Pointer   // DWORD* in/out
): DWORD; cdecl;
  external 'WLDAP32.dll' name 'ldap_search_extW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "ldap_search_extW"
  c_ldap_search_extW :: Ptr () -> CWString -> Word32 -> CWString -> Ptr Word16 -> Word32 -> Ptr () -> Ptr () -> Word32 -> Word32 -> Ptr Word32 -> IO Word32
-- ld : LDAP* in/out -> Ptr ()
-- base : LPCWSTR optional -> CWString
-- scope : DWORD -> Word32
-- filter : LPCWSTR -> CWString
-- attrs : WORD** -> Ptr Word16
-- attrsonly : DWORD -> Word32
-- ServerControls : LDAPControlW** optional -> Ptr ()
-- ClientControls : LDAPControlW** optional -> Ptr ()
-- TimeLimit : DWORD -> Word32
-- SizeLimit : DWORD -> Word32
-- MessageNumber : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ldap_search_extw =
  foreign "ldap_search_extW"
    ((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> uint32_t @-> uint32_t @-> (ptr uint32_t) @-> returning uint32_t)
(* ld : LDAP* in/out -> (ptr void) *)
(* base : LPCWSTR optional -> (ptr uint16_t) *)
(* scope : DWORD -> uint32_t *)
(* filter : LPCWSTR -> (ptr uint16_t) *)
(* attrs : WORD** -> (ptr uint16_t) *)
(* attrsonly : DWORD -> uint32_t *)
(* ServerControls : LDAPControlW** optional -> (ptr void) *)
(* ClientControls : LDAPControlW** optional -> (ptr void) *)
(* TimeLimit : DWORD -> uint32_t *)
(* SizeLimit : DWORD -> uint32_t *)
(* MessageNumber : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wldap32 (t "WLDAP32.dll"))
(cffi:use-foreign-library wldap32)

(cffi:defcfun ("ldap_search_extW" ldap-search-ext-w :convention :cdecl) :uint32
  (ld :pointer)   ; LDAP* in/out
  (base (:string :encoding :utf-16le))   ; LPCWSTR optional
  (scope :uint32)   ; DWORD
  (filter (:string :encoding :utf-16le))   ; LPCWSTR
  (attrs :pointer)   ; WORD**
  (attrsonly :uint32)   ; DWORD
  (server-controls :pointer)   ; LDAPControlW** optional
  (client-controls :pointer)   ; LDAPControlW** optional
  (time-limit :uint32)   ; DWORD
  (size-limit :uint32)   ; DWORD
  (message-number :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ldap_search_extW = Win32::API::More->new('WLDAP32',
    'DWORD ldap_search_extW(LPVOID ld, LPCWSTR base, DWORD scope, LPCWSTR filter, LPVOID attrs, DWORD attrsonly, LPVOID ServerControls, LPVOID ClientControls, DWORD TimeLimit, DWORD SizeLimit, LPVOID MessageNumber)');
# my $ret = $ldap_search_extW->Call($ld, $base, $scope, $filter, $attrs, $attrsonly, $ServerControls, $ClientControls, $TimeLimit, $SizeLimit, $MessageNumber);
# ld : LDAP* in/out -> LPVOID
# base : LPCWSTR optional -> LPCWSTR
# scope : DWORD -> DWORD
# filter : LPCWSTR -> LPCWSTR
# attrs : WORD** -> LPVOID
# attrsonly : DWORD -> DWORD
# ServerControls : LDAPControlW** optional -> LPVOID
# ClientControls : LDAPControlW** optional -> LPVOID
# TimeLimit : DWORD -> DWORD
# SizeLimit : DWORD -> DWORD
# MessageNumber : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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