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

SecurityDescriptorToBinarySD

関数
セキュリティ記述子オブジェクトをバイナリ形式へ変換する。
DLLACTIVEDS.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// ACTIVEDS.dll
#include <windows.h>

HRESULT SecurityDescriptorToBinarySD(
    VARIANT vVarSecDes,
    PSECURITY_DESCRIPTOR* ppSecurityDescriptor,
    DWORD* pdwSDLength,
    LPCWSTR pszServerName,
    LPCWSTR userName,
    LPCWSTR passWord,
    DWORD dwFlags
);

パラメーター

名前方向説明
vVarSecDesVARIANTin変換元のIADsSecurityDescriptorを保持するVARIANT。
ppSecurityDescriptorPSECURITY_DESCRIPTOR*inout変換後のバイナリ形式SDを受け取るポインタのアドレス。FreeADsMemで解放する。
pdwSDLengthDWORD*inout生成されたバイナリSDのバイト長を受け取るDWORDへのポインタ。
pszServerNameLPCWSTRin対象サーバ名。アカウント解決に用いる。NULL可。
userNameLPCWSTRin認証に使うユーザー名。NULLで現在のコンテキストを使う。
passWordLPCWSTRinuserNameに対応するパスワード。NULL可。
dwFlagsDWORDin認証方法を指定するフラグ。ADS_AUTHENTICATION_ENUMの値を与える。

戻り値の型: HRESULT

各言語での呼び出し定義

// ACTIVEDS.dll
#include <windows.h>

HRESULT SecurityDescriptorToBinarySD(
    VARIANT vVarSecDes,
    PSECURITY_DESCRIPTOR* ppSecurityDescriptor,
    DWORD* pdwSDLength,
    LPCWSTR pszServerName,
    LPCWSTR userName,
    LPCWSTR passWord,
    DWORD dwFlags
);
[DllImport("ACTIVEDS.dll", ExactSpelling = true)]
static extern int SecurityDescriptorToBinarySD(
    VARIANT vVarSecDes,   // VARIANT
    IntPtr ppSecurityDescriptor,   // PSECURITY_DESCRIPTOR* in/out
    ref uint pdwSDLength,   // DWORD* in/out
    [MarshalAs(UnmanagedType.LPWStr)] string pszServerName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string userName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string passWord,   // LPCWSTR
    uint dwFlags   // DWORD
);
<DllImport("ACTIVEDS.dll", ExactSpelling:=True)>
Public Shared Function SecurityDescriptorToBinarySD(
    vVarSecDes As VARIANT,   ' VARIANT
    ppSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR* in/out
    ByRef pdwSDLength As UInteger,   ' DWORD* in/out
    <MarshalAs(UnmanagedType.LPWStr)> pszServerName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> userName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> passWord As String,   ' LPCWSTR
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' vVarSecDes : VARIANT
' ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out
' pdwSDLength : DWORD* in/out
' pszServerName : LPCWSTR
' userName : LPCWSTR
' passWord : LPCWSTR
' dwFlags : DWORD
Declare PtrSafe Function SecurityDescriptorToBinarySD Lib "activeds" ( _
    ByVal vVarSecDes As LongPtr, _
    ByVal ppSecurityDescriptor As LongPtr, _
    ByRef pdwSDLength As Long, _
    ByVal pszServerName As LongPtr, _
    ByVal userName As LongPtr, _
    ByVal passWord As LongPtr, _
    ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SecurityDescriptorToBinarySD = ctypes.windll.activeds.SecurityDescriptorToBinarySD
SecurityDescriptorToBinarySD.restype = ctypes.c_int
SecurityDescriptorToBinarySD.argtypes = [
    VARIANT,  # vVarSecDes : VARIANT
    ctypes.c_void_p,  # ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out
    ctypes.POINTER(wintypes.DWORD),  # pdwSDLength : DWORD* in/out
    wintypes.LPCWSTR,  # pszServerName : LPCWSTR
    wintypes.LPCWSTR,  # userName : LPCWSTR
    wintypes.LPCWSTR,  # passWord : LPCWSTR
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ACTIVEDS.dll')
SecurityDescriptorToBinarySD = Fiddle::Function.new(
  lib['SecurityDescriptorToBinarySD'],
  [
    Fiddle::TYPE_VOIDP,  # vVarSecDes : VARIANT
    Fiddle::TYPE_VOIDP,  # ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out
    Fiddle::TYPE_VOIDP,  # pdwSDLength : DWORD* in/out
    Fiddle::TYPE_VOIDP,  # pszServerName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # userName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # passWord : LPCWSTR
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "activeds")]
extern "system" {
    fn SecurityDescriptorToBinarySD(
        vVarSecDes: VARIANT,  // VARIANT
        ppSecurityDescriptor: *mut *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR* in/out
        pdwSDLength: *mut u32,  // DWORD* in/out
        pszServerName: *const u16,  // LPCWSTR
        userName: *const u16,  // LPCWSTR
        passWord: *const u16,  // LPCWSTR
        dwFlags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ACTIVEDS.dll")]
public static extern int SecurityDescriptorToBinarySD(VARIANT vVarSecDes, IntPtr ppSecurityDescriptor, ref uint pdwSDLength, [MarshalAs(UnmanagedType.LPWStr)] string pszServerName, [MarshalAs(UnmanagedType.LPWStr)] string userName, [MarshalAs(UnmanagedType.LPWStr)] string passWord, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ACTIVEDS_SecurityDescriptorToBinarySD' -Namespace Win32 -PassThru
# $api::SecurityDescriptorToBinarySD(vVarSecDes, ppSecurityDescriptor, pdwSDLength, pszServerName, userName, passWord, dwFlags)
#uselib "ACTIVEDS.dll"
#func global SecurityDescriptorToBinarySD "SecurityDescriptorToBinarySD" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SecurityDescriptorToBinarySD vVarSecDes, ppSecurityDescriptor, varptr(pdwSDLength), pszServerName, userName, passWord, dwFlags   ; 戻り値は stat
; vVarSecDes : VARIANT -> "sptr"
; ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> "sptr"
; pdwSDLength : DWORD* in/out -> "sptr"
; pszServerName : LPCWSTR -> "sptr"
; userName : LPCWSTR -> "sptr"
; passWord : LPCWSTR -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ACTIVEDS.dll"
#cfunc global SecurityDescriptorToBinarySD "SecurityDescriptorToBinarySD" int, sptr, var, wstr, wstr, wstr, int
; res = SecurityDescriptorToBinarySD(vVarSecDes, ppSecurityDescriptor, pdwSDLength, pszServerName, userName, passWord, dwFlags)
; vVarSecDes : VARIANT -> "int"
; ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> "sptr"
; pdwSDLength : DWORD* in/out -> "var"
; pszServerName : LPCWSTR -> "wstr"
; userName : LPCWSTR -> "wstr"
; passWord : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SecurityDescriptorToBinarySD(VARIANT vVarSecDes, PSECURITY_DESCRIPTOR* ppSecurityDescriptor, DWORD* pdwSDLength, LPCWSTR pszServerName, LPCWSTR userName, LPCWSTR passWord, DWORD dwFlags)
#uselib "ACTIVEDS.dll"
#cfunc global SecurityDescriptorToBinarySD "SecurityDescriptorToBinarySD" int, intptr, var, wstr, wstr, wstr, int
; res = SecurityDescriptorToBinarySD(vVarSecDes, ppSecurityDescriptor, pdwSDLength, pszServerName, userName, passWord, dwFlags)
; vVarSecDes : VARIANT -> "int"
; ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> "intptr"
; pdwSDLength : DWORD* in/out -> "var"
; pszServerName : LPCWSTR -> "wstr"
; userName : LPCWSTR -> "wstr"
; passWord : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	activeds = windows.NewLazySystemDLL("ACTIVEDS.dll")
	procSecurityDescriptorToBinarySD = activeds.NewProc("SecurityDescriptorToBinarySD")
)

// vVarSecDes (VARIANT), ppSecurityDescriptor (PSECURITY_DESCRIPTOR* in/out), pdwSDLength (DWORD* in/out), pszServerName (LPCWSTR), userName (LPCWSTR), passWord (LPCWSTR), dwFlags (DWORD)
r1, _, err := procSecurityDescriptorToBinarySD.Call(
	uintptr(vVarSecDes),
	uintptr(ppSecurityDescriptor),
	uintptr(pdwSDLength),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszServerName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(userName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(passWord))),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SecurityDescriptorToBinarySD(
  vVarSecDes: VARIANT;   // VARIANT
  ppSecurityDescriptor: Pointer;   // PSECURITY_DESCRIPTOR* in/out
  pdwSDLength: Pointer;   // DWORD* in/out
  pszServerName: PWideChar;   // LPCWSTR
  userName: PWideChar;   // LPCWSTR
  passWord: PWideChar;   // LPCWSTR
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'ACTIVEDS.dll' name 'SecurityDescriptorToBinarySD';
result := DllCall("ACTIVEDS\SecurityDescriptorToBinarySD"
    , "Ptr", vVarSecDes   ; VARIANT
    , "Ptr", ppSecurityDescriptor   ; PSECURITY_DESCRIPTOR* in/out
    , "Ptr", pdwSDLength   ; DWORD* in/out
    , "WStr", pszServerName   ; LPCWSTR
    , "WStr", userName   ; LPCWSTR
    , "WStr", passWord   ; LPCWSTR
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: HRESULT
●SecurityDescriptorToBinarySD(vVarSecDes, ppSecurityDescriptor, pdwSDLength, pszServerName, userName, passWord, dwFlags) = DLL("ACTIVEDS.dll", "int SecurityDescriptorToBinarySD(void*, void*, void*, char*, char*, char*, dword)")
# 呼び出し: SecurityDescriptorToBinarySD(vVarSecDes, ppSecurityDescriptor, pdwSDLength, pszServerName, userName, passWord, dwFlags)
# vVarSecDes : VARIANT -> "void*"
# ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> "void*"
# pdwSDLength : DWORD* in/out -> "void*"
# pszServerName : LPCWSTR -> "char*"
# userName : LPCWSTR -> "char*"
# passWord : LPCWSTR -> "char*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "activeds" fn SecurityDescriptorToBinarySD(
    vVarSecDes: VARIANT, // VARIANT
    ppSecurityDescriptor: ?*anyopaque, // PSECURITY_DESCRIPTOR* in/out
    pdwSDLength: [*c]u32, // DWORD* in/out
    pszServerName: [*c]const u16, // LPCWSTR
    userName: [*c]const u16, // LPCWSTR
    passWord: [*c]const u16, // LPCWSTR
    dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc SecurityDescriptorToBinarySD(
    vVarSecDes: VARIANT,  # VARIANT
    ppSecurityDescriptor: pointer,  # PSECURITY_DESCRIPTOR* in/out
    pdwSDLength: ptr uint32,  # DWORD* in/out
    pszServerName: WideCString,  # LPCWSTR
    userName: WideCString,  # LPCWSTR
    passWord: WideCString,  # LPCWSTR
    dwFlags: uint32  # DWORD
): int32 {.importc: "SecurityDescriptorToBinarySD", stdcall, dynlib: "ACTIVEDS.dll".}
pragma(lib, "activeds");
extern(Windows)
int SecurityDescriptorToBinarySD(
    VARIANT vVarSecDes,   // VARIANT
    void* ppSecurityDescriptor,   // PSECURITY_DESCRIPTOR* in/out
    uint* pdwSDLength,   // DWORD* in/out
    const(wchar)* pszServerName,   // LPCWSTR
    const(wchar)* userName,   // LPCWSTR
    const(wchar)* passWord,   // LPCWSTR
    uint dwFlags   // DWORD
);
ccall((:SecurityDescriptorToBinarySD, "ACTIVEDS.dll"), stdcall, Int32,
      (VARIANT, Ptr{Cvoid}, Ptr{UInt32}, Cwstring, Cwstring, Cwstring, UInt32),
      vVarSecDes, ppSecurityDescriptor, pdwSDLength, pszServerName, userName, passWord, dwFlags)
# vVarSecDes : VARIANT -> VARIANT
# ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> Ptr{Cvoid}
# pdwSDLength : DWORD* in/out -> Ptr{UInt32}
# pszServerName : LPCWSTR -> Cwstring
# userName : LPCWSTR -> Cwstring
# passWord : LPCWSTR -> Cwstring
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SecurityDescriptorToBinarySD(
    VARIANT vVarSecDes,
    void* ppSecurityDescriptor,
    uint32_t* pdwSDLength,
    const uint16_t* pszServerName,
    const uint16_t* userName,
    const uint16_t* passWord,
    uint32_t dwFlags);
]]
local activeds = ffi.load("activeds")
-- activeds.SecurityDescriptorToBinarySD(vVarSecDes, ppSecurityDescriptor, pdwSDLength, pszServerName, userName, passWord, dwFlags)
-- vVarSecDes : VARIANT
-- ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out
-- pdwSDLength : DWORD* in/out
-- pszServerName : LPCWSTR
-- userName : LPCWSTR
-- passWord : LPCWSTR
-- dwFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ACTIVEDS.dll');
const SecurityDescriptorToBinarySD = lib.func('__stdcall', 'SecurityDescriptorToBinarySD', 'int32_t', ['VARIANT', 'void *', 'uint32_t *', 'str16', 'str16', 'str16', 'uint32_t']);
// SecurityDescriptorToBinarySD(vVarSecDes, ppSecurityDescriptor, pdwSDLength, pszServerName, userName, passWord, dwFlags)
// vVarSecDes : VARIANT -> 'VARIANT'
// ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> 'void *'
// pdwSDLength : DWORD* in/out -> 'uint32_t *'
// pszServerName : LPCWSTR -> 'str16'
// userName : LPCWSTR -> 'str16'
// passWord : LPCWSTR -> 'str16'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ACTIVEDS.dll", {
  SecurityDescriptorToBinarySD: { parameters: ["buffer", "pointer", "pointer", "buffer", "buffer", "buffer", "u32"], result: "i32" },
});
// lib.symbols.SecurityDescriptorToBinarySD(vVarSecDes, ppSecurityDescriptor, pdwSDLength, pszServerName, userName, passWord, dwFlags)
// vVarSecDes : VARIANT -> "buffer"
// ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> "pointer"
// pdwSDLength : DWORD* in/out -> "pointer"
// pszServerName : LPCWSTR -> "buffer"
// userName : LPCWSTR -> "buffer"
// passWord : LPCWSTR -> "buffer"
// dwFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SecurityDescriptorToBinarySD(
    VARIANT vVarSecDes,
    void* ppSecurityDescriptor,
    uint32_t* pdwSDLength,
    const uint16_t* pszServerName,
    const uint16_t* userName,
    const uint16_t* passWord,
    uint32_t dwFlags);
C, "ACTIVEDS.dll");
// $ffi->SecurityDescriptorToBinarySD(vVarSecDes, ppSecurityDescriptor, pdwSDLength, pszServerName, userName, passWord, dwFlags);
// vVarSecDes : VARIANT
// ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out
// pdwSDLength : DWORD* in/out
// pszServerName : LPCWSTR
// userName : LPCWSTR
// passWord : LPCWSTR
// dwFlags : DWORD
// 構造体/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 Activeds extends StdCallLibrary {
    Activeds INSTANCE = Native.load("activeds", Activeds.class);
    int SecurityDescriptorToBinarySD(
        VARIANT /* extends Structure (by value) */ vVarSecDes,   // VARIANT
        Pointer ppSecurityDescriptor,   // PSECURITY_DESCRIPTOR* in/out
        IntByReference pdwSDLength,   // DWORD* in/out
        WString pszServerName,   // LPCWSTR
        WString userName,   // LPCWSTR
        WString passWord,   // LPCWSTR
        int dwFlags   // DWORD
    );
}
@[Link("activeds")]
lib LibACTIVEDS
  fun SecurityDescriptorToBinarySD = SecurityDescriptorToBinarySD(
    vVarSecDes : VARIANT,   # VARIANT
    ppSecurityDescriptor : Void*,   # PSECURITY_DESCRIPTOR* in/out
    pdwSDLength : UInt32*,   # DWORD* in/out
    pszServerName : UInt16*,   # LPCWSTR
    userName : UInt16*,   # LPCWSTR
    passWord : UInt16*,   # LPCWSTR
    dwFlags : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SecurityDescriptorToBinarySDNative = Int32 Function(VARIANT, Pointer<Void>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef SecurityDescriptorToBinarySDDart = int Function(int, Pointer<Void>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int);
final SecurityDescriptorToBinarySD = DynamicLibrary.open('ACTIVEDS.dll')
    .lookupFunction<SecurityDescriptorToBinarySDNative, SecurityDescriptorToBinarySDDart>('SecurityDescriptorToBinarySD');
// vVarSecDes : VARIANT -> VARIANT
// ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> Pointer<Void>
// pdwSDLength : DWORD* in/out -> Pointer<Uint32>
// pszServerName : LPCWSTR -> Pointer<Utf16>
// userName : LPCWSTR -> Pointer<Utf16>
// passWord : LPCWSTR -> Pointer<Utf16>
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SecurityDescriptorToBinarySD(
  vVarSecDes: VARIANT;   // VARIANT
  ppSecurityDescriptor: Pointer;   // PSECURITY_DESCRIPTOR* in/out
  pdwSDLength: Pointer;   // DWORD* in/out
  pszServerName: PWideChar;   // LPCWSTR
  userName: PWideChar;   // LPCWSTR
  passWord: PWideChar;   // LPCWSTR
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'ACTIVEDS.dll' name 'SecurityDescriptorToBinarySD';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SecurityDescriptorToBinarySD"
  c_SecurityDescriptorToBinarySD :: VARIANT -> Ptr () -> Ptr Word32 -> CWString -> CWString -> CWString -> Word32 -> IO Int32
-- vVarSecDes : VARIANT -> VARIANT
-- ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> Ptr ()
-- pdwSDLength : DWORD* in/out -> Ptr Word32
-- pszServerName : LPCWSTR -> CWString
-- userName : LPCWSTR -> CWString
-- passWord : LPCWSTR -> CWString
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。
open Ctypes
open Foreign

let securitydescriptortobinarysd =
  foreign "SecurityDescriptorToBinarySD"
    (VARIANT @-> (ptr void) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning int32_t)
(* vVarSecDes : VARIANT -> VARIANT *)
(* ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> (ptr void) *)
(* pdwSDLength : DWORD* in/out -> (ptr uint32_t) *)
(* pszServerName : LPCWSTR -> (ptr uint16_t) *)
(* userName : LPCWSTR -> (ptr uint16_t) *)
(* passWord : LPCWSTR -> (ptr uint16_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library activeds (t "ACTIVEDS.dll"))
(cffi:use-foreign-library activeds)

(cffi:defcfun ("SecurityDescriptorToBinarySD" security-descriptor-to-binary-sd :convention :stdcall) :int32
  (v-var-sec-des (:struct variant))   ; VARIANT
  (pp-security-descriptor :pointer)   ; PSECURITY_DESCRIPTOR* in/out
  (pdw-sdlength :pointer)   ; DWORD* in/out
  (psz-server-name (:string :encoding :utf-16le))   ; LPCWSTR
  (user-name (:string :encoding :utf-16le))   ; LPCWSTR
  (pass-word (:string :encoding :utf-16le))   ; LPCWSTR
  (dw-flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SecurityDescriptorToBinarySD = Win32::API::More->new('ACTIVEDS',
    'int SecurityDescriptorToBinarySD(LPVOID vVarSecDes, HANDLE ppSecurityDescriptor, LPVOID pdwSDLength, LPCWSTR pszServerName, LPCWSTR userName, LPCWSTR passWord, DWORD dwFlags)');
# my $ret = $SecurityDescriptorToBinarySD->Call($vVarSecDes, $ppSecurityDescriptor, $pdwSDLength, $pszServerName, $userName, $passWord, $dwFlags);
# vVarSecDes : VARIANT -> LPVOID
# ppSecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> HANDLE
# pdwSDLength : DWORD* in/out -> LPVOID
# pszServerName : LPCWSTR -> LPCWSTR
# userName : LPCWSTR -> LPCWSTR
# passWord : LPCWSTR -> LPCWSTR
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型