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

SspiEncodeAuthIdentityAsStrings

関数
認証情報構造体をユーザー名やドメイン名などの文字列に展開する。
DLLSECUR32.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT SspiEncodeAuthIdentityAsStrings(
    void* pAuthIdentity,
    LPCWSTR* ppszUserName,
    LPCWSTR* ppszDomainName,
    LPCWSTR* ppszPackedCredentialsString   // optional
);

パラメーター

名前方向説明
pAuthIdentityvoid*in文字列へ変換する元の認証ID構造体へのポインタ。
ppszUserNameLPCWSTR*out出力。認証IDから抽出したユーザー名文字列を受け取るポインタ。SspiLocalFreeで解放する。
ppszDomainNameLPCWSTR*out出力。認証IDから抽出したドメイン名文字列を受け取るポインタ。SspiLocalFreeで解放する。
ppszPackedCredentialsStringLPCWSTR*outoptional出力。パスワード等を含むパック済み資格情報文字列を受け取るポインタ。SspiLocalFreeで解放する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SspiEncodeAuthIdentityAsStrings(
    void* pAuthIdentity,
    LPCWSTR* ppszUserName,
    LPCWSTR* ppszDomainName,
    LPCWSTR* ppszPackedCredentialsString   // optional
);
[DllImport("SECUR32.dll", ExactSpelling = true)]
static extern int SspiEncodeAuthIdentityAsStrings(
    IntPtr pAuthIdentity,   // void*
    IntPtr ppszUserName,   // LPCWSTR* out
    IntPtr ppszDomainName,   // LPCWSTR* out
    IntPtr ppszPackedCredentialsString   // LPCWSTR* optional, out
);
<DllImport("SECUR32.dll", ExactSpelling:=True)>
Public Shared Function SspiEncodeAuthIdentityAsStrings(
    pAuthIdentity As IntPtr,   ' void*
    ppszUserName As IntPtr,   ' LPCWSTR* out
    ppszDomainName As IntPtr,   ' LPCWSTR* out
    ppszPackedCredentialsString As IntPtr   ' LPCWSTR* optional, out
) As Integer
End Function
' pAuthIdentity : void*
' ppszUserName : LPCWSTR* out
' ppszDomainName : LPCWSTR* out
' ppszPackedCredentialsString : LPCWSTR* optional, out
Declare PtrSafe Function SspiEncodeAuthIdentityAsStrings Lib "secur32" ( _
    ByVal pAuthIdentity As LongPtr, _
    ByVal ppszUserName As LongPtr, _
    ByVal ppszDomainName As LongPtr, _
    ByVal ppszPackedCredentialsString As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SspiEncodeAuthIdentityAsStrings = ctypes.windll.secur32.SspiEncodeAuthIdentityAsStrings
SspiEncodeAuthIdentityAsStrings.restype = ctypes.c_int
SspiEncodeAuthIdentityAsStrings.argtypes = [
    ctypes.POINTER(None),  # pAuthIdentity : void*
    ctypes.c_void_p,  # ppszUserName : LPCWSTR* out
    ctypes.c_void_p,  # ppszDomainName : LPCWSTR* out
    ctypes.c_void_p,  # ppszPackedCredentialsString : LPCWSTR* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	secur32 = windows.NewLazySystemDLL("SECUR32.dll")
	procSspiEncodeAuthIdentityAsStrings = secur32.NewProc("SspiEncodeAuthIdentityAsStrings")
)

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

extern "secur32" fn SspiEncodeAuthIdentityAsStrings(
    pAuthIdentity: ?*anyopaque, // void*
    ppszUserName: [*c][*c]u16, // LPCWSTR* out
    ppszDomainName: [*c][*c]u16, // LPCWSTR* out
    ppszPackedCredentialsString: [*c][*c]u16 // LPCWSTR* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc SspiEncodeAuthIdentityAsStrings(
    pAuthIdentity: pointer,  # void*
    ppszUserName: ptr WideCString,  # LPCWSTR* out
    ppszDomainName: ptr WideCString,  # LPCWSTR* out
    ppszPackedCredentialsString: ptr WideCString  # LPCWSTR* optional, out
): int32 {.importc: "SspiEncodeAuthIdentityAsStrings", stdcall, dynlib: "SECUR32.dll".}
pragma(lib, "secur32");
extern(Windows)
int SspiEncodeAuthIdentityAsStrings(
    void* pAuthIdentity,   // void*
    wchar** ppszUserName,   // LPCWSTR* out
    wchar** ppszDomainName,   // LPCWSTR* out
    wchar** ppszPackedCredentialsString   // LPCWSTR* optional, out
);
ccall((:SspiEncodeAuthIdentityAsStrings, "SECUR32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Ptr{UInt16}}, Ptr{Ptr{UInt16}}, Ptr{Ptr{UInt16}}),
      pAuthIdentity, ppszUserName, ppszDomainName, ppszPackedCredentialsString)
# pAuthIdentity : void* -> Ptr{Cvoid}
# ppszUserName : LPCWSTR* out -> Ptr{Ptr{UInt16}}
# ppszDomainName : LPCWSTR* out -> Ptr{Ptr{UInt16}}
# ppszPackedCredentialsString : LPCWSTR* optional, out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SspiEncodeAuthIdentityAsStrings(
    void* pAuthIdentity,
    uint16_t** ppszUserName,
    uint16_t** ppszDomainName,
    uint16_t** ppszPackedCredentialsString);
]]
local secur32 = ffi.load("secur32")
-- secur32.SspiEncodeAuthIdentityAsStrings(pAuthIdentity, ppszUserName, ppszDomainName, ppszPackedCredentialsString)
-- pAuthIdentity : void*
-- ppszUserName : LPCWSTR* out
-- ppszDomainName : LPCWSTR* out
-- ppszPackedCredentialsString : LPCWSTR* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SECUR32.dll');
const SspiEncodeAuthIdentityAsStrings = lib.func('__stdcall', 'SspiEncodeAuthIdentityAsStrings', 'int32_t', ['void *', 'void *', 'void *', 'void *']);
// SspiEncodeAuthIdentityAsStrings(pAuthIdentity, ppszUserName, ppszDomainName, ppszPackedCredentialsString)
// pAuthIdentity : void* -> 'void *'
// ppszUserName : LPCWSTR* out -> 'void *'
// ppszDomainName : LPCWSTR* out -> 'void *'
// ppszPackedCredentialsString : LPCWSTR* optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SECUR32.dll", {
  SspiEncodeAuthIdentityAsStrings: { parameters: ["pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SspiEncodeAuthIdentityAsStrings(pAuthIdentity, ppszUserName, ppszDomainName, ppszPackedCredentialsString)
// pAuthIdentity : void* -> "pointer"
// ppszUserName : LPCWSTR* out -> "pointer"
// ppszDomainName : LPCWSTR* out -> "pointer"
// ppszPackedCredentialsString : LPCWSTR* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SspiEncodeAuthIdentityAsStrings(
    void* pAuthIdentity,
    uint16_t** ppszUserName,
    uint16_t** ppszDomainName,
    uint16_t** ppszPackedCredentialsString);
C, "SECUR32.dll");
// $ffi->SspiEncodeAuthIdentityAsStrings(pAuthIdentity, ppszUserName, ppszDomainName, ppszPackedCredentialsString);
// pAuthIdentity : void*
// ppszUserName : LPCWSTR* out
// ppszDomainName : LPCWSTR* out
// ppszPackedCredentialsString : LPCWSTR* optional, 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 SspiEncodeAuthIdentityAsStrings(
        Pointer pAuthIdentity,   // void*
        PointerByReference ppszUserName,   // LPCWSTR* out
        PointerByReference ppszDomainName,   // LPCWSTR* out
        PointerByReference ppszPackedCredentialsString   // LPCWSTR* optional, out
    );
}
@[Link("secur32")]
lib LibSECUR32
  fun SspiEncodeAuthIdentityAsStrings = SspiEncodeAuthIdentityAsStrings(
    pAuthIdentity : Void*,   # void*
    ppszUserName : UInt16**,   # LPCWSTR* out
    ppszDomainName : UInt16**,   # LPCWSTR* out
    ppszPackedCredentialsString : UInt16**   # LPCWSTR* optional, out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SspiEncodeAuthIdentityAsStringsNative = Int32 Function(Pointer<Void>, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>);
typedef SspiEncodeAuthIdentityAsStringsDart = int Function(Pointer<Void>, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>);
final SspiEncodeAuthIdentityAsStrings = DynamicLibrary.open('SECUR32.dll')
    .lookupFunction<SspiEncodeAuthIdentityAsStringsNative, SspiEncodeAuthIdentityAsStringsDart>('SspiEncodeAuthIdentityAsStrings');
// pAuthIdentity : void* -> Pointer<Void>
// ppszUserName : LPCWSTR* out -> Pointer<Pointer<Utf16>>
// ppszDomainName : LPCWSTR* out -> Pointer<Pointer<Utf16>>
// ppszPackedCredentialsString : LPCWSTR* optional, out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SspiEncodeAuthIdentityAsStrings(
  pAuthIdentity: Pointer;   // void*
  ppszUserName: PPWideChar;   // LPCWSTR* out
  ppszDomainName: PPWideChar;   // LPCWSTR* out
  ppszPackedCredentialsString: PPWideChar   // LPCWSTR* optional, out
): Integer; stdcall;
  external 'SECUR32.dll' name 'SspiEncodeAuthIdentityAsStrings';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SspiEncodeAuthIdentityAsStrings"
  c_SspiEncodeAuthIdentityAsStrings :: Ptr () -> Ptr CWString -> Ptr CWString -> Ptr CWString -> IO Int32
-- pAuthIdentity : void* -> Ptr ()
-- ppszUserName : LPCWSTR* out -> Ptr CWString
-- ppszDomainName : LPCWSTR* out -> Ptr CWString
-- ppszPackedCredentialsString : LPCWSTR* optional, out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sspiencodeauthidentityasstrings =
  foreign "SspiEncodeAuthIdentityAsStrings"
    ((ptr void) @-> (ptr (ptr uint16_t)) @-> (ptr (ptr uint16_t)) @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* pAuthIdentity : void* -> (ptr void) *)
(* ppszUserName : LPCWSTR* out -> (ptr (ptr uint16_t)) *)
(* ppszDomainName : LPCWSTR* out -> (ptr (ptr uint16_t)) *)
(* ppszPackedCredentialsString : LPCWSTR* optional, out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library secur32 (t "SECUR32.dll"))
(cffi:use-foreign-library secur32)

(cffi:defcfun ("SspiEncodeAuthIdentityAsStrings" sspi-encode-auth-identity-as-strings :convention :stdcall) :int32
  (p-auth-identity :pointer)   ; void*
  (ppsz-user-name :pointer)   ; LPCWSTR* out
  (ppsz-domain-name :pointer)   ; LPCWSTR* out
  (ppsz-packed-credentials-string :pointer))   ; LPCWSTR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SspiEncodeAuthIdentityAsStrings = Win32::API::More->new('SECUR32',
    'int SspiEncodeAuthIdentityAsStrings(LPVOID pAuthIdentity, LPVOID ppszUserName, LPVOID ppszDomainName, LPVOID ppszPackedCredentialsString)');
# my $ret = $SspiEncodeAuthIdentityAsStrings->Call($pAuthIdentity, $ppszUserName, $ppszDomainName, $ppszPackedCredentialsString);
# pAuthIdentity : void* -> LPVOID
# ppszUserName : LPCWSTR* out -> LPVOID
# ppszDomainName : LPCWSTR* out -> LPVOID
# ppszPackedCredentialsString : LPCWSTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。