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

DsClientMakeSpnForTargetServerW

関数
対象サーバー向けのクライアント用SPNを生成する(Unicode版)。
DLLNTDSAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD DsClientMakeSpnForTargetServerW(
    LPCWSTR ServiceClass,
    LPCWSTR ServiceName,
    DWORD* pcSpnLength,
    LPWSTR pszSpn
);

パラメーター

名前方向
ServiceClassLPCWSTRin
ServiceNameLPCWSTRin
pcSpnLengthDWORD*inout
pszSpnLPWSTRout

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DsClientMakeSpnForTargetServerW(
    LPCWSTR ServiceClass,
    LPCWSTR ServiceName,
    DWORD* pcSpnLength,
    LPWSTR pszSpn
);
[DllImport("NTDSAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DsClientMakeSpnForTargetServerW(
    [MarshalAs(UnmanagedType.LPWStr)] string ServiceClass,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string ServiceName,   // LPCWSTR
    ref uint pcSpnLength,   // DWORD* in/out
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszSpn   // LPWSTR out
);
<DllImport("NTDSAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DsClientMakeSpnForTargetServerW(
    <MarshalAs(UnmanagedType.LPWStr)> ServiceClass As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> ServiceName As String,   ' LPCWSTR
    ByRef pcSpnLength As UInteger,   ' DWORD* in/out
    <MarshalAs(UnmanagedType.LPWStr)> pszSpn As System.Text.StringBuilder   ' LPWSTR out
) As UInteger
End Function
' ServiceClass : LPCWSTR
' ServiceName : LPCWSTR
' pcSpnLength : DWORD* in/out
' pszSpn : LPWSTR out
Declare PtrSafe Function DsClientMakeSpnForTargetServerW Lib "ntdsapi" ( _
    ByVal ServiceClass As LongPtr, _
    ByVal ServiceName As LongPtr, _
    ByRef pcSpnLength As Long, _
    ByVal pszSpn 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

DsClientMakeSpnForTargetServerW = ctypes.windll.ntdsapi.DsClientMakeSpnForTargetServerW
DsClientMakeSpnForTargetServerW.restype = wintypes.DWORD
DsClientMakeSpnForTargetServerW.argtypes = [
    wintypes.LPCWSTR,  # ServiceClass : LPCWSTR
    wintypes.LPCWSTR,  # ServiceName : LPCWSTR
    ctypes.POINTER(wintypes.DWORD),  # pcSpnLength : DWORD* in/out
    wintypes.LPWSTR,  # pszSpn : LPWSTR out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
	procDsClientMakeSpnForTargetServerW = ntdsapi.NewProc("DsClientMakeSpnForTargetServerW")
)

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