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

ldap_search_ext_s

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

シグネチャ

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

DWORD ldap_search_ext_s(
    LDAP* ld,
    LPSTR base,   // optional
    DWORD scope,
    LPSTR filter,
    CHAR** attrs,
    DWORD attrsonly,
    LDAPControlA** ServerControls,   // optional
    LDAPControlA** ClientControls,   // optional
    LDAP_TIMEVAL* timeout,
    DWORD SizeLimit,
    LDAPMessage** res
);

パラメーター

名前方向説明
ldLDAP*inout検索を実行する対象のLDAPセッションハンドル。
baseLPSTRinoptional検索の起点となるベースDN(ANSI)。この識別名を基準に探索する。
scopeDWORDin検索範囲を示すフラグ。LDAP_SCOPE_BASE/ONELEVEL/SUBTREEのいずれかを指定する。
filterLPSTRin検索フィルター文字列(ANSI)。RFC形式の検索条件を指定する。
attrsCHAR**in取得する属性名のNULL終端配列。NULLで全属性を返す。
attrsonlyDWORDin属性名のみ取得するかのフラグ。非0で値を除き属性名だけを返す。
ServerControlsLDAPControlA**inoptionalサーバー側コントロールの配列(LDAPControlA*の配列)。不要ならNULL。
ClientControlsLDAPControlA**inoptionalクライアント側コントロールの配列(LDAPControlA*の配列)。不要ならNULL。
timeoutLDAP_TIMEVAL*inout検索の制限時間を示すLDAP_TIMEVAL構造体へのポインタ。NULLで無制限。
SizeLimitDWORDin返すエントリ数の上限。0で無制限を意味する。
resLDAPMessage**out検索結果メッセージを受け取るLDAPMessage*へのポインタ。使用後はldap_msgfreeで解放する。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD ldap_search_ext_s(
    LDAP* ld,
    LPSTR base,   // optional
    DWORD scope,
    LPSTR filter,
    CHAR** attrs,
    DWORD attrsonly,
    LDAPControlA** ServerControls,   // optional
    LDAPControlA** ClientControls,   // optional
    LDAP_TIMEVAL* timeout,
    DWORD SizeLimit,
    LDAPMessage** res
);
[DllImport("WLDAP32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_search_ext_s(
    IntPtr ld,   // LDAP* in/out
    [MarshalAs(UnmanagedType.LPStr)] string base,   // LPSTR optional
    uint scope,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string filter,   // LPSTR
    IntPtr attrs,   // CHAR**
    uint attrsonly,   // DWORD
    IntPtr ServerControls,   // LDAPControlA** optional
    IntPtr ClientControls,   // LDAPControlA** optional
    IntPtr timeout,   // LDAP_TIMEVAL* in/out
    uint SizeLimit,   // DWORD
    IntPtr res   // LDAPMessage** out
);
<DllImport("WLDAP32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_search_ext_s(
    ld As IntPtr,   ' LDAP* in/out
    <MarshalAs(UnmanagedType.LPStr)> base As String,   ' LPSTR optional
    scope As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> filter As String,   ' LPSTR
    attrs As IntPtr,   ' CHAR**
    attrsonly As UInteger,   ' DWORD
    ServerControls As IntPtr,   ' LDAPControlA** optional
    ClientControls As IntPtr,   ' LDAPControlA** optional
    timeout As IntPtr,   ' LDAP_TIMEVAL* in/out
    SizeLimit As UInteger,   ' DWORD
    res As IntPtr   ' LDAPMessage** out
) As UInteger
End Function
' ld : LDAP* in/out
' base : LPSTR optional
' scope : DWORD
' filter : LPSTR
' attrs : CHAR**
' attrsonly : DWORD
' ServerControls : LDAPControlA** optional
' ClientControls : LDAPControlA** optional
' timeout : LDAP_TIMEVAL* in/out
' SizeLimit : DWORD
' res : LDAPMessage** out
Declare PtrSafe Function ldap_search_ext_s Lib "wldap32" ( _
    ByVal ld As LongPtr, _
    ByVal base As String, _
    ByVal scope As Long, _
    ByVal filter As String, _
    ByVal attrs As LongPtr, _
    ByVal attrsonly As Long, _
    ByVal ServerControls As LongPtr, _
    ByVal ClientControls As LongPtr, _
    ByVal timeout As LongPtr, _
    ByVal SizeLimit As Long, _
    ByVal res As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ldap_search_ext_s = ctypes.cdll.wldap32.ldap_search_ext_s
ldap_search_ext_s.restype = wintypes.DWORD
ldap_search_ext_s.argtypes = [
    ctypes.c_void_p,  # ld : LDAP* in/out
    wintypes.LPCSTR,  # base : LPSTR optional
    wintypes.DWORD,  # scope : DWORD
    wintypes.LPCSTR,  # filter : LPSTR
    ctypes.c_void_p,  # attrs : CHAR**
    wintypes.DWORD,  # attrsonly : DWORD
    ctypes.c_void_p,  # ServerControls : LDAPControlA** optional
    ctypes.c_void_p,  # ClientControls : LDAPControlA** optional
    ctypes.c_void_p,  # timeout : LDAP_TIMEVAL* in/out
    wintypes.DWORD,  # SizeLimit : DWORD
    ctypes.c_void_p,  # res : LDAPMessage** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WLDAP32.dll')
ldap_search_ext_s = Fiddle::Function.new(
  lib['ldap_search_ext_s'],
  [
    Fiddle::TYPE_VOIDP,  # ld : LDAP* in/out
    Fiddle::TYPE_VOIDP,  # base : LPSTR optional
    -Fiddle::TYPE_INT,  # scope : DWORD
    Fiddle::TYPE_VOIDP,  # filter : LPSTR
    Fiddle::TYPE_VOIDP,  # attrs : CHAR**
    -Fiddle::TYPE_INT,  # attrsonly : DWORD
    Fiddle::TYPE_VOIDP,  # ServerControls : LDAPControlA** optional
    Fiddle::TYPE_VOIDP,  # ClientControls : LDAPControlA** optional
    Fiddle::TYPE_VOIDP,  # timeout : LDAP_TIMEVAL* in/out
    -Fiddle::TYPE_INT,  # SizeLimit : DWORD
    Fiddle::TYPE_VOIDP,  # res : LDAPMessage** out
  ],
  -Fiddle::TYPE_INT, Fiddle::Function::CDECL)
#[link(name = "wldap32")]
extern "C" {
    fn ldap_search_ext_s(
        ld: *mut LDAP,  // LDAP* in/out
        base: *mut u8,  // LPSTR optional
        scope: u32,  // DWORD
        filter: *mut u8,  // LPSTR
        attrs: *mut *mut i8,  // CHAR**
        attrsonly: u32,  // DWORD
        ServerControls: *mut *mut LDAPControlA,  // LDAPControlA** optional
        ClientControls: *mut *mut LDAPControlA,  // LDAPControlA** optional
        timeout: *mut LDAP_TIMEVAL,  // LDAP_TIMEVAL* in/out
        SizeLimit: u32,  // DWORD
        res: *mut *mut LDAPMessage  // LDAPMessage** out
    ) -> 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_search_ext_s(IntPtr ld, [MarshalAs(UnmanagedType.LPStr)] string base, uint scope, [MarshalAs(UnmanagedType.LPStr)] string filter, IntPtr attrs, uint attrsonly, IntPtr ServerControls, IntPtr ClientControls, IntPtr timeout, uint SizeLimit, IntPtr res);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_ldap_search_ext_s' -Namespace Win32 -PassThru
# $api::ldap_search_ext_s(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, timeout, SizeLimit, res)
#uselib "WLDAP32.dll"
#func global ldap_search_ext_s "ldap_search_ext_s" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ldap_search_ext_s varptr(ld), base, scope, filter, varptr(attrs), attrsonly, varptr(ServerControls), varptr(ClientControls), varptr(timeout), SizeLimit, varptr(res)   ; 戻り値は stat
; ld : LDAP* in/out -> "sptr"
; base : LPSTR optional -> "sptr"
; scope : DWORD -> "sptr"
; filter : LPSTR -> "sptr"
; attrs : CHAR** -> "sptr"
; attrsonly : DWORD -> "sptr"
; ServerControls : LDAPControlA** optional -> "sptr"
; ClientControls : LDAPControlA** optional -> "sptr"
; timeout : LDAP_TIMEVAL* in/out -> "sptr"
; SizeLimit : DWORD -> "sptr"
; res : LDAPMessage** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WLDAP32.dll"
#cfunc global ldap_search_ext_s "ldap_search_ext_s" var, str, int, str, var, int, var, var, var, int, var
; res = ldap_search_ext_s(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, timeout, SizeLimit, res)
; ld : LDAP* in/out -> "var"
; base : LPSTR optional -> "str"
; scope : DWORD -> "int"
; filter : LPSTR -> "str"
; attrs : CHAR** -> "var"
; attrsonly : DWORD -> "int"
; ServerControls : LDAPControlA** optional -> "var"
; ClientControls : LDAPControlA** optional -> "var"
; timeout : LDAP_TIMEVAL* in/out -> "var"
; SizeLimit : DWORD -> "int"
; res : LDAPMessage** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD ldap_search_ext_s(LDAP* ld, LPSTR base, DWORD scope, LPSTR filter, CHAR** attrs, DWORD attrsonly, LDAPControlA** ServerControls, LDAPControlA** ClientControls, LDAP_TIMEVAL* timeout, DWORD SizeLimit, LDAPMessage** res)
#uselib "WLDAP32.dll"
#cfunc global ldap_search_ext_s "ldap_search_ext_s" var, str, int, str, var, int, var, var, var, int, var
; res = ldap_search_ext_s(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, timeout, SizeLimit, res)
; ld : LDAP* in/out -> "var"
; base : LPSTR optional -> "str"
; scope : DWORD -> "int"
; filter : LPSTR -> "str"
; attrs : CHAR** -> "var"
; attrsonly : DWORD -> "int"
; ServerControls : LDAPControlA** optional -> "var"
; ClientControls : LDAPControlA** optional -> "var"
; timeout : LDAP_TIMEVAL* in/out -> "var"
; SizeLimit : DWORD -> "int"
; res : LDAPMessage** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
	procldap_search_ext_s = wldap32.NewProc("ldap_search_ext_s")
)

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

extern "wldap32" fn ldap_search_ext_s(
    ld: [*c]LDAP, // LDAP* in/out
    base: [*c]const u8, // LPSTR optional
    scope: u32, // DWORD
    filter: [*c]const u8, // LPSTR
    attrs: [*c][*c]i8, // CHAR**
    attrsonly: u32, // DWORD
    ServerControls: [*c][*c]LDAPControlA, // LDAPControlA** optional
    ClientControls: [*c][*c]LDAPControlA, // LDAPControlA** optional
    timeout: [*c]LDAP_TIMEVAL, // LDAP_TIMEVAL* in/out
    SizeLimit: u32, // DWORD
    res: [*c][*c]LDAPMessage // LDAPMessage** out
) callconv(.c) u32;
proc ldap_search_ext_s(
    ld: ptr LDAP,  # LDAP* in/out
    base: cstring,  # LPSTR optional
    scope: uint32,  # DWORD
    filter: cstring,  # LPSTR
    attrs: ptr int8,  # CHAR**
    attrsonly: uint32,  # DWORD
    ServerControls: ptr LDAPControlA,  # LDAPControlA** optional
    ClientControls: ptr LDAPControlA,  # LDAPControlA** optional
    timeout: ptr LDAP_TIMEVAL,  # LDAP_TIMEVAL* in/out
    SizeLimit: uint32,  # DWORD
    res: ptr LDAPMessage  # LDAPMessage** out
): uint32 {.importc: "ldap_search_ext_s", cdecl, dynlib: "WLDAP32.dll".}
pragma(lib, "wldap32");
extern(C)
uint ldap_search_ext_s(
    LDAP* ld,   // LDAP* in/out
    const(char)* base,   // LPSTR optional
    uint scope,   // DWORD
    const(char)* filter,   // LPSTR
    byte** attrs,   // CHAR**
    uint attrsonly,   // DWORD
    LDAPControlA** ServerControls,   // LDAPControlA** optional
    LDAPControlA** ClientControls,   // LDAPControlA** optional
    LDAP_TIMEVAL* timeout,   // LDAP_TIMEVAL* in/out
    uint SizeLimit,   // DWORD
    LDAPMessage** res   // LDAPMessage** out
);
ccall((:ldap_search_ext_s, "WLDAP32.dll"), UInt32,
      (Ptr{LDAP}, Cstring, UInt32, Cstring, Ptr{Int8}, UInt32, Ptr{LDAPControlA}, Ptr{LDAPControlA}, Ptr{LDAP_TIMEVAL}, UInt32, Ptr{LDAPMessage}),
      ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, timeout, SizeLimit, res)
# ld : LDAP* in/out -> Ptr{LDAP}
# base : LPSTR optional -> Cstring
# scope : DWORD -> UInt32
# filter : LPSTR -> Cstring
# attrs : CHAR** -> Ptr{Int8}
# attrsonly : DWORD -> UInt32
# ServerControls : LDAPControlA** optional -> Ptr{LDAPControlA}
# ClientControls : LDAPControlA** optional -> Ptr{LDAPControlA}
# timeout : LDAP_TIMEVAL* in/out -> Ptr{LDAP_TIMEVAL}
# SizeLimit : DWORD -> UInt32
# res : LDAPMessage** out -> Ptr{LDAPMessage}
local ffi = require("ffi")
ffi.cdef[[
uint32_t ldap_search_ext_s(
    void* ld,
    const char* base,
    uint32_t scope,
    const char* filter,
    int8_t** attrs,
    uint32_t attrsonly,
    void* ServerControls,
    void* ClientControls,
    void* timeout,
    uint32_t SizeLimit,
    void* res);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ldap_search_ext_s(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, timeout, SizeLimit, res)
-- ld : LDAP* in/out
-- base : LPSTR optional
-- scope : DWORD
-- filter : LPSTR
-- attrs : CHAR**
-- attrsonly : DWORD
-- ServerControls : LDAPControlA** optional
-- ClientControls : LDAPControlA** optional
-- timeout : LDAP_TIMEVAL* in/out
-- SizeLimit : DWORD
-- res : LDAPMessage** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WLDAP32.dll');
const ldap_search_ext_s = lib.func('__cdecl', 'ldap_search_ext_s', 'uint32_t', ['void *', 'str', 'uint32_t', 'str', 'int8_t *', 'uint32_t', 'void *', 'void *', 'void *', 'uint32_t', 'void *']);
// ldap_search_ext_s(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, timeout, SizeLimit, res)
// ld : LDAP* in/out -> 'void *'
// base : LPSTR optional -> 'str'
// scope : DWORD -> 'uint32_t'
// filter : LPSTR -> 'str'
// attrs : CHAR** -> 'int8_t *'
// attrsonly : DWORD -> 'uint32_t'
// ServerControls : LDAPControlA** optional -> 'void *'
// ClientControls : LDAPControlA** optional -> 'void *'
// timeout : LDAP_TIMEVAL* in/out -> 'void *'
// SizeLimit : DWORD -> 'uint32_t'
// res : LDAPMessage** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WLDAP32.dll", {
  ldap_search_ext_s: { parameters: ["pointer", "buffer", "u32", "buffer", "pointer", "u32", "pointer", "pointer", "pointer", "u32", "pointer"], result: "u32" },
});
// lib.symbols.ldap_search_ext_s(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, timeout, SizeLimit, res)
// ld : LDAP* in/out -> "pointer"
// base : LPSTR optional -> "buffer"
// scope : DWORD -> "u32"
// filter : LPSTR -> "buffer"
// attrs : CHAR** -> "pointer"
// attrsonly : DWORD -> "u32"
// ServerControls : LDAPControlA** optional -> "pointer"
// ClientControls : LDAPControlA** optional -> "pointer"
// timeout : LDAP_TIMEVAL* in/out -> "pointer"
// SizeLimit : DWORD -> "u32"
// res : LDAPMessage** out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t ldap_search_ext_s(
    void* ld,
    const char* base,
    uint32_t scope,
    const char* filter,
    int8_t** attrs,
    uint32_t attrsonly,
    void* ServerControls,
    void* ClientControls,
    void* timeout,
    uint32_t SizeLimit,
    void* res);
C, "WLDAP32.dll");
// $ffi->ldap_search_ext_s(ld, base, scope, filter, attrs, attrsonly, ServerControls, ClientControls, timeout, SizeLimit, res);
// ld : LDAP* in/out
// base : LPSTR optional
// scope : DWORD
// filter : LPSTR
// attrs : CHAR**
// attrsonly : DWORD
// ServerControls : LDAPControlA** optional
// ClientControls : LDAPControlA** optional
// timeout : LDAP_TIMEVAL* in/out
// SizeLimit : DWORD
// res : LDAPMessage** 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.ASCII_OPTIONS);
    int ldap_search_ext_s(
        Pointer ld,   // LDAP* in/out
        String base,   // LPSTR optional
        int scope,   // DWORD
        String filter,   // LPSTR
        Pointer attrs,   // CHAR**
        int attrsonly,   // DWORD
        Pointer ServerControls,   // LDAPControlA** optional
        Pointer ClientControls,   // LDAPControlA** optional
        Pointer timeout,   // LDAP_TIMEVAL* in/out
        int SizeLimit,   // DWORD
        Pointer res   // LDAPMessage** out
    );
}
@[Link("wldap32")]
lib LibWLDAP32
  fun ldap_search_ext_s = ldap_search_ext_s(
    ld : LDAP*,   # LDAP* in/out
    base : UInt8*,   # LPSTR optional
    scope : UInt32,   # DWORD
    filter : UInt8*,   # LPSTR
    attrs : Int8**,   # CHAR**
    attrsonly : UInt32,   # DWORD
    ServerControls : LDAPControlA**,   # LDAPControlA** optional
    ClientControls : LDAPControlA**,   # LDAPControlA** optional
    timeout : LDAP_TIMEVAL*,   # LDAP_TIMEVAL* in/out
    SizeLimit : UInt32,   # DWORD
    res : LDAPMessage**   # LDAPMessage** out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ldap_search_ext_sNative = Uint32 Function(Pointer<Void>, Pointer<Utf8>, Uint32, Pointer<Utf8>, Pointer<Int8>, Uint32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint32, Pointer<Void>);
typedef ldap_search_ext_sDart = int Function(Pointer<Void>, Pointer<Utf8>, int, Pointer<Utf8>, Pointer<Int8>, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, int, Pointer<Void>);
final ldap_search_ext_s = DynamicLibrary.open('WLDAP32.dll')
    .lookupFunction<ldap_search_ext_sNative, ldap_search_ext_sDart>('ldap_search_ext_s');
// ld : LDAP* in/out -> Pointer<Void>
// base : LPSTR optional -> Pointer<Utf8>
// scope : DWORD -> Uint32
// filter : LPSTR -> Pointer<Utf8>
// attrs : CHAR** -> Pointer<Int8>
// attrsonly : DWORD -> Uint32
// ServerControls : LDAPControlA** optional -> Pointer<Void>
// ClientControls : LDAPControlA** optional -> Pointer<Void>
// timeout : LDAP_TIMEVAL* in/out -> Pointer<Void>
// SizeLimit : DWORD -> Uint32
// res : LDAPMessage** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ldap_search_ext_s(
  ld: Pointer;   // LDAP* in/out
  base: PAnsiChar;   // LPSTR optional
  scope: DWORD;   // DWORD
  filter: PAnsiChar;   // LPSTR
  attrs: Pointer;   // CHAR**
  attrsonly: DWORD;   // DWORD
  ServerControls: Pointer;   // LDAPControlA** optional
  ClientControls: Pointer;   // LDAPControlA** optional
  timeout: Pointer;   // LDAP_TIMEVAL* in/out
  SizeLimit: DWORD;   // DWORD
  res: Pointer   // LDAPMessage** out
): DWORD; cdecl;
  external 'WLDAP32.dll' name 'ldap_search_ext_s';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "ldap_search_ext_s"
  c_ldap_search_ext_s :: Ptr () -> CString -> Word32 -> CString -> Ptr Int8 -> Word32 -> Ptr () -> Ptr () -> Ptr () -> Word32 -> Ptr () -> IO Word32
-- ld : LDAP* in/out -> Ptr ()
-- base : LPSTR optional -> CString
-- scope : DWORD -> Word32
-- filter : LPSTR -> CString
-- attrs : CHAR** -> Ptr Int8
-- attrsonly : DWORD -> Word32
-- ServerControls : LDAPControlA** optional -> Ptr ()
-- ClientControls : LDAPControlA** optional -> Ptr ()
-- timeout : LDAP_TIMEVAL* in/out -> Ptr ()
-- SizeLimit : DWORD -> Word32
-- res : LDAPMessage** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ldap_search_ext_s =
  foreign "ldap_search_ext_s"
    ((ptr void) @-> string @-> uint32_t @-> string @-> (ptr int8_t) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> returning uint32_t)
(* ld : LDAP* in/out -> (ptr void) *)
(* base : LPSTR optional -> string *)
(* scope : DWORD -> uint32_t *)
(* filter : LPSTR -> string *)
(* attrs : CHAR** -> (ptr int8_t) *)
(* attrsonly : DWORD -> uint32_t *)
(* ServerControls : LDAPControlA** optional -> (ptr void) *)
(* ClientControls : LDAPControlA** optional -> (ptr void) *)
(* timeout : LDAP_TIMEVAL* in/out -> (ptr void) *)
(* SizeLimit : DWORD -> uint32_t *)
(* res : LDAPMessage** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wldap32 (t "WLDAP32.dll"))
(cffi:use-foreign-library wldap32)

(cffi:defcfun ("ldap_search_ext_s" ldap-search-ext-s :convention :cdecl) :uint32
  (ld :pointer)   ; LDAP* in/out
  (base :string)   ; LPSTR optional
  (scope :uint32)   ; DWORD
  (filter :string)   ; LPSTR
  (attrs :pointer)   ; CHAR**
  (attrsonly :uint32)   ; DWORD
  (server-controls :pointer)   ; LDAPControlA** optional
  (client-controls :pointer)   ; LDAPControlA** optional
  (timeout :pointer)   ; LDAP_TIMEVAL* in/out
  (size-limit :uint32)   ; DWORD
  (res :pointer))   ; LDAPMessage** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ldap_search_ext_s = Win32::API::More->new('WLDAP32',
    'DWORD ldap_search_ext_s(LPVOID ld, LPCSTR base, DWORD scope, LPCSTR filter, LPVOID attrs, DWORD attrsonly, LPVOID ServerControls, LPVOID ClientControls, LPVOID timeout, DWORD SizeLimit, LPVOID res)');
# my $ret = $ldap_search_ext_s->Call($ld, $base, $scope, $filter, $attrs, $attrsonly, $ServerControls, $ClientControls, $timeout, $SizeLimit, $res);
# ld : LDAP* in/out -> LPVOID
# base : LPSTR optional -> LPCSTR
# scope : DWORD -> DWORD
# filter : LPSTR -> LPCSTR
# attrs : CHAR** -> LPVOID
# attrsonly : DWORD -> DWORD
# ServerControls : LDAPControlA** optional -> LPVOID
# ClientControls : LDAPControlA** optional -> LPVOID
# timeout : LDAP_TIMEVAL* in/out -> LPVOID
# SizeLimit : DWORD -> DWORD
# res : LDAPMessage** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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