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

ldap_addW

関数
LDAPディレクトリに新しいエントリを非同期に追加する(Unicode版)。
DLLWLDAP32.dll文字セットUnicode (-W)呼出規約cdecl対応OSWindows Vista 以降

シグネチャ

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

DWORD ldap_addW(
    LDAP* ld,
    LPWSTR dn,
    LDAPModW** attrs
);

パラメーター

名前方向説明
ldLDAP*inout追加操作を行う対象のLDAPセッションハンドル。
dnLPWSTRin新規作成するエントリの識別名(DN、Unicode)。
attrsLDAPModW**inout新規エントリの属性と値を記述したLDAPModW構造体のNULL終端配列。

戻り値の型: DWORD

各言語での呼び出し定義

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

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

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

var (
	wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
	procldap_addW = wldap32.NewProc("ldap_addW")
)

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

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

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

let ldap_addw =
  foreign "ldap_addW"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr void) @-> returning uint32_t)
(* ld : LDAP* in/out -> (ptr void) *)
(* dn : LPWSTR -> (ptr uint16_t) *)
(* attrs : LDAPModW** in/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_addW" ldap-add-w :convention :cdecl) :uint32
  (ld :pointer)   ; LDAP* in/out
  (dn (:string :encoding :utf-16le))   ; LPWSTR
  (attrs :pointer))   ; LDAPModW** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ldap_addW = Win32::API::More->new('WLDAP32',
    'DWORD ldap_addW(LPVOID ld, LPCWSTR dn, LPVOID attrs)');
# my $ret = $ldap_addW->Call($ld, $dn, $attrs);
# ld : LDAP* in/out -> LPVOID
# dn : LPWSTR -> LPCWSTR
# attrs : LDAPModW** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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