ホーム › Networking.ActiveDirectory › DsReplicaGetInfo2W
DsReplicaGetInfo2W
関数属性や列挙コンテキストを指定して詳細なレプリケーション情報を取得する。
シグネチャ
// NTDSAPI.dll
#include <windows.h>
DWORD DsReplicaGetInfo2W(
HANDLE hDS,
DS_REPL_INFO_TYPE InfoType,
LPCWSTR pszObject, // optional
GUID* puuidForSourceDsaObjGuid, // optional
LPCWSTR pszAttributeName, // optional
LPCWSTR pszValue, // optional
DWORD dwFlags,
DWORD dwEnumerationContext,
void** ppInfo
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hDS | HANDLE | in | DsBind系で取得したディレクトリサービスへのバインドハンドル。対象DCを指す。 |
| InfoType | DS_REPL_INFO_TYPE | in | 取得するレプリケーション情報の種別を指定する列挙値。隣接サーバや属性メタデータ等を選ぶ。 |
| pszObject | LPCWSTR | inoptional | 情報取得の対象となるオブジェクトの識別名(DN)を指すワイド文字列。種別により省略可。 |
| puuidForSourceDsaObjGuid | GUID* | inoptional | ソースDSAオブジェクトのGUIDへのポインタ。特定ソースを絞り込む場合に指定し、不要ならNULL可。 |
| pszAttributeName | LPCWSTR | inoptional | 対象とする属性名のワイド文字列。属性単位の情報取得で使用し、不要ならNULL可。 |
| pszValue | LPCWSTR | inoptional | 対象属性値を表すワイド文字列。値で絞り込む場合に指定し、不要ならNULL可。 |
| dwFlags | DWORD | in | 情報取得の挙動を制御するDS_REPL_INFO_FLAGS_*ビットフラグ。動作変更が不要なら0。 |
| dwEnumerationContext | DWORD | in | 列挙の再開位置を示すコンテキスト値。先頭から取得する場合は0を指定する。 |
| ppInfo | void** | out | 取得した情報構造体へのポインタを受け取る出力。使用後はDsReplicaFreeInfoで解放する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// NTDSAPI.dll
#include <windows.h>
DWORD DsReplicaGetInfo2W(
HANDLE hDS,
DS_REPL_INFO_TYPE InfoType,
LPCWSTR pszObject, // optional
GUID* puuidForSourceDsaObjGuid, // optional
LPCWSTR pszAttributeName, // optional
LPCWSTR pszValue, // optional
DWORD dwFlags,
DWORD dwEnumerationContext,
void** ppInfo
);[DllImport("NTDSAPI.dll", ExactSpelling = true)]
static extern uint DsReplicaGetInfo2W(
IntPtr hDS, // HANDLE
int InfoType, // DS_REPL_INFO_TYPE
[MarshalAs(UnmanagedType.LPWStr)] string pszObject, // LPCWSTR optional
IntPtr puuidForSourceDsaObjGuid, // GUID* optional
[MarshalAs(UnmanagedType.LPWStr)] string pszAttributeName, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pszValue, // LPCWSTR optional
uint dwFlags, // DWORD
uint dwEnumerationContext, // DWORD
IntPtr ppInfo // void** out
);<DllImport("NTDSAPI.dll", ExactSpelling:=True)>
Public Shared Function DsReplicaGetInfo2W(
hDS As IntPtr, ' HANDLE
InfoType As Integer, ' DS_REPL_INFO_TYPE
<MarshalAs(UnmanagedType.LPWStr)> pszObject As String, ' LPCWSTR optional
puuidForSourceDsaObjGuid As IntPtr, ' GUID* optional
<MarshalAs(UnmanagedType.LPWStr)> pszAttributeName As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pszValue As String, ' LPCWSTR optional
dwFlags As UInteger, ' DWORD
dwEnumerationContext As UInteger, ' DWORD
ppInfo As IntPtr ' void** out
) As UInteger
End Function' hDS : HANDLE
' InfoType : DS_REPL_INFO_TYPE
' pszObject : LPCWSTR optional
' puuidForSourceDsaObjGuid : GUID* optional
' pszAttributeName : LPCWSTR optional
' pszValue : LPCWSTR optional
' dwFlags : DWORD
' dwEnumerationContext : DWORD
' ppInfo : void** out
Declare PtrSafe Function DsReplicaGetInfo2W Lib "ntdsapi" ( _
ByVal hDS As LongPtr, _
ByVal InfoType As Long, _
ByVal pszObject As LongPtr, _
ByVal puuidForSourceDsaObjGuid As LongPtr, _
ByVal pszAttributeName As LongPtr, _
ByVal pszValue As LongPtr, _
ByVal dwFlags As Long, _
ByVal dwEnumerationContext As Long, _
ByVal ppInfo As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DsReplicaGetInfo2W = ctypes.windll.ntdsapi.DsReplicaGetInfo2W
DsReplicaGetInfo2W.restype = wintypes.DWORD
DsReplicaGetInfo2W.argtypes = [
wintypes.HANDLE, # hDS : HANDLE
ctypes.c_int, # InfoType : DS_REPL_INFO_TYPE
wintypes.LPCWSTR, # pszObject : LPCWSTR optional
ctypes.c_void_p, # puuidForSourceDsaObjGuid : GUID* optional
wintypes.LPCWSTR, # pszAttributeName : LPCWSTR optional
wintypes.LPCWSTR, # pszValue : LPCWSTR optional
wintypes.DWORD, # dwFlags : DWORD
wintypes.DWORD, # dwEnumerationContext : DWORD
ctypes.c_void_p, # ppInfo : void** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NTDSAPI.dll')
DsReplicaGetInfo2W = Fiddle::Function.new(
lib['DsReplicaGetInfo2W'],
[
Fiddle::TYPE_VOIDP, # hDS : HANDLE
Fiddle::TYPE_INT, # InfoType : DS_REPL_INFO_TYPE
Fiddle::TYPE_VOIDP, # pszObject : LPCWSTR optional
Fiddle::TYPE_VOIDP, # puuidForSourceDsaObjGuid : GUID* optional
Fiddle::TYPE_VOIDP, # pszAttributeName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pszValue : LPCWSTR optional
-Fiddle::TYPE_INT, # dwFlags : DWORD
-Fiddle::TYPE_INT, # dwEnumerationContext : DWORD
Fiddle::TYPE_VOIDP, # ppInfo : void** out
],
-Fiddle::TYPE_INT)#[link(name = "ntdsapi")]
extern "system" {
fn DsReplicaGetInfo2W(
hDS: *mut core::ffi::c_void, // HANDLE
InfoType: i32, // DS_REPL_INFO_TYPE
pszObject: *const u16, // LPCWSTR optional
puuidForSourceDsaObjGuid: *mut GUID, // GUID* optional
pszAttributeName: *const u16, // LPCWSTR optional
pszValue: *const u16, // LPCWSTR optional
dwFlags: u32, // DWORD
dwEnumerationContext: u32, // DWORD
ppInfo: *mut *mut () // void** out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("NTDSAPI.dll")]
public static extern uint DsReplicaGetInfo2W(IntPtr hDS, int InfoType, [MarshalAs(UnmanagedType.LPWStr)] string pszObject, IntPtr puuidForSourceDsaObjGuid, [MarshalAs(UnmanagedType.LPWStr)] string pszAttributeName, [MarshalAs(UnmanagedType.LPWStr)] string pszValue, uint dwFlags, uint dwEnumerationContext, IntPtr ppInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NTDSAPI_DsReplicaGetInfo2W' -Namespace Win32 -PassThru
# $api::DsReplicaGetInfo2W(hDS, InfoType, pszObject, puuidForSourceDsaObjGuid, pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo)#uselib "NTDSAPI.dll"
#func global DsReplicaGetInfo2W "DsReplicaGetInfo2W" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DsReplicaGetInfo2W hDS, InfoType, pszObject, varptr(puuidForSourceDsaObjGuid), pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo ; 戻り値は stat
; hDS : HANDLE -> "sptr"
; InfoType : DS_REPL_INFO_TYPE -> "sptr"
; pszObject : LPCWSTR optional -> "sptr"
; puuidForSourceDsaObjGuid : GUID* optional -> "sptr"
; pszAttributeName : LPCWSTR optional -> "sptr"
; pszValue : LPCWSTR optional -> "sptr"
; dwFlags : DWORD -> "sptr"
; dwEnumerationContext : DWORD -> "sptr"
; ppInfo : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "NTDSAPI.dll" #cfunc global DsReplicaGetInfo2W "DsReplicaGetInfo2W" sptr, int, wstr, var, wstr, wstr, int, int, sptr ; res = DsReplicaGetInfo2W(hDS, InfoType, pszObject, puuidForSourceDsaObjGuid, pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo) ; hDS : HANDLE -> "sptr" ; InfoType : DS_REPL_INFO_TYPE -> "int" ; pszObject : LPCWSTR optional -> "wstr" ; puuidForSourceDsaObjGuid : GUID* optional -> "var" ; pszAttributeName : LPCWSTR optional -> "wstr" ; pszValue : LPCWSTR optional -> "wstr" ; dwFlags : DWORD -> "int" ; dwEnumerationContext : DWORD -> "int" ; ppInfo : void** out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "NTDSAPI.dll" #cfunc global DsReplicaGetInfo2W "DsReplicaGetInfo2W" sptr, int, wstr, sptr, wstr, wstr, int, int, sptr ; res = DsReplicaGetInfo2W(hDS, InfoType, pszObject, varptr(puuidForSourceDsaObjGuid), pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo) ; hDS : HANDLE -> "sptr" ; InfoType : DS_REPL_INFO_TYPE -> "int" ; pszObject : LPCWSTR optional -> "wstr" ; puuidForSourceDsaObjGuid : GUID* optional -> "sptr" ; pszAttributeName : LPCWSTR optional -> "wstr" ; pszValue : LPCWSTR optional -> "wstr" ; dwFlags : DWORD -> "int" ; dwEnumerationContext : DWORD -> "int" ; ppInfo : void** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DsReplicaGetInfo2W(HANDLE hDS, DS_REPL_INFO_TYPE InfoType, LPCWSTR pszObject, GUID* puuidForSourceDsaObjGuid, LPCWSTR pszAttributeName, LPCWSTR pszValue, DWORD dwFlags, DWORD dwEnumerationContext, void** ppInfo) #uselib "NTDSAPI.dll" #cfunc global DsReplicaGetInfo2W "DsReplicaGetInfo2W" intptr, int, wstr, var, wstr, wstr, int, int, intptr ; res = DsReplicaGetInfo2W(hDS, InfoType, pszObject, puuidForSourceDsaObjGuid, pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo) ; hDS : HANDLE -> "intptr" ; InfoType : DS_REPL_INFO_TYPE -> "int" ; pszObject : LPCWSTR optional -> "wstr" ; puuidForSourceDsaObjGuid : GUID* optional -> "var" ; pszAttributeName : LPCWSTR optional -> "wstr" ; pszValue : LPCWSTR optional -> "wstr" ; dwFlags : DWORD -> "int" ; dwEnumerationContext : DWORD -> "int" ; ppInfo : void** out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DsReplicaGetInfo2W(HANDLE hDS, DS_REPL_INFO_TYPE InfoType, LPCWSTR pszObject, GUID* puuidForSourceDsaObjGuid, LPCWSTR pszAttributeName, LPCWSTR pszValue, DWORD dwFlags, DWORD dwEnumerationContext, void** ppInfo) #uselib "NTDSAPI.dll" #cfunc global DsReplicaGetInfo2W "DsReplicaGetInfo2W" intptr, int, wstr, intptr, wstr, wstr, int, int, intptr ; res = DsReplicaGetInfo2W(hDS, InfoType, pszObject, varptr(puuidForSourceDsaObjGuid), pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo) ; hDS : HANDLE -> "intptr" ; InfoType : DS_REPL_INFO_TYPE -> "int" ; pszObject : LPCWSTR optional -> "wstr" ; puuidForSourceDsaObjGuid : GUID* optional -> "intptr" ; pszAttributeName : LPCWSTR optional -> "wstr" ; pszValue : LPCWSTR optional -> "wstr" ; dwFlags : DWORD -> "int" ; dwEnumerationContext : DWORD -> "int" ; ppInfo : void** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
procDsReplicaGetInfo2W = ntdsapi.NewProc("DsReplicaGetInfo2W")
)
// hDS (HANDLE), InfoType (DS_REPL_INFO_TYPE), pszObject (LPCWSTR optional), puuidForSourceDsaObjGuid (GUID* optional), pszAttributeName (LPCWSTR optional), pszValue (LPCWSTR optional), dwFlags (DWORD), dwEnumerationContext (DWORD), ppInfo (void** out)
r1, _, err := procDsReplicaGetInfo2W.Call(
uintptr(hDS),
uintptr(InfoType),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszObject))),
uintptr(puuidForSourceDsaObjGuid),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszAttributeName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszValue))),
uintptr(dwFlags),
uintptr(dwEnumerationContext),
uintptr(ppInfo),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DsReplicaGetInfo2W(
hDS: THandle; // HANDLE
InfoType: Integer; // DS_REPL_INFO_TYPE
pszObject: PWideChar; // LPCWSTR optional
puuidForSourceDsaObjGuid: PGUID; // GUID* optional
pszAttributeName: PWideChar; // LPCWSTR optional
pszValue: PWideChar; // LPCWSTR optional
dwFlags: DWORD; // DWORD
dwEnumerationContext: DWORD; // DWORD
ppInfo: Pointer // void** out
): DWORD; stdcall;
external 'NTDSAPI.dll' name 'DsReplicaGetInfo2W';result := DllCall("NTDSAPI\DsReplicaGetInfo2W"
, "Ptr", hDS ; HANDLE
, "Int", InfoType ; DS_REPL_INFO_TYPE
, "WStr", pszObject ; LPCWSTR optional
, "Ptr", puuidForSourceDsaObjGuid ; GUID* optional
, "WStr", pszAttributeName ; LPCWSTR optional
, "WStr", pszValue ; LPCWSTR optional
, "UInt", dwFlags ; DWORD
, "UInt", dwEnumerationContext ; DWORD
, "Ptr", ppInfo ; void** out
, "UInt") ; return: DWORD●DsReplicaGetInfo2W(hDS, InfoType, pszObject, puuidForSourceDsaObjGuid, pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo) = DLL("NTDSAPI.dll", "dword DsReplicaGetInfo2W(void*, int, char*, void*, char*, char*, dword, dword, void*)")
# 呼び出し: DsReplicaGetInfo2W(hDS, InfoType, pszObject, puuidForSourceDsaObjGuid, pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo)
# hDS : HANDLE -> "void*"
# InfoType : DS_REPL_INFO_TYPE -> "int"
# pszObject : LPCWSTR optional -> "char*"
# puuidForSourceDsaObjGuid : GUID* optional -> "void*"
# pszAttributeName : LPCWSTR optional -> "char*"
# pszValue : LPCWSTR optional -> "char*"
# dwFlags : DWORD -> "dword"
# dwEnumerationContext : DWORD -> "dword"
# ppInfo : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ntdsapi" fn DsReplicaGetInfo2W(
hDS: ?*anyopaque, // HANDLE
InfoType: i32, // DS_REPL_INFO_TYPE
pszObject: [*c]const u16, // LPCWSTR optional
puuidForSourceDsaObjGuid: [*c]GUID, // GUID* optional
pszAttributeName: [*c]const u16, // LPCWSTR optional
pszValue: [*c]const u16, // LPCWSTR optional
dwFlags: u32, // DWORD
dwEnumerationContext: u32, // DWORD
ppInfo: ?*anyopaque // void** out
) callconv(std.os.windows.WINAPI) u32;proc DsReplicaGetInfo2W(
hDS: pointer, # HANDLE
InfoType: int32, # DS_REPL_INFO_TYPE
pszObject: WideCString, # LPCWSTR optional
puuidForSourceDsaObjGuid: ptr GUID, # GUID* optional
pszAttributeName: WideCString, # LPCWSTR optional
pszValue: WideCString, # LPCWSTR optional
dwFlags: uint32, # DWORD
dwEnumerationContext: uint32, # DWORD
ppInfo: pointer # void** out
): uint32 {.importc: "DsReplicaGetInfo2W", stdcall, dynlib: "NTDSAPI.dll".}pragma(lib, "ntdsapi");
extern(Windows)
uint DsReplicaGetInfo2W(
void* hDS, // HANDLE
int InfoType, // DS_REPL_INFO_TYPE
const(wchar)* pszObject, // LPCWSTR optional
GUID* puuidForSourceDsaObjGuid, // GUID* optional
const(wchar)* pszAttributeName, // LPCWSTR optional
const(wchar)* pszValue, // LPCWSTR optional
uint dwFlags, // DWORD
uint dwEnumerationContext, // DWORD
void** ppInfo // void** out
);ccall((:DsReplicaGetInfo2W, "NTDSAPI.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Int32, Cwstring, Ptr{GUID}, Cwstring, Cwstring, UInt32, UInt32, Ptr{Cvoid}),
hDS, InfoType, pszObject, puuidForSourceDsaObjGuid, pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo)
# hDS : HANDLE -> Ptr{Cvoid}
# InfoType : DS_REPL_INFO_TYPE -> Int32
# pszObject : LPCWSTR optional -> Cwstring
# puuidForSourceDsaObjGuid : GUID* optional -> Ptr{GUID}
# pszAttributeName : LPCWSTR optional -> Cwstring
# pszValue : LPCWSTR optional -> Cwstring
# dwFlags : DWORD -> UInt32
# dwEnumerationContext : DWORD -> UInt32
# ppInfo : void** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DsReplicaGetInfo2W(
void* hDS,
int32_t InfoType,
const uint16_t* pszObject,
void* puuidForSourceDsaObjGuid,
const uint16_t* pszAttributeName,
const uint16_t* pszValue,
uint32_t dwFlags,
uint32_t dwEnumerationContext,
void** ppInfo);
]]
local ntdsapi = ffi.load("ntdsapi")
-- ntdsapi.DsReplicaGetInfo2W(hDS, InfoType, pszObject, puuidForSourceDsaObjGuid, pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo)
-- hDS : HANDLE
-- InfoType : DS_REPL_INFO_TYPE
-- pszObject : LPCWSTR optional
-- puuidForSourceDsaObjGuid : GUID* optional
-- pszAttributeName : LPCWSTR optional
-- pszValue : LPCWSTR optional
-- dwFlags : DWORD
-- dwEnumerationContext : DWORD
-- ppInfo : void** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('NTDSAPI.dll');
const DsReplicaGetInfo2W = lib.func('__stdcall', 'DsReplicaGetInfo2W', 'uint32_t', ['void *', 'int32_t', 'str16', 'void *', 'str16', 'str16', 'uint32_t', 'uint32_t', 'void *']);
// DsReplicaGetInfo2W(hDS, InfoType, pszObject, puuidForSourceDsaObjGuid, pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo)
// hDS : HANDLE -> 'void *'
// InfoType : DS_REPL_INFO_TYPE -> 'int32_t'
// pszObject : LPCWSTR optional -> 'str16'
// puuidForSourceDsaObjGuid : GUID* optional -> 'void *'
// pszAttributeName : LPCWSTR optional -> 'str16'
// pszValue : LPCWSTR optional -> 'str16'
// dwFlags : DWORD -> 'uint32_t'
// dwEnumerationContext : DWORD -> 'uint32_t'
// ppInfo : void** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("NTDSAPI.dll", {
DsReplicaGetInfo2W: { parameters: ["pointer", "i32", "buffer", "pointer", "buffer", "buffer", "u32", "u32", "pointer"], result: "u32" },
});
// lib.symbols.DsReplicaGetInfo2W(hDS, InfoType, pszObject, puuidForSourceDsaObjGuid, pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo)
// hDS : HANDLE -> "pointer"
// InfoType : DS_REPL_INFO_TYPE -> "i32"
// pszObject : LPCWSTR optional -> "buffer"
// puuidForSourceDsaObjGuid : GUID* optional -> "pointer"
// pszAttributeName : LPCWSTR optional -> "buffer"
// pszValue : LPCWSTR optional -> "buffer"
// dwFlags : DWORD -> "u32"
// dwEnumerationContext : DWORD -> "u32"
// ppInfo : void** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DsReplicaGetInfo2W(
void* hDS,
int32_t InfoType,
const uint16_t* pszObject,
void* puuidForSourceDsaObjGuid,
const uint16_t* pszAttributeName,
const uint16_t* pszValue,
uint32_t dwFlags,
uint32_t dwEnumerationContext,
void** ppInfo);
C, "NTDSAPI.dll");
// $ffi->DsReplicaGetInfo2W(hDS, InfoType, pszObject, puuidForSourceDsaObjGuid, pszAttributeName, pszValue, dwFlags, dwEnumerationContext, ppInfo);
// hDS : HANDLE
// InfoType : DS_REPL_INFO_TYPE
// pszObject : LPCWSTR optional
// puuidForSourceDsaObjGuid : GUID* optional
// pszAttributeName : LPCWSTR optional
// pszValue : LPCWSTR optional
// dwFlags : DWORD
// dwEnumerationContext : DWORD
// ppInfo : void** out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Ntdsapi extends StdCallLibrary {
Ntdsapi INSTANCE = Native.load("ntdsapi", Ntdsapi.class);
int DsReplicaGetInfo2W(
Pointer hDS, // HANDLE
int InfoType, // DS_REPL_INFO_TYPE
WString pszObject, // LPCWSTR optional
Pointer puuidForSourceDsaObjGuid, // GUID* optional
WString pszAttributeName, // LPCWSTR optional
WString pszValue, // LPCWSTR optional
int dwFlags, // DWORD
int dwEnumerationContext, // DWORD
Pointer ppInfo // void** out
);
}@[Link("ntdsapi")]
lib LibNTDSAPI
fun DsReplicaGetInfo2W = DsReplicaGetInfo2W(
hDS : Void*, # HANDLE
InfoType : Int32, # DS_REPL_INFO_TYPE
pszObject : UInt16*, # LPCWSTR optional
puuidForSourceDsaObjGuid : GUID*, # GUID* optional
pszAttributeName : UInt16*, # LPCWSTR optional
pszValue : UInt16*, # LPCWSTR optional
dwFlags : UInt32, # DWORD
dwEnumerationContext : UInt32, # DWORD
ppInfo : Void** # void** out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DsReplicaGetInfo2WNative = Uint32 Function(Pointer<Void>, Int32, Pointer<Utf16>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Uint32, Pointer<Void>);
typedef DsReplicaGetInfo2WDart = int Function(Pointer<Void>, int, Pointer<Utf16>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int, int, Pointer<Void>);
final DsReplicaGetInfo2W = DynamicLibrary.open('NTDSAPI.dll')
.lookupFunction<DsReplicaGetInfo2WNative, DsReplicaGetInfo2WDart>('DsReplicaGetInfo2W');
// hDS : HANDLE -> Pointer<Void>
// InfoType : DS_REPL_INFO_TYPE -> Int32
// pszObject : LPCWSTR optional -> Pointer<Utf16>
// puuidForSourceDsaObjGuid : GUID* optional -> Pointer<Void>
// pszAttributeName : LPCWSTR optional -> Pointer<Utf16>
// pszValue : LPCWSTR optional -> Pointer<Utf16>
// dwFlags : DWORD -> Uint32
// dwEnumerationContext : DWORD -> Uint32
// ppInfo : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DsReplicaGetInfo2W(
hDS: THandle; // HANDLE
InfoType: Integer; // DS_REPL_INFO_TYPE
pszObject: PWideChar; // LPCWSTR optional
puuidForSourceDsaObjGuid: PGUID; // GUID* optional
pszAttributeName: PWideChar; // LPCWSTR optional
pszValue: PWideChar; // LPCWSTR optional
dwFlags: DWORD; // DWORD
dwEnumerationContext: DWORD; // DWORD
ppInfo: Pointer // void** out
): DWORD; stdcall;
external 'NTDSAPI.dll' name 'DsReplicaGetInfo2W';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DsReplicaGetInfo2W"
c_DsReplicaGetInfo2W :: Ptr () -> Int32 -> CWString -> Ptr () -> CWString -> CWString -> Word32 -> Word32 -> Ptr () -> IO Word32
-- hDS : HANDLE -> Ptr ()
-- InfoType : DS_REPL_INFO_TYPE -> Int32
-- pszObject : LPCWSTR optional -> CWString
-- puuidForSourceDsaObjGuid : GUID* optional -> Ptr ()
-- pszAttributeName : LPCWSTR optional -> CWString
-- pszValue : LPCWSTR optional -> CWString
-- dwFlags : DWORD -> Word32
-- dwEnumerationContext : DWORD -> Word32
-- ppInfo : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dsreplicagetinfo2w =
foreign "DsReplicaGetInfo2W"
((ptr void) @-> int32_t @-> (ptr uint16_t) @-> (ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr void) @-> returning uint32_t)
(* hDS : HANDLE -> (ptr void) *)
(* InfoType : DS_REPL_INFO_TYPE -> int32_t *)
(* pszObject : LPCWSTR optional -> (ptr uint16_t) *)
(* puuidForSourceDsaObjGuid : GUID* optional -> (ptr void) *)
(* pszAttributeName : LPCWSTR optional -> (ptr uint16_t) *)
(* pszValue : LPCWSTR optional -> (ptr uint16_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* dwEnumerationContext : DWORD -> uint32_t *)
(* ppInfo : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ntdsapi (t "NTDSAPI.dll"))
(cffi:use-foreign-library ntdsapi)
(cffi:defcfun ("DsReplicaGetInfo2W" ds-replica-get-info2-w :convention :stdcall) :uint32
(h-ds :pointer) ; HANDLE
(info-type :int32) ; DS_REPL_INFO_TYPE
(psz-object (:string :encoding :utf-16le)) ; LPCWSTR optional
(puuid-for-source-dsa-obj-guid :pointer) ; GUID* optional
(psz-attribute-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(psz-value (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-flags :uint32) ; DWORD
(dw-enumeration-context :uint32) ; DWORD
(pp-info :pointer)) ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DsReplicaGetInfo2W = Win32::API::More->new('NTDSAPI',
'DWORD DsReplicaGetInfo2W(HANDLE hDS, int InfoType, LPCWSTR pszObject, LPVOID puuidForSourceDsaObjGuid, LPCWSTR pszAttributeName, LPCWSTR pszValue, DWORD dwFlags, DWORD dwEnumerationContext, LPVOID ppInfo)');
# my $ret = $DsReplicaGetInfo2W->Call($hDS, $InfoType, $pszObject, $puuidForSourceDsaObjGuid, $pszAttributeName, $pszValue, $dwFlags, $dwEnumerationContext, $ppInfo);
# hDS : HANDLE -> HANDLE
# InfoType : DS_REPL_INFO_TYPE -> int
# pszObject : LPCWSTR optional -> LPCWSTR
# puuidForSourceDsaObjGuid : GUID* optional -> LPVOID
# pszAttributeName : LPCWSTR optional -> LPCWSTR
# pszValue : LPCWSTR optional -> LPCWSTR
# dwFlags : DWORD -> DWORD
# dwEnumerationContext : DWORD -> DWORD
# ppInfo : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型