Win32 API 日本語リファレンス
ホームSecurity.Authentication.Identity › SspiMarshalAuthIdentity

SspiMarshalAuthIdentity

関数
認証情報構造体をバイト配列へマーシャリングする。
DLLSECUR32.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

// SECUR32.dll
#include <windows.h>

HRESULT SspiMarshalAuthIdentity(
    void* AuthIdentity,
    DWORD* AuthIdentityLength,
    CHAR** AuthIdentityByteArray
);

パラメーター

名前方向説明
AuthIdentityvoid*inマーシャリングする元の認証ID構造体へのポインタ。
AuthIdentityLengthDWORD*out出力。生成されたバイト配列の長さ(バイト数)を受け取るDWORDへのポインタ。
AuthIdentityByteArrayCHAR**out出力。シリアライズされた認証IDのバイト配列を受け取るポインタ。SspiLocalFreeで解放する。

戻り値の型: HRESULT

各言語での呼び出し定義

// SECUR32.dll
#include <windows.h>

HRESULT SspiMarshalAuthIdentity(
    void* AuthIdentity,
    DWORD* AuthIdentityLength,
    CHAR** AuthIdentityByteArray
);
[DllImport("SECUR32.dll", ExactSpelling = true)]
static extern int SspiMarshalAuthIdentity(
    IntPtr AuthIdentity,   // void*
    out uint AuthIdentityLength,   // DWORD* out
    IntPtr AuthIdentityByteArray   // CHAR** out
);
<DllImport("SECUR32.dll", ExactSpelling:=True)>
Public Shared Function SspiMarshalAuthIdentity(
    AuthIdentity As IntPtr,   ' void*
    <Out> ByRef AuthIdentityLength As UInteger,   ' DWORD* out
    AuthIdentityByteArray As IntPtr   ' CHAR** out
) As Integer
End Function
' AuthIdentity : void*
' AuthIdentityLength : DWORD* out
' AuthIdentityByteArray : CHAR** out
Declare PtrSafe Function SspiMarshalAuthIdentity Lib "secur32" ( _
    ByVal AuthIdentity As LongPtr, _
    ByRef AuthIdentityLength As Long, _
    ByVal AuthIdentityByteArray As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SspiMarshalAuthIdentity = ctypes.windll.secur32.SspiMarshalAuthIdentity
SspiMarshalAuthIdentity.restype = ctypes.c_int
SspiMarshalAuthIdentity.argtypes = [
    ctypes.POINTER(None),  # AuthIdentity : void*
    ctypes.POINTER(wintypes.DWORD),  # AuthIdentityLength : DWORD* out
    ctypes.c_void_p,  # AuthIdentityByteArray : CHAR** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SECUR32.dll')
SspiMarshalAuthIdentity = Fiddle::Function.new(
  lib['SspiMarshalAuthIdentity'],
  [
    Fiddle::TYPE_VOIDP,  # AuthIdentity : void*
    Fiddle::TYPE_VOIDP,  # AuthIdentityLength : DWORD* out
    Fiddle::TYPE_VOIDP,  # AuthIdentityByteArray : CHAR** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "secur32")]
extern "system" {
    fn SspiMarshalAuthIdentity(
        AuthIdentity: *mut (),  // void*
        AuthIdentityLength: *mut u32,  // DWORD* out
        AuthIdentityByteArray: *mut *mut i8  // CHAR** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SECUR32.dll")]
public static extern int SspiMarshalAuthIdentity(IntPtr AuthIdentity, out uint AuthIdentityLength, IntPtr AuthIdentityByteArray);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SECUR32_SspiMarshalAuthIdentity' -Namespace Win32 -PassThru
# $api::SspiMarshalAuthIdentity(AuthIdentity, AuthIdentityLength, AuthIdentityByteArray)
#uselib "SECUR32.dll"
#func global SspiMarshalAuthIdentity "SspiMarshalAuthIdentity" sptr, sptr, sptr
; SspiMarshalAuthIdentity AuthIdentity, varptr(AuthIdentityLength), varptr(AuthIdentityByteArray)   ; 戻り値は stat
; AuthIdentity : void* -> "sptr"
; AuthIdentityLength : DWORD* out -> "sptr"
; AuthIdentityByteArray : CHAR** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SECUR32.dll"
#cfunc global SspiMarshalAuthIdentity "SspiMarshalAuthIdentity" sptr, var, var
; res = SspiMarshalAuthIdentity(AuthIdentity, AuthIdentityLength, AuthIdentityByteArray)
; AuthIdentity : void* -> "sptr"
; AuthIdentityLength : DWORD* out -> "var"
; AuthIdentityByteArray : CHAR** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SspiMarshalAuthIdentity(void* AuthIdentity, DWORD* AuthIdentityLength, CHAR** AuthIdentityByteArray)
#uselib "SECUR32.dll"
#cfunc global SspiMarshalAuthIdentity "SspiMarshalAuthIdentity" intptr, var, var
; res = SspiMarshalAuthIdentity(AuthIdentity, AuthIdentityLength, AuthIdentityByteArray)
; AuthIdentity : void* -> "intptr"
; AuthIdentityLength : DWORD* out -> "var"
; AuthIdentityByteArray : CHAR** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	secur32 = windows.NewLazySystemDLL("SECUR32.dll")
	procSspiMarshalAuthIdentity = secur32.NewProc("SspiMarshalAuthIdentity")
)

// AuthIdentity (void*), AuthIdentityLength (DWORD* out), AuthIdentityByteArray (CHAR** out)
r1, _, err := procSspiMarshalAuthIdentity.Call(
	uintptr(AuthIdentity),
	uintptr(AuthIdentityLength),
	uintptr(AuthIdentityByteArray),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SspiMarshalAuthIdentity(
  AuthIdentity: Pointer;   // void*
  AuthIdentityLength: Pointer;   // DWORD* out
  AuthIdentityByteArray: Pointer   // CHAR** out
): Integer; stdcall;
  external 'SECUR32.dll' name 'SspiMarshalAuthIdentity';
result := DllCall("SECUR32\SspiMarshalAuthIdentity"
    , "Ptr", AuthIdentity   ; void*
    , "Ptr", AuthIdentityLength   ; DWORD* out
    , "Ptr", AuthIdentityByteArray   ; CHAR** out
    , "Int")   ; return: HRESULT
●SspiMarshalAuthIdentity(AuthIdentity, AuthIdentityLength, AuthIdentityByteArray) = DLL("SECUR32.dll", "int SspiMarshalAuthIdentity(void*, void*, void*)")
# 呼び出し: SspiMarshalAuthIdentity(AuthIdentity, AuthIdentityLength, AuthIdentityByteArray)
# AuthIdentity : void* -> "void*"
# AuthIdentityLength : DWORD* out -> "void*"
# AuthIdentityByteArray : CHAR** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "secur32" fn SspiMarshalAuthIdentity(
    AuthIdentity: ?*anyopaque, // void*
    AuthIdentityLength: [*c]u32, // DWORD* out
    AuthIdentityByteArray: [*c][*c]i8 // CHAR** out
) callconv(std.os.windows.WINAPI) i32;
proc SspiMarshalAuthIdentity(
    AuthIdentity: pointer,  # void*
    AuthIdentityLength: ptr uint32,  # DWORD* out
    AuthIdentityByteArray: ptr int8  # CHAR** out
): int32 {.importc: "SspiMarshalAuthIdentity", stdcall, dynlib: "SECUR32.dll".}
pragma(lib, "secur32");
extern(Windows)
int SspiMarshalAuthIdentity(
    void* AuthIdentity,   // void*
    uint* AuthIdentityLength,   // DWORD* out
    byte** AuthIdentityByteArray   // CHAR** out
);
ccall((:SspiMarshalAuthIdentity, "SECUR32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{UInt32}, Ptr{Int8}),
      AuthIdentity, AuthIdentityLength, AuthIdentityByteArray)
# AuthIdentity : void* -> Ptr{Cvoid}
# AuthIdentityLength : DWORD* out -> Ptr{UInt32}
# AuthIdentityByteArray : CHAR** out -> Ptr{Int8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SspiMarshalAuthIdentity(
    void* AuthIdentity,
    uint32_t* AuthIdentityLength,
    int8_t** AuthIdentityByteArray);
]]
local secur32 = ffi.load("secur32")
-- secur32.SspiMarshalAuthIdentity(AuthIdentity, AuthIdentityLength, AuthIdentityByteArray)
-- AuthIdentity : void*
-- AuthIdentityLength : DWORD* out
-- AuthIdentityByteArray : CHAR** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SECUR32.dll');
const SspiMarshalAuthIdentity = lib.func('__stdcall', 'SspiMarshalAuthIdentity', 'int32_t', ['void *', 'uint32_t *', 'int8_t *']);
// SspiMarshalAuthIdentity(AuthIdentity, AuthIdentityLength, AuthIdentityByteArray)
// AuthIdentity : void* -> 'void *'
// AuthIdentityLength : DWORD* out -> 'uint32_t *'
// AuthIdentityByteArray : CHAR** out -> 'int8_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SECUR32.dll", {
  SspiMarshalAuthIdentity: { parameters: ["pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SspiMarshalAuthIdentity(AuthIdentity, AuthIdentityLength, AuthIdentityByteArray)
// AuthIdentity : void* -> "pointer"
// AuthIdentityLength : DWORD* out -> "pointer"
// AuthIdentityByteArray : CHAR** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SspiMarshalAuthIdentity(
    void* AuthIdentity,
    uint32_t* AuthIdentityLength,
    int8_t** AuthIdentityByteArray);
C, "SECUR32.dll");
// $ffi->SspiMarshalAuthIdentity(AuthIdentity, AuthIdentityLength, AuthIdentityByteArray);
// AuthIdentity : void*
// AuthIdentityLength : DWORD* out
// AuthIdentityByteArray : CHAR** out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Secur32 extends StdCallLibrary {
    Secur32 INSTANCE = Native.load("secur32", Secur32.class);
    int SspiMarshalAuthIdentity(
        Pointer AuthIdentity,   // void*
        IntByReference AuthIdentityLength,   // DWORD* out
        Pointer AuthIdentityByteArray   // CHAR** out
    );
}
@[Link("secur32")]
lib LibSECUR32
  fun SspiMarshalAuthIdentity = SspiMarshalAuthIdentity(
    AuthIdentity : Void*,   # void*
    AuthIdentityLength : UInt32*,   # DWORD* out
    AuthIdentityByteArray : Int8**   # CHAR** out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SspiMarshalAuthIdentityNative = Int32 Function(Pointer<Void>, Pointer<Uint32>, Pointer<Int8>);
typedef SspiMarshalAuthIdentityDart = int Function(Pointer<Void>, Pointer<Uint32>, Pointer<Int8>);
final SspiMarshalAuthIdentity = DynamicLibrary.open('SECUR32.dll')
    .lookupFunction<SspiMarshalAuthIdentityNative, SspiMarshalAuthIdentityDart>('SspiMarshalAuthIdentity');
// AuthIdentity : void* -> Pointer<Void>
// AuthIdentityLength : DWORD* out -> Pointer<Uint32>
// AuthIdentityByteArray : CHAR** out -> Pointer<Int8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SspiMarshalAuthIdentity(
  AuthIdentity: Pointer;   // void*
  AuthIdentityLength: Pointer;   // DWORD* out
  AuthIdentityByteArray: Pointer   // CHAR** out
): Integer; stdcall;
  external 'SECUR32.dll' name 'SspiMarshalAuthIdentity';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SspiMarshalAuthIdentity"
  c_SspiMarshalAuthIdentity :: Ptr () -> Ptr Word32 -> Ptr Int8 -> IO Int32
-- AuthIdentity : void* -> Ptr ()
-- AuthIdentityLength : DWORD* out -> Ptr Word32
-- AuthIdentityByteArray : CHAR** out -> Ptr Int8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sspimarshalauthidentity =
  foreign "SspiMarshalAuthIdentity"
    ((ptr void) @-> (ptr uint32_t) @-> (ptr int8_t) @-> returning int32_t)
(* AuthIdentity : void* -> (ptr void) *)
(* AuthIdentityLength : DWORD* out -> (ptr uint32_t) *)
(* AuthIdentityByteArray : CHAR** out -> (ptr int8_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library secur32 (t "SECUR32.dll"))
(cffi:use-foreign-library secur32)

(cffi:defcfun ("SspiMarshalAuthIdentity" sspi-marshal-auth-identity :convention :stdcall) :int32
  (auth-identity :pointer)   ; void*
  (auth-identity-length :pointer)   ; DWORD* out
  (auth-identity-byte-array :pointer))   ; CHAR** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SspiMarshalAuthIdentity = Win32::API::More->new('SECUR32',
    'int SspiMarshalAuthIdentity(LPVOID AuthIdentity, LPVOID AuthIdentityLength, LPVOID AuthIdentityByteArray)');
# my $ret = $SspiMarshalAuthIdentity->Call($AuthIdentity, $AuthIdentityLength, $AuthIdentityByteArray);
# AuthIdentity : void* -> LPVOID
# AuthIdentityLength : DWORD* out -> LPVOID
# AuthIdentityByteArray : CHAR** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。