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

CertOpenSystemStoreW

関数
システム証明書ストアをUnicode名で開く。
DLLCRYPT32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

HCERTSTORE CertOpenSystemStoreW(
    HCRYPTPROV_LEGACY hProv,   // optional
    LPCWSTR szSubsystemProtocol
);

パラメーター

名前方向
hProvHCRYPTPROV_LEGACYinoptional
szSubsystemProtocolLPCWSTRin

戻り値の型: HCERTSTORE

各言語での呼び出し定義

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

HCERTSTORE CertOpenSystemStoreW(
    HCRYPTPROV_LEGACY hProv,   // optional
    LPCWSTR szSubsystemProtocol
);
[DllImport("CRYPT32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr CertOpenSystemStoreW(
    UIntPtr hProv,   // HCRYPTPROV_LEGACY optional
    [MarshalAs(UnmanagedType.LPWStr)] string szSubsystemProtocol   // LPCWSTR
);
<DllImport("CRYPT32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CertOpenSystemStoreW(
    hProv As UIntPtr,   ' HCRYPTPROV_LEGACY optional
    <MarshalAs(UnmanagedType.LPWStr)> szSubsystemProtocol As String   ' LPCWSTR
) As IntPtr
End Function
' hProv : HCRYPTPROV_LEGACY optional
' szSubsystemProtocol : LPCWSTR
Declare PtrSafe Function CertOpenSystemStoreW Lib "crypt32" ( _
    ByVal hProv As LongPtr, _
    ByVal szSubsystemProtocol As LongPtr) As LongPtr
' 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

CertOpenSystemStoreW = ctypes.windll.crypt32.CertOpenSystemStoreW
CertOpenSystemStoreW.restype = ctypes.c_void_p
CertOpenSystemStoreW.argtypes = [
    ctypes.c_size_t,  # hProv : HCRYPTPROV_LEGACY optional
    wintypes.LPCWSTR,  # szSubsystemProtocol : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CRYPT32.dll')
CertOpenSystemStoreW = Fiddle::Function.new(
  lib['CertOpenSystemStoreW'],
  [
    Fiddle::TYPE_UINTPTR_T,  # hProv : HCRYPTPROV_LEGACY optional
    Fiddle::TYPE_VOIDP,  # szSubsystemProtocol : LPCWSTR
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "crypt32")]
extern "system" {
    fn CertOpenSystemStoreW(
        hProv: usize,  // HCRYPTPROV_LEGACY optional
        szSubsystemProtocol: *const u16  // LPCWSTR
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CRYPT32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr CertOpenSystemStoreW(UIntPtr hProv, [MarshalAs(UnmanagedType.LPWStr)] string szSubsystemProtocol);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CertOpenSystemStoreW' -Namespace Win32 -PassThru
# $api::CertOpenSystemStoreW(hProv, szSubsystemProtocol)
#uselib "CRYPT32.dll"
#func global CertOpenSystemStoreW "CertOpenSystemStoreW" wptr, wptr
; CertOpenSystemStoreW hProv, szSubsystemProtocol   ; 戻り値は stat
; hProv : HCRYPTPROV_LEGACY optional -> "wptr"
; szSubsystemProtocol : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "CRYPT32.dll"
#cfunc global CertOpenSystemStoreW "CertOpenSystemStoreW" sptr, wstr
; res = CertOpenSystemStoreW(hProv, szSubsystemProtocol)
; hProv : HCRYPTPROV_LEGACY optional -> "sptr"
; szSubsystemProtocol : LPCWSTR -> "wstr"
; HCERTSTORE CertOpenSystemStoreW(HCRYPTPROV_LEGACY hProv, LPCWSTR szSubsystemProtocol)
#uselib "CRYPT32.dll"
#cfunc global CertOpenSystemStoreW "CertOpenSystemStoreW" intptr, wstr
; res = CertOpenSystemStoreW(hProv, szSubsystemProtocol)
; hProv : HCRYPTPROV_LEGACY optional -> "intptr"
; szSubsystemProtocol : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCertOpenSystemStoreW = crypt32.NewProc("CertOpenSystemStoreW")
)

// hProv (HCRYPTPROV_LEGACY optional), szSubsystemProtocol (LPCWSTR)
r1, _, err := procCertOpenSystemStoreW.Call(
	uintptr(hProv),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szSubsystemProtocol))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HCERTSTORE
function CertOpenSystemStoreW(
  hProv: NativeUInt;   // HCRYPTPROV_LEGACY optional
  szSubsystemProtocol: PWideChar   // LPCWSTR
): THandle; stdcall;
  external 'CRYPT32.dll' name 'CertOpenSystemStoreW';
result := DllCall("CRYPT32\CertOpenSystemStoreW"
    , "UPtr", hProv   ; HCRYPTPROV_LEGACY optional
    , "WStr", szSubsystemProtocol   ; LPCWSTR
    , "Ptr")   ; return: HCERTSTORE
●CertOpenSystemStoreW(hProv, szSubsystemProtocol) = DLL("CRYPT32.dll", "void* CertOpenSystemStoreW(int, char*)")
# 呼び出し: CertOpenSystemStoreW(hProv, szSubsystemProtocol)
# hProv : HCRYPTPROV_LEGACY optional -> "int"
# szSubsystemProtocol : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。