ホーム › System.Com › CoInitializeSecurity
CoInitializeSecurity
関数プロセス全体のCOMセキュリティ設定を初期化する。
シグネチャ
// OLE32.dll
#include <windows.h>
HRESULT CoInitializeSecurity(
PSECURITY_DESCRIPTOR pSecDesc, // optional
INT cAuthSvc,
SOLE_AUTHENTICATION_SERVICE* asAuthSvc, // optional
void* pReserved1, // optional
RPC_C_AUTHN_LEVEL dwAuthnLevel,
RPC_C_IMP_LEVEL dwImpLevel,
void* pAuthList, // optional
DWORD dwCapabilities,
void* pReserved3 // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pSecDesc | PSECURITY_DESCRIPTOR | inoptional |
| cAuthSvc | INT | in |
| asAuthSvc | SOLE_AUTHENTICATION_SERVICE* | inoptional |
| pReserved1 | void* | inoptional |
| dwAuthnLevel | RPC_C_AUTHN_LEVEL | in |
| dwImpLevel | RPC_C_IMP_LEVEL | in |
| pAuthList | void* | inoptional |
| dwCapabilities | DWORD | in |
| pReserved3 | void* | inoptional |
戻り値の型: HRESULT
各言語での呼び出し定義
// OLE32.dll
#include <windows.h>
HRESULT CoInitializeSecurity(
PSECURITY_DESCRIPTOR pSecDesc, // optional
INT cAuthSvc,
SOLE_AUTHENTICATION_SERVICE* asAuthSvc, // optional
void* pReserved1, // optional
RPC_C_AUTHN_LEVEL dwAuthnLevel,
RPC_C_IMP_LEVEL dwImpLevel,
void* pAuthList, // optional
DWORD dwCapabilities,
void* pReserved3 // optional
);[DllImport("OLE32.dll", ExactSpelling = true)]
static extern int CoInitializeSecurity(
IntPtr pSecDesc, // PSECURITY_DESCRIPTOR optional
int cAuthSvc, // INT
IntPtr asAuthSvc, // SOLE_AUTHENTICATION_SERVICE* optional
IntPtr pReserved1, // void* optional
uint dwAuthnLevel, // RPC_C_AUTHN_LEVEL
uint dwImpLevel, // RPC_C_IMP_LEVEL
IntPtr pAuthList, // void* optional
uint dwCapabilities, // DWORD
IntPtr pReserved3 // void* optional
);<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function CoInitializeSecurity(
pSecDesc As IntPtr, ' PSECURITY_DESCRIPTOR optional
cAuthSvc As Integer, ' INT
asAuthSvc As IntPtr, ' SOLE_AUTHENTICATION_SERVICE* optional
pReserved1 As IntPtr, ' void* optional
dwAuthnLevel As UInteger, ' RPC_C_AUTHN_LEVEL
dwImpLevel As UInteger, ' RPC_C_IMP_LEVEL
pAuthList As IntPtr, ' void* optional
dwCapabilities As UInteger, ' DWORD
pReserved3 As IntPtr ' void* optional
) As Integer
End Function' pSecDesc : PSECURITY_DESCRIPTOR optional
' cAuthSvc : INT
' asAuthSvc : SOLE_AUTHENTICATION_SERVICE* optional
' pReserved1 : void* optional
' dwAuthnLevel : RPC_C_AUTHN_LEVEL
' dwImpLevel : RPC_C_IMP_LEVEL
' pAuthList : void* optional
' dwCapabilities : DWORD
' pReserved3 : void* optional
Declare PtrSafe Function CoInitializeSecurity Lib "ole32" ( _
ByVal pSecDesc As LongPtr, _
ByVal cAuthSvc As Long, _
ByVal asAuthSvc As LongPtr, _
ByVal pReserved1 As LongPtr, _
ByVal dwAuthnLevel As Long, _
ByVal dwImpLevel As Long, _
ByVal pAuthList As LongPtr, _
ByVal dwCapabilities As Long, _
ByVal pReserved3 As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CoInitializeSecurity = ctypes.windll.ole32.CoInitializeSecurity
CoInitializeSecurity.restype = ctypes.c_int
CoInitializeSecurity.argtypes = [
wintypes.HANDLE, # pSecDesc : PSECURITY_DESCRIPTOR optional
ctypes.c_int, # cAuthSvc : INT
ctypes.c_void_p, # asAuthSvc : SOLE_AUTHENTICATION_SERVICE* optional
ctypes.POINTER(None), # pReserved1 : void* optional
wintypes.DWORD, # dwAuthnLevel : RPC_C_AUTHN_LEVEL
wintypes.DWORD, # dwImpLevel : RPC_C_IMP_LEVEL
ctypes.POINTER(None), # pAuthList : void* optional
wintypes.DWORD, # dwCapabilities : DWORD
ctypes.POINTER(None), # pReserved3 : void* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLE32.dll')
CoInitializeSecurity = Fiddle::Function.new(
lib['CoInitializeSecurity'],
[
Fiddle::TYPE_VOIDP, # pSecDesc : PSECURITY_DESCRIPTOR optional
Fiddle::TYPE_INT, # cAuthSvc : INT
Fiddle::TYPE_VOIDP, # asAuthSvc : SOLE_AUTHENTICATION_SERVICE* optional
Fiddle::TYPE_VOIDP, # pReserved1 : void* optional
-Fiddle::TYPE_INT, # dwAuthnLevel : RPC_C_AUTHN_LEVEL
-Fiddle::TYPE_INT, # dwImpLevel : RPC_C_IMP_LEVEL
Fiddle::TYPE_VOIDP, # pAuthList : void* optional
-Fiddle::TYPE_INT, # dwCapabilities : DWORD
Fiddle::TYPE_VOIDP, # pReserved3 : void* optional
],
Fiddle::TYPE_INT)#[link(name = "ole32")]
extern "system" {
fn CoInitializeSecurity(
pSecDesc: *mut core::ffi::c_void, // PSECURITY_DESCRIPTOR optional
cAuthSvc: i32, // INT
asAuthSvc: *mut SOLE_AUTHENTICATION_SERVICE, // SOLE_AUTHENTICATION_SERVICE* optional
pReserved1: *mut (), // void* optional
dwAuthnLevel: u32, // RPC_C_AUTHN_LEVEL
dwImpLevel: u32, // RPC_C_IMP_LEVEL
pAuthList: *mut (), // void* optional
dwCapabilities: u32, // DWORD
pReserved3: *mut () // void* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLE32.dll")]
public static extern int CoInitializeSecurity(IntPtr pSecDesc, int cAuthSvc, IntPtr asAuthSvc, IntPtr pReserved1, uint dwAuthnLevel, uint dwImpLevel, IntPtr pAuthList, uint dwCapabilities, IntPtr pReserved3);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_CoInitializeSecurity' -Namespace Win32 -PassThru
# $api::CoInitializeSecurity(pSecDesc, cAuthSvc, asAuthSvc, pReserved1, dwAuthnLevel, dwImpLevel, pAuthList, dwCapabilities, pReserved3)#uselib "OLE32.dll"
#func global CoInitializeSecurity "CoInitializeSecurity" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CoInitializeSecurity pSecDesc, cAuthSvc, varptr(asAuthSvc), pReserved1, dwAuthnLevel, dwImpLevel, pAuthList, dwCapabilities, pReserved3 ; 戻り値は stat
; pSecDesc : PSECURITY_DESCRIPTOR optional -> "sptr"
; cAuthSvc : INT -> "sptr"
; asAuthSvc : SOLE_AUTHENTICATION_SERVICE* optional -> "sptr"
; pReserved1 : void* optional -> "sptr"
; dwAuthnLevel : RPC_C_AUTHN_LEVEL -> "sptr"
; dwImpLevel : RPC_C_IMP_LEVEL -> "sptr"
; pAuthList : void* optional -> "sptr"
; dwCapabilities : DWORD -> "sptr"
; pReserved3 : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "OLE32.dll" #cfunc global CoInitializeSecurity "CoInitializeSecurity" sptr, int, var, sptr, int, int, sptr, int, sptr ; res = CoInitializeSecurity(pSecDesc, cAuthSvc, asAuthSvc, pReserved1, dwAuthnLevel, dwImpLevel, pAuthList, dwCapabilities, pReserved3) ; pSecDesc : PSECURITY_DESCRIPTOR optional -> "sptr" ; cAuthSvc : INT -> "int" ; asAuthSvc : SOLE_AUTHENTICATION_SERVICE* optional -> "var" ; pReserved1 : void* optional -> "sptr" ; dwAuthnLevel : RPC_C_AUTHN_LEVEL -> "int" ; dwImpLevel : RPC_C_IMP_LEVEL -> "int" ; pAuthList : void* optional -> "sptr" ; dwCapabilities : DWORD -> "int" ; pReserved3 : void* optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "OLE32.dll" #cfunc global CoInitializeSecurity "CoInitializeSecurity" sptr, int, sptr, sptr, int, int, sptr, int, sptr ; res = CoInitializeSecurity(pSecDesc, cAuthSvc, varptr(asAuthSvc), pReserved1, dwAuthnLevel, dwImpLevel, pAuthList, dwCapabilities, pReserved3) ; pSecDesc : PSECURITY_DESCRIPTOR optional -> "sptr" ; cAuthSvc : INT -> "int" ; asAuthSvc : SOLE_AUTHENTICATION_SERVICE* optional -> "sptr" ; pReserved1 : void* optional -> "sptr" ; dwAuthnLevel : RPC_C_AUTHN_LEVEL -> "int" ; dwImpLevel : RPC_C_IMP_LEVEL -> "int" ; pAuthList : void* optional -> "sptr" ; dwCapabilities : DWORD -> "int" ; pReserved3 : void* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT CoInitializeSecurity(PSECURITY_DESCRIPTOR pSecDesc, INT cAuthSvc, SOLE_AUTHENTICATION_SERVICE* asAuthSvc, void* pReserved1, RPC_C_AUTHN_LEVEL dwAuthnLevel, RPC_C_IMP_LEVEL dwImpLevel, void* pAuthList, DWORD dwCapabilities, void* pReserved3) #uselib "OLE32.dll" #cfunc global CoInitializeSecurity "CoInitializeSecurity" intptr, int, var, intptr, int, int, intptr, int, intptr ; res = CoInitializeSecurity(pSecDesc, cAuthSvc, asAuthSvc, pReserved1, dwAuthnLevel, dwImpLevel, pAuthList, dwCapabilities, pReserved3) ; pSecDesc : PSECURITY_DESCRIPTOR optional -> "intptr" ; cAuthSvc : INT -> "int" ; asAuthSvc : SOLE_AUTHENTICATION_SERVICE* optional -> "var" ; pReserved1 : void* optional -> "intptr" ; dwAuthnLevel : RPC_C_AUTHN_LEVEL -> "int" ; dwImpLevel : RPC_C_IMP_LEVEL -> "int" ; pAuthList : void* optional -> "intptr" ; dwCapabilities : DWORD -> "int" ; pReserved3 : void* optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT CoInitializeSecurity(PSECURITY_DESCRIPTOR pSecDesc, INT cAuthSvc, SOLE_AUTHENTICATION_SERVICE* asAuthSvc, void* pReserved1, RPC_C_AUTHN_LEVEL dwAuthnLevel, RPC_C_IMP_LEVEL dwImpLevel, void* pAuthList, DWORD dwCapabilities, void* pReserved3) #uselib "OLE32.dll" #cfunc global CoInitializeSecurity "CoInitializeSecurity" intptr, int, intptr, intptr, int, int, intptr, int, intptr ; res = CoInitializeSecurity(pSecDesc, cAuthSvc, varptr(asAuthSvc), pReserved1, dwAuthnLevel, dwImpLevel, pAuthList, dwCapabilities, pReserved3) ; pSecDesc : PSECURITY_DESCRIPTOR optional -> "intptr" ; cAuthSvc : INT -> "int" ; asAuthSvc : SOLE_AUTHENTICATION_SERVICE* optional -> "intptr" ; pReserved1 : void* optional -> "intptr" ; dwAuthnLevel : RPC_C_AUTHN_LEVEL -> "int" ; dwImpLevel : RPC_C_IMP_LEVEL -> "int" ; pAuthList : void* optional -> "intptr" ; dwCapabilities : DWORD -> "int" ; pReserved3 : void* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ole32 = windows.NewLazySystemDLL("OLE32.dll")
procCoInitializeSecurity = ole32.NewProc("CoInitializeSecurity")
)
// pSecDesc (PSECURITY_DESCRIPTOR optional), cAuthSvc (INT), asAuthSvc (SOLE_AUTHENTICATION_SERVICE* optional), pReserved1 (void* optional), dwAuthnLevel (RPC_C_AUTHN_LEVEL), dwImpLevel (RPC_C_IMP_LEVEL), pAuthList (void* optional), dwCapabilities (DWORD), pReserved3 (void* optional)
r1, _, err := procCoInitializeSecurity.Call(
uintptr(pSecDesc),
uintptr(cAuthSvc),
uintptr(asAuthSvc),
uintptr(pReserved1),
uintptr(dwAuthnLevel),
uintptr(dwImpLevel),
uintptr(pAuthList),
uintptr(dwCapabilities),
uintptr(pReserved3),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction CoInitializeSecurity(
pSecDesc: THandle; // PSECURITY_DESCRIPTOR optional
cAuthSvc: Integer; // INT
asAuthSvc: Pointer; // SOLE_AUTHENTICATION_SERVICE* optional
pReserved1: Pointer; // void* optional
dwAuthnLevel: DWORD; // RPC_C_AUTHN_LEVEL
dwImpLevel: DWORD; // RPC_C_IMP_LEVEL
pAuthList: Pointer; // void* optional
dwCapabilities: DWORD; // DWORD
pReserved3: Pointer // void* optional
): Integer; stdcall;
external 'OLE32.dll' name 'CoInitializeSecurity';result := DllCall("OLE32\CoInitializeSecurity"
, "Ptr", pSecDesc ; PSECURITY_DESCRIPTOR optional
, "Int", cAuthSvc ; INT
, "Ptr", asAuthSvc ; SOLE_AUTHENTICATION_SERVICE* optional
, "Ptr", pReserved1 ; void* optional
, "UInt", dwAuthnLevel ; RPC_C_AUTHN_LEVEL
, "UInt", dwImpLevel ; RPC_C_IMP_LEVEL
, "Ptr", pAuthList ; void* optional
, "UInt", dwCapabilities ; DWORD
, "Ptr", pReserved3 ; void* optional
, "Int") ; return: HRESULT●CoInitializeSecurity(pSecDesc, cAuthSvc, asAuthSvc, pReserved1, dwAuthnLevel, dwImpLevel, pAuthList, dwCapabilities, pReserved3) = DLL("OLE32.dll", "int CoInitializeSecurity(void*, int, void*, void*, dword, dword, void*, dword, void*)")
# 呼び出し: CoInitializeSecurity(pSecDesc, cAuthSvc, asAuthSvc, pReserved1, dwAuthnLevel, dwImpLevel, pAuthList, dwCapabilities, pReserved3)
# pSecDesc : PSECURITY_DESCRIPTOR optional -> "void*"
# cAuthSvc : INT -> "int"
# asAuthSvc : SOLE_AUTHENTICATION_SERVICE* optional -> "void*"
# pReserved1 : void* optional -> "void*"
# dwAuthnLevel : RPC_C_AUTHN_LEVEL -> "dword"
# dwImpLevel : RPC_C_IMP_LEVEL -> "dword"
# pAuthList : void* optional -> "void*"
# dwCapabilities : DWORD -> "dword"
# pReserved3 : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。