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

DsWriteAccountSpnW

関数
アカウントオブジェクトにSPNを書き込む(Unicode版)。
DLLNTDSAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD DsWriteAccountSpnW(
    HANDLE hDS,
    DS_SPN_WRITE_OP Operation,
    LPCWSTR pszAccount,
    DWORD cSpn,
    LPCWSTR* rpszSpn
);

パラメーター

名前方向
hDSHANDLEin
OperationDS_SPN_WRITE_OPin
pszAccountLPCWSTRin
cSpnDWORDin
rpszSpnLPCWSTR*in

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DsWriteAccountSpnW(
    HANDLE hDS,
    DS_SPN_WRITE_OP Operation,
    LPCWSTR pszAccount,
    DWORD cSpn,
    LPCWSTR* rpszSpn
);
[DllImport("NTDSAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DsWriteAccountSpnW(
    IntPtr hDS,   // HANDLE
    int Operation,   // DS_SPN_WRITE_OP
    [MarshalAs(UnmanagedType.LPWStr)] string pszAccount,   // LPCWSTR
    uint cSpn,   // DWORD
    IntPtr rpszSpn   // LPCWSTR*
);
<DllImport("NTDSAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DsWriteAccountSpnW(
    hDS As IntPtr,   ' HANDLE
    Operation As Integer,   ' DS_SPN_WRITE_OP
    <MarshalAs(UnmanagedType.LPWStr)> pszAccount As String,   ' LPCWSTR
    cSpn As UInteger,   ' DWORD
    rpszSpn As IntPtr   ' LPCWSTR*
) As UInteger
End Function
' hDS : HANDLE
' Operation : DS_SPN_WRITE_OP
' pszAccount : LPCWSTR
' cSpn : DWORD
' rpszSpn : LPCWSTR*
Declare PtrSafe Function DsWriteAccountSpnW Lib "ntdsapi" ( _
    ByVal hDS As LongPtr, _
    ByVal Operation As Long, _
    ByVal pszAccount As LongPtr, _
    ByVal cSpn As Long, _
    ByVal rpszSpn 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

DsWriteAccountSpnW = ctypes.windll.ntdsapi.DsWriteAccountSpnW
DsWriteAccountSpnW.restype = wintypes.DWORD
DsWriteAccountSpnW.argtypes = [
    wintypes.HANDLE,  # hDS : HANDLE
    ctypes.c_int,  # Operation : DS_SPN_WRITE_OP
    wintypes.LPCWSTR,  # pszAccount : LPCWSTR
    wintypes.DWORD,  # cSpn : DWORD
    ctypes.c_void_p,  # rpszSpn : LPCWSTR*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NTDSAPI.dll')
DsWriteAccountSpnW = Fiddle::Function.new(
  lib['DsWriteAccountSpnW'],
  [
    Fiddle::TYPE_VOIDP,  # hDS : HANDLE
    Fiddle::TYPE_INT,  # Operation : DS_SPN_WRITE_OP
    Fiddle::TYPE_VOIDP,  # pszAccount : LPCWSTR
    -Fiddle::TYPE_INT,  # cSpn : DWORD
    Fiddle::TYPE_VOIDP,  # rpszSpn : LPCWSTR*
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "ntdsapi")]
extern "system" {
    fn DsWriteAccountSpnW(
        hDS: *mut core::ffi::c_void,  // HANDLE
        Operation: i32,  // DS_SPN_WRITE_OP
        pszAccount: *const u16,  // LPCWSTR
        cSpn: u32,  // DWORD
        rpszSpn: *const *const u16  // LPCWSTR*
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NTDSAPI.dll", CharSet = CharSet.Unicode)]
public static extern uint DsWriteAccountSpnW(IntPtr hDS, int Operation, [MarshalAs(UnmanagedType.LPWStr)] string pszAccount, uint cSpn, IntPtr rpszSpn);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NTDSAPI_DsWriteAccountSpnW' -Namespace Win32 -PassThru
# $api::DsWriteAccountSpnW(hDS, Operation, pszAccount, cSpn, rpszSpn)
#uselib "NTDSAPI.dll"
#func global DsWriteAccountSpnW "DsWriteAccountSpnW" wptr, wptr, wptr, wptr, wptr
; DsWriteAccountSpnW hDS, Operation, pszAccount, cSpn, varptr(rpszSpn)   ; 戻り値は stat
; hDS : HANDLE -> "wptr"
; Operation : DS_SPN_WRITE_OP -> "wptr"
; pszAccount : LPCWSTR -> "wptr"
; cSpn : DWORD -> "wptr"
; rpszSpn : LPCWSTR* -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "NTDSAPI.dll"
#cfunc global DsWriteAccountSpnW "DsWriteAccountSpnW" sptr, int, wstr, int, var
; res = DsWriteAccountSpnW(hDS, Operation, pszAccount, cSpn, rpszSpn)
; hDS : HANDLE -> "sptr"
; Operation : DS_SPN_WRITE_OP -> "int"
; pszAccount : LPCWSTR -> "wstr"
; cSpn : DWORD -> "int"
; rpszSpn : LPCWSTR* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD DsWriteAccountSpnW(HANDLE hDS, DS_SPN_WRITE_OP Operation, LPCWSTR pszAccount, DWORD cSpn, LPCWSTR* rpszSpn)
#uselib "NTDSAPI.dll"
#cfunc global DsWriteAccountSpnW "DsWriteAccountSpnW" intptr, int, wstr, int, var
; res = DsWriteAccountSpnW(hDS, Operation, pszAccount, cSpn, rpszSpn)
; hDS : HANDLE -> "intptr"
; Operation : DS_SPN_WRITE_OP -> "int"
; pszAccount : LPCWSTR -> "wstr"
; cSpn : DWORD -> "int"
; rpszSpn : LPCWSTR* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
	procDsWriteAccountSpnW = ntdsapi.NewProc("DsWriteAccountSpnW")
)

// hDS (HANDLE), Operation (DS_SPN_WRITE_OP), pszAccount (LPCWSTR), cSpn (DWORD), rpszSpn (LPCWSTR*)
r1, _, err := procDsWriteAccountSpnW.Call(
	uintptr(hDS),
	uintptr(Operation),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszAccount))),
	uintptr(cSpn),
	uintptr(rpszSpn),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DsWriteAccountSpnW(
  hDS: THandle;   // HANDLE
  Operation: Integer;   // DS_SPN_WRITE_OP
  pszAccount: PWideChar;   // LPCWSTR
  cSpn: DWORD;   // DWORD
  rpszSpn: PPWideChar   // LPCWSTR*
): DWORD; stdcall;
  external 'NTDSAPI.dll' name 'DsWriteAccountSpnW';
result := DllCall("NTDSAPI\DsWriteAccountSpnW"
    , "Ptr", hDS   ; HANDLE
    , "Int", Operation   ; DS_SPN_WRITE_OP
    , "WStr", pszAccount   ; LPCWSTR
    , "UInt", cSpn   ; DWORD
    , "Ptr", rpszSpn   ; LPCWSTR*
    , "UInt")   ; return: DWORD
●DsWriteAccountSpnW(hDS, Operation, pszAccount, cSpn, rpszSpn) = DLL("NTDSAPI.dll", "dword DsWriteAccountSpnW(void*, int, char*, dword, void*)")
# 呼び出し: DsWriteAccountSpnW(hDS, Operation, pszAccount, cSpn, rpszSpn)
# hDS : HANDLE -> "void*"
# Operation : DS_SPN_WRITE_OP -> "int"
# pszAccount : LPCWSTR -> "char*"
# cSpn : DWORD -> "dword"
# rpszSpn : LPCWSTR* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。