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

ldap_modrdn2_sW

関数
LDAPエントリのRDNを同期的に変更する(Unicode版)。
DLLWLDAP32.dll文字セットUnicode (-W)呼出規約cdecl対応OSWindows Vista 以降

シグネチャ

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

DWORD ldap_modrdn2_sW(
    LDAP* ExternalHandle,
    LPCWSTR DistinguishedName,
    LPCWSTR NewDistinguishedName,
    INT DeleteOldRdn
);

パラメーター

名前方向説明
ExternalHandleLDAP*inout操作対象のLDAPセッションハンドル。
DistinguishedNameLPCWSTRinRDN変更対象エントリの現在の識別名(DN、Unicode)。
NewDistinguishedNameLPCWSTRin新しい相対識別名(RDN、Unicode)。同期的にRDNを置き換える。
DeleteOldRdnINTin旧RDN属性値を削除するかのフラグ。非0で削除、0で保持する。

戻り値の型: DWORD

各言語での呼び出し定義

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

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

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

var (
	wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
	procldap_modrdn2_sW = wldap32.NewProc("ldap_modrdn2_sW")
)

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

typedef ldap_modrdn2_sWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Int32);
typedef ldap_modrdn2_sWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int);
final ldap_modrdn2_sW = DynamicLibrary.open('WLDAP32.dll')
    .lookupFunction<ldap_modrdn2_sWNative, ldap_modrdn2_sWDart>('ldap_modrdn2_sW');
// ExternalHandle : LDAP* in/out -> Pointer<Void>
// DistinguishedName : LPCWSTR -> Pointer<Utf16>
// NewDistinguishedName : LPCWSTR -> Pointer<Utf16>
// DeleteOldRdn : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ldap_modrdn2_sW(
  ExternalHandle: Pointer;   // LDAP* in/out
  DistinguishedName: PWideChar;   // LPCWSTR
  NewDistinguishedName: PWideChar;   // LPCWSTR
  DeleteOldRdn: Integer   // INT
): DWORD; cdecl;
  external 'WLDAP32.dll' name 'ldap_modrdn2_sW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "ldap_modrdn2_sW"
  c_ldap_modrdn2_sW :: Ptr () -> CWString -> CWString -> Int32 -> IO Word32
-- ExternalHandle : LDAP* in/out -> Ptr ()
-- DistinguishedName : LPCWSTR -> CWString
-- NewDistinguishedName : LPCWSTR -> CWString
-- DeleteOldRdn : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ldap_modrdn2_sw =
  foreign "ldap_modrdn2_sW"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> returning uint32_t)
(* ExternalHandle : LDAP* in/out -> (ptr void) *)
(* DistinguishedName : LPCWSTR -> (ptr uint16_t) *)
(* NewDistinguishedName : LPCWSTR -> (ptr uint16_t) *)
(* DeleteOldRdn : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wldap32 (t "WLDAP32.dll"))
(cffi:use-foreign-library wldap32)

(cffi:defcfun ("ldap_modrdn2_sW" ldap-modrdn2-s-w :convention :cdecl) :uint32
  (external-handle :pointer)   ; LDAP* in/out
  (distinguished-name (:string :encoding :utf-16le))   ; LPCWSTR
  (new-distinguished-name (:string :encoding :utf-16le))   ; LPCWSTR
  (delete-old-rdn :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ldap_modrdn2_sW = Win32::API::More->new('WLDAP32',
    'DWORD ldap_modrdn2_sW(LPVOID ExternalHandle, LPCWSTR DistinguishedName, LPCWSTR NewDistinguishedName, int DeleteOldRdn)');
# my $ret = $ldap_modrdn2_sW->Call($ExternalHandle, $DistinguishedName, $NewDistinguishedName, $DeleteOldRdn);
# ExternalHandle : LDAP* in/out -> LPVOID
# DistinguishedName : LPCWSTR -> LPCWSTR
# NewDistinguishedName : LPCWSTR -> LPCWSTR
# DeleteOldRdn : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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