Win32 API 日本語リファレンス
ホームSecurity.Cryptography › CertGetStoreProperty

CertGetStoreProperty

関数
証明書ストアの指定プロパティを取得する。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CertGetStoreProperty(
    HCERTSTORE hCertStore,
    DWORD dwPropId,
    void* pvData,   // optional
    DWORD* pcbData
);

パラメーター

名前方向
hCertStoreHCERTSTOREin
dwPropIdDWORDin
pvDatavoid*outoptional
pcbDataDWORD*inout

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL CertGetStoreProperty(
    HCERTSTORE hCertStore,
    DWORD dwPropId,
    void* pvData,   // optional
    DWORD* pcbData
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CertGetStoreProperty(
    IntPtr hCertStore,   // HCERTSTORE
    uint dwPropId,   // DWORD
    IntPtr pvData,   // void* optional, out
    ref uint pcbData   // DWORD* in/out
);
<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CertGetStoreProperty(
    hCertStore As IntPtr,   ' HCERTSTORE
    dwPropId As UInteger,   ' DWORD
    pvData As IntPtr,   ' void* optional, out
    ByRef pcbData As UInteger   ' DWORD* in/out
) As Boolean
End Function
' hCertStore : HCERTSTORE
' dwPropId : DWORD
' pvData : void* optional, out
' pcbData : DWORD* in/out
Declare PtrSafe Function CertGetStoreProperty Lib "crypt32" ( _
    ByVal hCertStore As LongPtr, _
    ByVal dwPropId As Long, _
    ByVal pvData As LongPtr, _
    ByRef pcbData As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CertGetStoreProperty = ctypes.windll.crypt32.CertGetStoreProperty
CertGetStoreProperty.restype = wintypes.BOOL
CertGetStoreProperty.argtypes = [
    wintypes.HANDLE,  # hCertStore : HCERTSTORE
    wintypes.DWORD,  # dwPropId : DWORD
    ctypes.POINTER(None),  # pvData : void* optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcbData : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CRYPT32.dll')
CertGetStoreProperty = Fiddle::Function.new(
  lib['CertGetStoreProperty'],
  [
    Fiddle::TYPE_VOIDP,  # hCertStore : HCERTSTORE
    -Fiddle::TYPE_INT,  # dwPropId : DWORD
    Fiddle::TYPE_VOIDP,  # pvData : void* optional, out
    Fiddle::TYPE_VOIDP,  # pcbData : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "crypt32")]
extern "system" {
    fn CertGetStoreProperty(
        hCertStore: *mut core::ffi::c_void,  // HCERTSTORE
        dwPropId: u32,  // DWORD
        pvData: *mut (),  // void* optional, out
        pcbData: *mut u32  // DWORD* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true)]
public static extern bool CertGetStoreProperty(IntPtr hCertStore, uint dwPropId, IntPtr pvData, ref uint pcbData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CertGetStoreProperty' -Namespace Win32 -PassThru
# $api::CertGetStoreProperty(hCertStore, dwPropId, pvData, pcbData)
#uselib "CRYPT32.dll"
#func global CertGetStoreProperty "CertGetStoreProperty" sptr, sptr, sptr, sptr
; CertGetStoreProperty hCertStore, dwPropId, pvData, varptr(pcbData)   ; 戻り値は stat
; hCertStore : HCERTSTORE -> "sptr"
; dwPropId : DWORD -> "sptr"
; pvData : void* optional, out -> "sptr"
; pcbData : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CRYPT32.dll"
#cfunc global CertGetStoreProperty "CertGetStoreProperty" sptr, int, sptr, var
; res = CertGetStoreProperty(hCertStore, dwPropId, pvData, pcbData)
; hCertStore : HCERTSTORE -> "sptr"
; dwPropId : DWORD -> "int"
; pvData : void* optional, out -> "sptr"
; pcbData : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CertGetStoreProperty(HCERTSTORE hCertStore, DWORD dwPropId, void* pvData, DWORD* pcbData)
#uselib "CRYPT32.dll"
#cfunc global CertGetStoreProperty "CertGetStoreProperty" intptr, int, intptr, var
; res = CertGetStoreProperty(hCertStore, dwPropId, pvData, pcbData)
; hCertStore : HCERTSTORE -> "intptr"
; dwPropId : DWORD -> "int"
; pvData : void* optional, out -> "intptr"
; pcbData : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCertGetStoreProperty = crypt32.NewProc("CertGetStoreProperty")
)

// hCertStore (HCERTSTORE), dwPropId (DWORD), pvData (void* optional, out), pcbData (DWORD* in/out)
r1, _, err := procCertGetStoreProperty.Call(
	uintptr(hCertStore),
	uintptr(dwPropId),
	uintptr(pvData),
	uintptr(pcbData),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CertGetStoreProperty(
  hCertStore: THandle;   // HCERTSTORE
  dwPropId: DWORD;   // DWORD
  pvData: Pointer;   // void* optional, out
  pcbData: Pointer   // DWORD* in/out
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CertGetStoreProperty';
result := DllCall("CRYPT32\CertGetStoreProperty"
    , "Ptr", hCertStore   ; HCERTSTORE
    , "UInt", dwPropId   ; DWORD
    , "Ptr", pvData   ; void* optional, out
    , "Ptr", pcbData   ; DWORD* in/out
    , "Int")   ; return: BOOL
●CertGetStoreProperty(hCertStore, dwPropId, pvData, pcbData) = DLL("CRYPT32.dll", "bool CertGetStoreProperty(void*, dword, void*, void*)")
# 呼び出し: CertGetStoreProperty(hCertStore, dwPropId, pvData, pcbData)
# hCertStore : HCERTSTORE -> "void*"
# dwPropId : DWORD -> "dword"
# pvData : void* optional, out -> "void*"
# pcbData : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。