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

DsMakeSpnA

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

シグネチャ

// DSPARSE.dll  (ANSI / -A)
#include <windows.h>

DWORD DsMakeSpnA(
    LPCSTR ServiceClass,
    LPCSTR ServiceName,
    LPCSTR InstanceName,   // optional
    WORD InstancePort,
    LPCSTR Referrer,   // optional
    DWORD* pcSpnLength,
    LPSTR pszSpn   // optional
);

パラメーター

名前方向
ServiceClassLPCSTRin
ServiceNameLPCSTRin
InstanceNameLPCSTRinoptional
InstancePortWORDin
ReferrerLPCSTRinoptional
pcSpnLengthDWORD*inout
pszSpnLPSTRoutoptional

戻り値の型: DWORD

各言語での呼び出し定義

// DSPARSE.dll  (ANSI / -A)
#include <windows.h>

DWORD DsMakeSpnA(
    LPCSTR ServiceClass,
    LPCSTR ServiceName,
    LPCSTR InstanceName,   // optional
    WORD InstancePort,
    LPCSTR Referrer,   // optional
    DWORD* pcSpnLength,
    LPSTR pszSpn   // optional
);
[DllImport("DSPARSE.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint DsMakeSpnA(
    [MarshalAs(UnmanagedType.LPStr)] string ServiceClass,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string ServiceName,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string InstanceName,   // LPCSTR optional
    ushort InstancePort,   // WORD
    [MarshalAs(UnmanagedType.LPStr)] string Referrer,   // LPCSTR optional
    ref uint pcSpnLength,   // DWORD* in/out
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszSpn   // LPSTR optional, out
);
<DllImport("DSPARSE.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DsMakeSpnA(
    <MarshalAs(UnmanagedType.LPStr)> ServiceClass As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> ServiceName As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> InstanceName As String,   ' LPCSTR optional
    InstancePort As UShort,   ' WORD
    <MarshalAs(UnmanagedType.LPStr)> Referrer As String,   ' LPCSTR optional
    ByRef pcSpnLength As UInteger,   ' DWORD* in/out
    <MarshalAs(UnmanagedType.LPStr)> pszSpn As System.Text.StringBuilder   ' LPSTR optional, out
) As UInteger
End Function
' ServiceClass : LPCSTR
' ServiceName : LPCSTR
' InstanceName : LPCSTR optional
' InstancePort : WORD
' Referrer : LPCSTR optional
' pcSpnLength : DWORD* in/out
' pszSpn : LPSTR optional, out
Declare PtrSafe Function DsMakeSpnA Lib "dsparse" ( _
    ByVal ServiceClass As String, _
    ByVal ServiceName As String, _
    ByVal InstanceName As String, _
    ByVal InstancePort As Integer, _
    ByVal Referrer As String, _
    ByRef pcSpnLength As Long, _
    ByVal pszSpn As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	dsparse = windows.NewLazySystemDLL("DSPARSE.dll")
	procDsMakeSpnA = dsparse.NewProc("DsMakeSpnA")
)

// ServiceClass (LPCSTR), ServiceName (LPCSTR), InstanceName (LPCSTR optional), InstancePort (WORD), Referrer (LPCSTR optional), pcSpnLength (DWORD* in/out), pszSpn (LPSTR optional, out)
r1, _, err := procDsMakeSpnA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(ServiceClass))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(ServiceName))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(InstanceName))),
	uintptr(InstancePort),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(Referrer))),
	uintptr(pcSpnLength),
	uintptr(pszSpn),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DsMakeSpnA(
  ServiceClass: PAnsiChar;   // LPCSTR
  ServiceName: PAnsiChar;   // LPCSTR
  InstanceName: PAnsiChar;   // LPCSTR optional
  InstancePort: Word;   // WORD
  Referrer: PAnsiChar;   // LPCSTR optional
  pcSpnLength: Pointer;   // DWORD* in/out
  pszSpn: PAnsiChar   // LPSTR optional, out
): DWORD; stdcall;
  external 'DSPARSE.dll' name 'DsMakeSpnA';
result := DllCall("DSPARSE\DsMakeSpnA"
    , "AStr", ServiceClass   ; LPCSTR
    , "AStr", ServiceName   ; LPCSTR
    , "AStr", InstanceName   ; LPCSTR optional
    , "UShort", InstancePort   ; WORD
    , "AStr", Referrer   ; LPCSTR optional
    , "Ptr", pcSpnLength   ; DWORD* in/out
    , "Ptr", pszSpn   ; LPSTR optional, out
    , "UInt")   ; return: DWORD
●DsMakeSpnA(ServiceClass, ServiceName, InstanceName, InstancePort, Referrer, pcSpnLength, pszSpn) = DLL("DSPARSE.dll", "dword DsMakeSpnA(char*, char*, char*, int, char*, void*, char*)")
# 呼び出し: DsMakeSpnA(ServiceClass, ServiceName, InstanceName, InstancePort, Referrer, pcSpnLength, pszSpn)
# ServiceClass : LPCSTR -> "char*"
# ServiceName : LPCSTR -> "char*"
# InstanceName : LPCSTR optional -> "char*"
# InstancePort : WORD -> "int"
# Referrer : LPCSTR optional -> "char*"
# pcSpnLength : DWORD* in/out -> "void*"
# pszSpn : LPSTR optional, out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。