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

ImportSecurityContextA

関数
エクスポートされたセキュリティコンテキストをインポートする(ANSI版)。
DLLSECUR32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT ImportSecurityContextA(
    LPSTR pszPackage,
    SecBuffer* pPackedContext,
    void* Token,
    SecHandle* phContext
);

パラメーター

名前方向
pszPackageLPSTRin
pPackedContextSecBuffer*in
Tokenvoid*in
phContextSecHandle*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT ImportSecurityContextA(
    LPSTR pszPackage,
    SecBuffer* pPackedContext,
    void* Token,
    SecHandle* phContext
);
[DllImport("SECUR32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int ImportSecurityContextA(
    [MarshalAs(UnmanagedType.LPStr)] string pszPackage,   // LPSTR
    IntPtr pPackedContext,   // SecBuffer*
    IntPtr Token,   // void*
    IntPtr phContext   // SecHandle* out
);
<DllImport("SECUR32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function ImportSecurityContextA(
    <MarshalAs(UnmanagedType.LPStr)> pszPackage As String,   ' LPSTR
    pPackedContext As IntPtr,   ' SecBuffer*
    Token As IntPtr,   ' void*
    phContext As IntPtr   ' SecHandle* out
) As Integer
End Function
' pszPackage : LPSTR
' pPackedContext : SecBuffer*
' Token : void*
' phContext : SecHandle* out
Declare PtrSafe Function ImportSecurityContextA Lib "secur32" ( _
    ByVal pszPackage As String, _
    ByVal pPackedContext As LongPtr, _
    ByVal Token As LongPtr, _
    ByVal phContext As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ImportSecurityContextA = ctypes.windll.secur32.ImportSecurityContextA
ImportSecurityContextA.restype = ctypes.c_int
ImportSecurityContextA.argtypes = [
    wintypes.LPCSTR,  # pszPackage : LPSTR
    ctypes.c_void_p,  # pPackedContext : SecBuffer*
    ctypes.POINTER(None),  # Token : void*
    ctypes.c_void_p,  # phContext : SecHandle* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	secur32 = windows.NewLazySystemDLL("SECUR32.dll")
	procImportSecurityContextA = secur32.NewProc("ImportSecurityContextA")
)

// pszPackage (LPSTR), pPackedContext (SecBuffer*), Token (void*), phContext (SecHandle* out)
r1, _, err := procImportSecurityContextA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszPackage))),
	uintptr(pPackedContext),
	uintptr(Token),
	uintptr(phContext),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function ImportSecurityContextA(
  pszPackage: PAnsiChar;   // LPSTR
  pPackedContext: Pointer;   // SecBuffer*
  Token: Pointer;   // void*
  phContext: Pointer   // SecHandle* out
): Integer; stdcall;
  external 'SECUR32.dll' name 'ImportSecurityContextA';
result := DllCall("SECUR32\ImportSecurityContextA"
    , "AStr", pszPackage   ; LPSTR
    , "Ptr", pPackedContext   ; SecBuffer*
    , "Ptr", Token   ; void*
    , "Ptr", phContext   ; SecHandle* out
    , "Int")   ; return: HRESULT
●ImportSecurityContextA(pszPackage, pPackedContext, Token, phContext) = DLL("SECUR32.dll", "int ImportSecurityContextA(char*, void*, void*, void*)")
# 呼び出し: ImportSecurityContextA(pszPackage, pPackedContext, Token, phContext)
# pszPackage : LPSTR -> "char*"
# pPackedContext : SecBuffer* -> "void*"
# Token : void* -> "void*"
# phContext : SecHandle* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。