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

DsCrackSpnW

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

シグネチャ

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

DWORD DsCrackSpnW(
    LPCWSTR pszSpn,
    DWORD* pcServiceClass,   // optional
    LPWSTR ServiceClass,   // optional
    DWORD* pcServiceName,   // optional
    LPWSTR ServiceName,   // optional
    DWORD* pcInstanceName,   // optional
    LPWSTR InstanceName,   // optional
    WORD* pInstancePort   // optional
);

パラメーター

名前方向
pszSpnLPCWSTRin
pcServiceClassDWORD*inoutoptional
ServiceClassLPWSTRoutoptional
pcServiceNameDWORD*inoutoptional
ServiceNameLPWSTRoutoptional
pcInstanceNameDWORD*inoutoptional
InstanceNameLPWSTRoutoptional
pInstancePortWORD*outoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DsCrackSpnW = ctypes.windll.dsparse.DsCrackSpnW
DsCrackSpnW.restype = wintypes.DWORD
DsCrackSpnW.argtypes = [
    wintypes.LPCWSTR,  # pszSpn : LPCWSTR
    ctypes.POINTER(wintypes.DWORD),  # pcServiceClass : DWORD* optional, in/out
    wintypes.LPWSTR,  # ServiceClass : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcServiceName : DWORD* optional, in/out
    wintypes.LPWSTR,  # ServiceName : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcInstanceName : DWORD* optional, in/out
    wintypes.LPWSTR,  # InstanceName : LPWSTR optional, out
    ctypes.POINTER(ctypes.c_ushort),  # pInstancePort : WORD* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dsparse = windows.NewLazySystemDLL("DSPARSE.dll")
	procDsCrackSpnW = dsparse.NewProc("DsCrackSpnW")
)

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