ホーム › Networking.Ldap › ldap_compareW
ldap_compareW
関数属性値が一致するかLDAPサーバーで非同期に比較する(Unicode版)。
シグネチャ
// WLDAP32.dll (Unicode / -W)
#include <windows.h>
DWORD ldap_compareW(
LDAP* ld,
LPCWSTR dn,
LPCWSTR attr,
LPWSTR value
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ld | LDAP* | inout | 比較操作を行う対象のLDAPセッションハンドル。 |
| dn | LPCWSTR | in | 比較対象エントリの識別名(DN、Unicode)。 |
| attr | LPCWSTR | in | 比較する属性名(Unicode)。エントリ内の対象属性を指す。 |
| value | LPWSTR | in | 属性と照合する値(Unicode)。一致するかをサーバーが判定する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// WLDAP32.dll (Unicode / -W)
#include <windows.h>
DWORD ldap_compareW(
LDAP* ld,
LPCWSTR dn,
LPCWSTR attr,
LPWSTR value
);[DllImport("WLDAP32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_compareW(
IntPtr ld, // LDAP* in/out
[MarshalAs(UnmanagedType.LPWStr)] string dn, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string attr, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string value // LPWSTR
);<DllImport("WLDAP32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_compareW(
ld As IntPtr, ' LDAP* in/out
<MarshalAs(UnmanagedType.LPWStr)> dn As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> attr As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> value As String ' LPWSTR
) As UInteger
End Function' ld : LDAP* in/out
' dn : LPCWSTR
' attr : LPCWSTR
' value : LPWSTR
Declare PtrSafe Function ldap_compareW Lib "wldap32" ( _
ByVal ld As LongPtr, _
ByVal dn As LongPtr, _
ByVal attr As LongPtr, _
ByVal value 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_compareW = ctypes.cdll.wldap32.ldap_compareW
ldap_compareW.restype = wintypes.DWORD
ldap_compareW.argtypes = [
ctypes.c_void_p, # ld : LDAP* in/out
wintypes.LPCWSTR, # dn : LPCWSTR
wintypes.LPCWSTR, # attr : LPCWSTR
wintypes.LPCWSTR, # value : LPWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WLDAP32.dll')
ldap_compareW = Fiddle::Function.new(
lib['ldap_compareW'],
[
Fiddle::TYPE_VOIDP, # ld : LDAP* in/out
Fiddle::TYPE_VOIDP, # dn : LPCWSTR
Fiddle::TYPE_VOIDP, # attr : LPCWSTR
Fiddle::TYPE_VOIDP, # value : LPWSTR
],
-Fiddle::TYPE_INT, Fiddle::Function::CDECL)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "wldap32")]
extern "C" {
fn ldap_compareW(
ld: *mut LDAP, // LDAP* in/out
dn: *const u16, // LPCWSTR
attr: *const u16, // LPCWSTR
value: *mut u16 // LPWSTR
) -> 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_compareW(IntPtr ld, [MarshalAs(UnmanagedType.LPWStr)] string dn, [MarshalAs(UnmanagedType.LPWStr)] string attr, [MarshalAs(UnmanagedType.LPWStr)] string value);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_ldap_compareW' -Namespace Win32 -PassThru
# $api::ldap_compareW(ld, dn, attr, value)#uselib "WLDAP32.dll"
#func global ldap_compareW "ldap_compareW" wptr, wptr, wptr, wptr
; ldap_compareW varptr(ld), dn, attr, value ; 戻り値は stat
; ld : LDAP* in/out -> "wptr"
; dn : LPCWSTR -> "wptr"
; attr : LPCWSTR -> "wptr"
; value : LPWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WLDAP32.dll" #cfunc global ldap_compareW "ldap_compareW" var, wstr, wstr, wstr ; res = ldap_compareW(ld, dn, attr, value) ; ld : LDAP* in/out -> "var" ; dn : LPCWSTR -> "wstr" ; attr : LPCWSTR -> "wstr" ; value : LPWSTR -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WLDAP32.dll" #cfunc global ldap_compareW "ldap_compareW" sptr, wstr, wstr, wstr ; res = ldap_compareW(varptr(ld), dn, attr, value) ; ld : LDAP* in/out -> "sptr" ; dn : LPCWSTR -> "wstr" ; attr : LPCWSTR -> "wstr" ; value : LPWSTR -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD ldap_compareW(LDAP* ld, LPCWSTR dn, LPCWSTR attr, LPWSTR value) #uselib "WLDAP32.dll" #cfunc global ldap_compareW "ldap_compareW" var, wstr, wstr, wstr ; res = ldap_compareW(ld, dn, attr, value) ; ld : LDAP* in/out -> "var" ; dn : LPCWSTR -> "wstr" ; attr : LPCWSTR -> "wstr" ; value : LPWSTR -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD ldap_compareW(LDAP* ld, LPCWSTR dn, LPCWSTR attr, LPWSTR value) #uselib "WLDAP32.dll" #cfunc global ldap_compareW "ldap_compareW" intptr, wstr, wstr, wstr ; res = ldap_compareW(varptr(ld), dn, attr, value) ; ld : LDAP* in/out -> "intptr" ; dn : LPCWSTR -> "wstr" ; attr : LPCWSTR -> "wstr" ; value : LPWSTR -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
procldap_compareW = wldap32.NewProc("ldap_compareW")
)
// ld (LDAP* in/out), dn (LPCWSTR), attr (LPCWSTR), value (LPWSTR)
r1, _, err := procldap_compareW.Call(
uintptr(ld),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(dn))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(attr))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(value))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction ldap_compareW(
ld: Pointer; // LDAP* in/out
dn: PWideChar; // LPCWSTR
attr: PWideChar; // LPCWSTR
value: PWideChar // LPWSTR
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_compareW';result := DllCall("WLDAP32\ldap_compareW"
, "Ptr", ld ; LDAP* in/out
, "WStr", dn ; LPCWSTR
, "WStr", attr ; LPCWSTR
, "WStr", value ; LPWSTR
, "Cdecl UInt") ; return: DWORD●ldap_compareW(ld, dn, attr, value) = DLL("WLDAP32.dll", "dword ldap_compareW(void*, char*, char*, char*)")
# 呼び出し: ldap_compareW(ld, dn, attr, value)
# ld : LDAP* in/out -> "void*"
# dn : LPCWSTR -> "char*"
# attr : LPCWSTR -> "char*"
# value : LPWSTR -> "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_compareW(
ld: [*c]LDAP, // LDAP* in/out
dn: [*c]const u16, // LPCWSTR
attr: [*c]const u16, // LPCWSTR
value: [*c]const u16 // LPWSTR
) callconv(.c) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc ldap_compareW(
ld: ptr LDAP, # LDAP* in/out
dn: WideCString, # LPCWSTR
attr: WideCString, # LPCWSTR
value: WideCString # LPWSTR
): uint32 {.importc: "ldap_compareW", cdecl, dynlib: "WLDAP32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "wldap32");
extern(C)
uint ldap_compareW(
LDAP* ld, // LDAP* in/out
const(wchar)* dn, // LPCWSTR
const(wchar)* attr, // LPCWSTR
const(wchar)* value // LPWSTR
);ccall((:ldap_compareW, "WLDAP32.dll"), UInt32,
(Ptr{LDAP}, Cwstring, Cwstring, Cwstring),
ld, dn, attr, value)
# ld : LDAP* in/out -> Ptr{LDAP}
# dn : LPCWSTR -> Cwstring
# attr : LPCWSTR -> Cwstring
# value : LPWSTR -> Cwstring
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t ldap_compareW(
void* ld,
const uint16_t* dn,
const uint16_t* attr,
const uint16_t* value);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ldap_compareW(ld, dn, attr, value)
-- ld : LDAP* in/out
-- dn : LPCWSTR
-- attr : LPCWSTR
-- value : LPWSTR
-- 構造体/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_compareW = lib.func('__cdecl', 'ldap_compareW', 'uint32_t', ['void *', 'str16', 'str16', 'str16']);
// ldap_compareW(ld, dn, attr, value)
// ld : LDAP* in/out -> 'void *'
// dn : LPCWSTR -> 'str16'
// attr : LPCWSTR -> 'str16'
// value : LPWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WLDAP32.dll", {
ldap_compareW: { parameters: ["pointer", "buffer", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.ldap_compareW(ld, dn, attr, value)
// ld : LDAP* in/out -> "pointer"
// dn : LPCWSTR -> "buffer"
// attr : LPCWSTR -> "buffer"
// value : LPWSTR -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t ldap_compareW(
void* ld,
const uint16_t* dn,
const uint16_t* attr,
const uint16_t* value);
C, "WLDAP32.dll");
// $ffi->ldap_compareW(ld, dn, attr, value);
// ld : LDAP* in/out
// dn : LPCWSTR
// attr : LPCWSTR
// value : LPWSTR
// 構造体/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_compareW(
Pointer ld, // LDAP* in/out
WString dn, // LPCWSTR
WString attr, // LPCWSTR
WString value // LPWSTR
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("wldap32")]
lib LibWLDAP32
fun ldap_compareW = ldap_compareW(
ld : LDAP*, # LDAP* in/out
dn : UInt16*, # LPCWSTR
attr : UInt16*, # LPCWSTR
value : UInt16* # LPWSTR
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ldap_compareWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
typedef ldap_compareWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
final ldap_compareW = DynamicLibrary.open('WLDAP32.dll')
.lookupFunction<ldap_compareWNative, ldap_compareWDart>('ldap_compareW');
// ld : LDAP* in/out -> Pointer<Void>
// dn : LPCWSTR -> Pointer<Utf16>
// attr : LPCWSTR -> Pointer<Utf16>
// value : LPWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ldap_compareW(
ld: Pointer; // LDAP* in/out
dn: PWideChar; // LPCWSTR
attr: PWideChar; // LPCWSTR
value: PWideChar // LPWSTR
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_compareW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ldap_compareW"
c_ldap_compareW :: Ptr () -> CWString -> CWString -> CWString -> IO Word32
-- ld : LDAP* in/out -> Ptr ()
-- dn : LPCWSTR -> CWString
-- attr : LPCWSTR -> CWString
-- value : LPWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ldap_comparew =
foreign "ldap_compareW"
((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* ld : LDAP* in/out -> (ptr void) *)
(* dn : LPCWSTR -> (ptr uint16_t) *)
(* attr : LPCWSTR -> (ptr uint16_t) *)
(* value : LPWSTR -> (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_compareW" ldap-compare-w :convention :cdecl) :uint32
(ld :pointer) ; LDAP* in/out
(dn (:string :encoding :utf-16le)) ; LPCWSTR
(attr (:string :encoding :utf-16le)) ; LPCWSTR
(value (:string :encoding :utf-16le))) ; LPWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ldap_compareW = Win32::API::More->new('WLDAP32',
'DWORD ldap_compareW(LPVOID ld, LPCWSTR dn, LPCWSTR attr, LPCWSTR value)');
# my $ret = $ldap_compareW->Call($ld, $dn, $attr, $value);
# ld : LDAP* in/out -> LPVOID
# dn : LPCWSTR -> LPCWSTR
# attr : LPCWSTR -> LPCWSTR
# value : LPWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f ldap_compareA (ANSI版) — 属性値が一致するかLDAPサーバーで非同期に比較する(ANSI版)。
使用する型