ホーム › Networking.Ldap › ldap_add_sW
ldap_add_sW
関数LDAPディレクトリに新しいエントリを同期的に追加する(Unicode版)。
シグネチャ
// WLDAP32.dll (Unicode / -W)
#include <windows.h>
DWORD ldap_add_sW(
LDAP* ld,
LPWSTR dn,
LDAPModW** attrs
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ld | LDAP* | inout | 追加操作を行う対象のLDAPセッションハンドル。 |
| dn | LPWSTR | in | 新規作成するエントリの識別名(DN、Unicode)。 |
| attrs | LDAPModW** | inout | 新規エントリの属性と値を記述したLDAPModW構造体のNULL終端配列。同期的に追加する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// WLDAP32.dll (Unicode / -W)
#include <windows.h>
DWORD ldap_add_sW(
LDAP* ld,
LPWSTR dn,
LDAPModW** attrs
);[DllImport("WLDAP32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_add_sW(
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_add_sW(
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_add_sW 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_add_sW = ctypes.cdll.wldap32.ldap_add_sW
ldap_add_sW.restype = wintypes.DWORD
ldap_add_sW.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_add_sW = Fiddle::Function.new(
lib['ldap_add_sW'],
[
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_add_sW(
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_add_sW(IntPtr ld, [MarshalAs(UnmanagedType.LPWStr)] string dn, IntPtr attrs);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_ldap_add_sW' -Namespace Win32 -PassThru
# $api::ldap_add_sW(ld, dn, attrs)#uselib "WLDAP32.dll"
#func global ldap_add_sW "ldap_add_sW" wptr, wptr, wptr
; ldap_add_sW 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_add_sW "ldap_add_sW" var, wstr, var ; res = ldap_add_sW(ld, dn, attrs) ; ld : LDAP* in/out -> "var" ; dn : LPWSTR -> "wstr" ; attrs : LDAPModW** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WLDAP32.dll" #cfunc global ldap_add_sW "ldap_add_sW" sptr, wstr, sptr ; res = ldap_add_sW(varptr(ld), dn, varptr(attrs)) ; ld : LDAP* in/out -> "sptr" ; dn : LPWSTR -> "wstr" ; attrs : LDAPModW** in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD ldap_add_sW(LDAP* ld, LPWSTR dn, LDAPModW** attrs) #uselib "WLDAP32.dll" #cfunc global ldap_add_sW "ldap_add_sW" var, wstr, var ; res = ldap_add_sW(ld, dn, attrs) ; ld : LDAP* in/out -> "var" ; dn : LPWSTR -> "wstr" ; attrs : LDAPModW** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD ldap_add_sW(LDAP* ld, LPWSTR dn, LDAPModW** attrs) #uselib "WLDAP32.dll" #cfunc global ldap_add_sW "ldap_add_sW" intptr, wstr, intptr ; res = ldap_add_sW(varptr(ld), dn, varptr(attrs)) ; ld : LDAP* in/out -> "intptr" ; dn : LPWSTR -> "wstr" ; attrs : LDAPModW** in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
procldap_add_sW = wldap32.NewProc("ldap_add_sW")
)
// ld (LDAP* in/out), dn (LPWSTR), attrs (LDAPModW** in/out)
r1, _, err := procldap_add_sW.Call(
uintptr(ld),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(dn))),
uintptr(attrs),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction ldap_add_sW(
ld: Pointer; // LDAP* in/out
dn: PWideChar; // LPWSTR
attrs: Pointer // LDAPModW** in/out
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_add_sW';result := DllCall("WLDAP32\ldap_add_sW"
, "Ptr", ld ; LDAP* in/out
, "WStr", dn ; LPWSTR
, "Ptr", attrs ; LDAPModW** in/out
, "Cdecl UInt") ; return: DWORD●ldap_add_sW(ld, dn, attrs) = DLL("WLDAP32.dll", "dword ldap_add_sW(void*, char*, void*)")
# 呼び出し: ldap_add_sW(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_add_sW(
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_add_sW(
ld: ptr LDAP, # LDAP* in/out
dn: WideCString, # LPWSTR
attrs: ptr LDAPModW # LDAPModW** in/out
): uint32 {.importc: "ldap_add_sW", cdecl, dynlib: "WLDAP32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "wldap32");
extern(C)
uint ldap_add_sW(
LDAP* ld, // LDAP* in/out
const(wchar)* dn, // LPWSTR
LDAPModW** attrs // LDAPModW** in/out
);ccall((:ldap_add_sW, "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_add_sW(
void* ld,
const uint16_t* dn,
void* attrs);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ldap_add_sW(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_add_sW = lib.func('__cdecl', 'ldap_add_sW', 'uint32_t', ['void *', 'str16', 'void *']);
// ldap_add_sW(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_add_sW: { parameters: ["pointer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.ldap_add_sW(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_add_sW(
void* ld,
const uint16_t* dn,
void* attrs);
C, "WLDAP32.dll");
// $ffi->ldap_add_sW(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_add_sW(
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_add_sW = ldap_add_sW(
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_add_sWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>);
typedef ldap_add_sWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>);
final ldap_add_sW = DynamicLibrary.open('WLDAP32.dll')
.lookupFunction<ldap_add_sWNative, ldap_add_sWDart>('ldap_add_sW');
// 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_add_sW(
ld: Pointer; // LDAP* in/out
dn: PWideChar; // LPWSTR
attrs: Pointer // LDAPModW** in/out
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_add_sW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ldap_add_sW"
c_ldap_add_sW :: 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_add_sw =
foreign "ldap_add_sW"
((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_add_sW" ldap-add-s-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_add_sW = Win32::API::More->new('WLDAP32',
'DWORD ldap_add_sW(LPVOID ld, LPCWSTR dn, LPVOID attrs)');
# my $ret = $ldap_add_sW->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 変換を行う。関連項目
文字セット違い
- f ldap_add_sA (ANSI版) — LDAPディレクトリに新しいエントリを同期的に追加する(ANSI版)。
使用する型