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

DsMakeSpnW

関数
構成要素からサービスプリンシパル名を生成する(Unicode版)。
DLLDSPARSE.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD DsMakeSpnW(
    LPCWSTR ServiceClass,
    LPCWSTR ServiceName,
    LPCWSTR InstanceName,   // optional
    WORD InstancePort,
    LPCWSTR Referrer,   // optional
    DWORD* pcSpnLength,
    LPWSTR pszSpn   // optional
);

パラメーター

名前方向
ServiceClassLPCWSTRin
ServiceNameLPCWSTRin
InstanceNameLPCWSTRinoptional
InstancePortWORDin
ReferrerLPCWSTRinoptional
pcSpnLengthDWORD*inout
pszSpnLPWSTRoutoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DsMakeSpnW = ctypes.windll.dsparse.DsMakeSpnW
DsMakeSpnW.restype = wintypes.DWORD
DsMakeSpnW.argtypes = [
    wintypes.LPCWSTR,  # ServiceClass : LPCWSTR
    wintypes.LPCWSTR,  # ServiceName : LPCWSTR
    wintypes.LPCWSTR,  # InstanceName : LPCWSTR optional
    ctypes.c_ushort,  # InstancePort : WORD
    wintypes.LPCWSTR,  # Referrer : LPCWSTR optional
    ctypes.POINTER(wintypes.DWORD),  # pcSpnLength : DWORD* in/out
    wintypes.LPWSTR,  # pszSpn : LPWSTR optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dsparse = windows.NewLazySystemDLL("DSPARSE.dll")
	procDsMakeSpnW = dsparse.NewProc("DsMakeSpnW")
)

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