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

SetContextAttributesW

関数
セキュリティコンテキストの属性を設定する(Unicode版)。
DLLSECUR32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT SetContextAttributesW(
    SecHandle* phContext,
    SECPKG_ATTR ulAttribute,
    void* pBuffer,
    DWORD cbBuffer
);

パラメーター

名前方向
phContextSecHandle*in
ulAttributeSECPKG_ATTRin
pBuffervoid*in
cbBufferDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SetContextAttributesW(
    SecHandle* phContext,
    SECPKG_ATTR ulAttribute,
    void* pBuffer,
    DWORD cbBuffer
);
[DllImport("SECUR32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SetContextAttributesW(
    IntPtr phContext,   // SecHandle*
    uint ulAttribute,   // SECPKG_ATTR
    IntPtr pBuffer,   // void*
    uint cbBuffer   // DWORD
);
<DllImport("SECUR32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SetContextAttributesW(
    phContext As IntPtr,   ' SecHandle*
    ulAttribute As UInteger,   ' SECPKG_ATTR
    pBuffer As IntPtr,   ' void*
    cbBuffer As UInteger   ' DWORD
) As Integer
End Function
' phContext : SecHandle*
' ulAttribute : SECPKG_ATTR
' pBuffer : void*
' cbBuffer : DWORD
Declare PtrSafe Function SetContextAttributesW Lib "secur32" ( _
    ByVal phContext As LongPtr, _
    ByVal ulAttribute As Long, _
    ByVal pBuffer As LongPtr, _
    ByVal cbBuffer As Long) 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

SetContextAttributesW = ctypes.windll.secur32.SetContextAttributesW
SetContextAttributesW.restype = ctypes.c_int
SetContextAttributesW.argtypes = [
    ctypes.c_void_p,  # phContext : SecHandle*
    wintypes.DWORD,  # ulAttribute : SECPKG_ATTR
    ctypes.POINTER(None),  # pBuffer : void*
    wintypes.DWORD,  # cbBuffer : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	secur32 = windows.NewLazySystemDLL("SECUR32.dll")
	procSetContextAttributesW = secur32.NewProc("SetContextAttributesW")
)

// phContext (SecHandle*), ulAttribute (SECPKG_ATTR), pBuffer (void*), cbBuffer (DWORD)
r1, _, err := procSetContextAttributesW.Call(
	uintptr(phContext),
	uintptr(ulAttribute),
	uintptr(pBuffer),
	uintptr(cbBuffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SetContextAttributesW(
  phContext: Pointer;   // SecHandle*
  ulAttribute: DWORD;   // SECPKG_ATTR
  pBuffer: Pointer;   // void*
  cbBuffer: DWORD   // DWORD
): Integer; stdcall;
  external 'SECUR32.dll' name 'SetContextAttributesW';
result := DllCall("SECUR32\SetContextAttributesW"
    , "Ptr", phContext   ; SecHandle*
    , "UInt", ulAttribute   ; SECPKG_ATTR
    , "Ptr", pBuffer   ; void*
    , "UInt", cbBuffer   ; DWORD
    , "Int")   ; return: HRESULT
●SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer) = DLL("SECUR32.dll", "int SetContextAttributesW(void*, dword, void*, dword)")
# 呼び出し: SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer)
# phContext : SecHandle* -> "void*"
# ulAttribute : SECPKG_ATTR -> "dword"
# pBuffer : void* -> "void*"
# cbBuffer : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。