CertControlStore
関数シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CertControlStore(
HCERTSTORE hCertStore,
CERT_CONTROL_STORE_FLAGS dwFlags,
DWORD dwCtrlType,
const void* pvCtrlPara // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hCertStore | HCERTSTORE | in | 証明書ストアのハンドル。 | ||||||||||||
| dwFlags | CERT_CONTROL_STORE_FLAGS | in | dwCtrlType パラメーターが CERT_STORE_CTRL_COMMIT に設定されている場合、このパラメーターには次のいずれかの値を指定できます。
dwCtrlType が CERT_STORE_CTRL_NOTIFY_CHANGE または CERT_STORE_CTRL_RESYNC に設定されている場合、dwFlags パラメーターは使用されず、0 に設定する必要があります。 | ||||||||||||
| dwCtrlType | DWORD | in | CertControlStore が実行する制御アクション。pvCtrlPara と dwFlags の解釈は dwCtrlType の値に依存します。現在、次のアクションが定義されています。
| ||||||||||||
| pvCtrlPara | void* | inoptional | dwCtrlType が CERT_STORE_NOTIFY_CHANGE の場合、pvCtrlPara にはハンドルのアドレスを設定します。ストアの永続化された状態からの変更が検出されると、システムはこのハンドルに対して通知変更イベントをシグナル状態にします。このハンドルは、関数 CreateEvent の呼び出しによって初期化しておく必要があります。レジストリベースのストアの場合、pvCtrlPara パラメーターには NULL を設定できます。pvCtrlPara が NULL の場合、内部的な通知変更イベントが作成され、シグナル状態にされるよう登録されます。内部的な通知変更イベントを使用すると、ストアが変更された場合にのみ再同期操作を行えます。 dwCtrlType が CERT_STORE_CTRL_RESYNC の場合、pvCtrlPara には、永続化されたストアの次回の変更時にシグナル状態にするイベントハンドルのアドレスを設定します。通常このアドレスは、初期化時に CERT_STORE_CTRL_NOTIFY_CHANGE とともに渡したイベントハンドルのアドレスです。渡されたイベントハンドルは再アーム(再武装)されます。pvCtrlPara を NULL に設定した場合、再アームされるイベントはありません。 dwCtrlType が CERT_STORE_CTRL_COMMIT の場合、pvCtrlPara は使用されず、NULL に設定する必要があります。 |
戻り値の型: BOOL
公式ドキュメント
使用中のキャッシュされたストアの内容と、ストレージに永続化されているそのストアの内容との間に差異が生じたときに、アプリケーションへ通知できるようにします。
戻り値
関数が成功すると、0 以外の値を返します。
関数が失敗すると、0 を返します。拡張エラー情報を取得するには、 GetLastError を呼び出します。
dwCtrlType が CERT_STORE_NOTIFY_CHANGE の場合、イベントシグナル用のハンドルが正常に設定されたときに 0 以外の値を返します。イベントハンドルが設定されなかった場合は 0 を返します。
dwCtrlType が CERT_STORE_CTRL_RESYNC の場合、再同期が成功すると 0 以外の値を返します。再同期が失敗すると 0 を返します。
dwCtrlType が CERT_STORE_CTRL_COMMIT の場合、永続ストレージへのコミットが正常に完了したことを示すために 0 以外の値を返します。コミットが失敗した場合は 0 を返します。
一部のプロバイダーは、特定の制御タイプをサポートしていない場合があります。その場合、CertControlStore は 0 を返し、GetLastError には ERROR_NOT_SUPPORTED コードが設定されます。
解説(Remarks)
ストアの再同期はいつでも実行できます。シグナル状態になった通知変更イベントの後に行う必要はありません。
CERT_STORE_CTRL_NOTIFY_CHANGE は、RegNotifyChangeKeyValue 関数を使用することで、レジストリベースのストアプロバイダーでサポートされます。
CERT_STORE_CTRL_NOTIFY_CHANGE を使用する CertControlStore は、CERT_STORE_CTRL_RESYNC とともに渡される各イベントハンドルに対して 1 回ずつ呼び出されます。CERT_STORE_CTRL_NOTIFY_CHANGE を使用するこれらの呼び出しは、各イベントの作成後に行う必要があり、イベントがシグナル状態になった後に行ってはなりません。
例
次の例は、使用中のキャッシュされたストアの内容と、ストレージに永続化されているそのストアの内容との間に差異が生じたときに、アプリケーションへ通知できるようにする方法を示します。このコード例の完全なコンテキストを含む全体の例については、 サンプル C プログラム: 証明書ストアのプロパティの設定と取得を参照してください。
//--------------------------------------------------------------------
// Declare and initialize variables.
HCERTSTORE hCertStore; // Original certificate store
HANDLE hEvent;
BOOL fSignal;
//--------------------------------------------------------------------
// Initialize an event.
if(hEvent = CreateEvent(
NULL,
FALSE, // Manual reset is FALSE
FALSE, // The initial state of the event is FALSE
NULL))
{
printf("An event has been created. \n");
}
else
{
printf("The event was not created. \n");
exit(1);
}
//--------------------------------------------------------------------
// Open the MY certificate store.
if ( hCertStore = CertOpenStore(
CERT_STORE_PROV_SYSTEM,
0,
NULL,
CERT_SYSTEM_STORE_CURRENT_USER,
L"MY"))
{
printf("The MY store is open. \n");
}
else
{
printf("The MY store did not open. \n");
exit(1);
}
//--------------------------------------------------------------------
// Call CertControlStore the first time with
// CERT_CONTROL_STORE_NOTIFY_CHANGE.
if(CertControlStore(
hCertStore, // The store to be controlled
0, // Not used
CERT_STORE_CTRL_NOTIFY_CHANGE, // Control action type
&hEvent)) // Points to the event handle
// When a change is detected,
// a signal is written to the
// memory location pointed to by
// hHandle.
{
printf("Notify change worked. \n");
}
else
{
printf("Notify change failed. \n");
exit(1);
}
//--------------------------------------------------------------------
// Wait for the store to change.
fSignal = (WAIT_OBJECT_0 == WaitForSingleObjectEx(
hEvent,
1000, // Number of milliseconds to wait;
// Use INFINITE to wait indefinitely for
// a change
FALSE));
if (fSignal)
{
//--------------------------------------------------------------------
// The store has changed.
// Call the function a second time with CERT_STORE_CTRL_RESYNC.
if(CertControlStore(
hCertStore, // The store to be controlled
0, // Not used
CERT_STORE_CTRL_RESYNC, // Control action type
&hEvent)) // The handle of the event
// to be rearmed
printf("Resynchronization worked. \n");
else
{
printf("Resynchronization failed. \n");
exit(1);
}
}
else
{
printf("The store was not changed. \n");
printf("Resynchronization was not needed. \n");
}
// Release the handle to the store.
if(CertCloseStore(hCertStore,
0))
{
printf("The MY store was closed. \n");
}
else
{
printf("An error occurred. The MY store was not closed. \n");
}
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CertControlStore(
HCERTSTORE hCertStore,
CERT_CONTROL_STORE_FLAGS dwFlags,
DWORD dwCtrlType,
const void* pvCtrlPara // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CertControlStore(
IntPtr hCertStore, // HCERTSTORE
uint dwFlags, // CERT_CONTROL_STORE_FLAGS
uint dwCtrlType, // DWORD
IntPtr pvCtrlPara // void* optional
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CertControlStore(
hCertStore As IntPtr, ' HCERTSTORE
dwFlags As UInteger, ' CERT_CONTROL_STORE_FLAGS
dwCtrlType As UInteger, ' DWORD
pvCtrlPara As IntPtr ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hCertStore : HCERTSTORE
' dwFlags : CERT_CONTROL_STORE_FLAGS
' dwCtrlType : DWORD
' pvCtrlPara : void* optional
Declare PtrSafe Function CertControlStore Lib "crypt32" ( _
ByVal hCertStore As LongPtr, _
ByVal dwFlags As Long, _
ByVal dwCtrlType As Long, _
ByVal pvCtrlPara As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CertControlStore = ctypes.windll.crypt32.CertControlStore
CertControlStore.restype = wintypes.BOOL
CertControlStore.argtypes = [
wintypes.HANDLE, # hCertStore : HCERTSTORE
wintypes.DWORD, # dwFlags : CERT_CONTROL_STORE_FLAGS
wintypes.DWORD, # dwCtrlType : DWORD
ctypes.POINTER(None), # pvCtrlPara : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CertControlStore = Fiddle::Function.new(
lib['CertControlStore'],
[
Fiddle::TYPE_VOIDP, # hCertStore : HCERTSTORE
-Fiddle::TYPE_INT, # dwFlags : CERT_CONTROL_STORE_FLAGS
-Fiddle::TYPE_INT, # dwCtrlType : DWORD
Fiddle::TYPE_VOIDP, # pvCtrlPara : void* optional
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CertControlStore(
hCertStore: *mut core::ffi::c_void, // HCERTSTORE
dwFlags: u32, // CERT_CONTROL_STORE_FLAGS
dwCtrlType: u32, // DWORD
pvCtrlPara: *const () // void* optional
) -> 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 CertControlStore(IntPtr hCertStore, uint dwFlags, uint dwCtrlType, IntPtr pvCtrlPara);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CertControlStore' -Namespace Win32 -PassThru
# $api::CertControlStore(hCertStore, dwFlags, dwCtrlType, pvCtrlPara)#uselib "CRYPT32.dll"
#func global CertControlStore "CertControlStore" sptr, sptr, sptr, sptr
; CertControlStore hCertStore, dwFlags, dwCtrlType, pvCtrlPara ; 戻り値は stat
; hCertStore : HCERTSTORE -> "sptr"
; dwFlags : CERT_CONTROL_STORE_FLAGS -> "sptr"
; dwCtrlType : DWORD -> "sptr"
; pvCtrlPara : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CRYPT32.dll"
#cfunc global CertControlStore "CertControlStore" sptr, int, int, sptr
; res = CertControlStore(hCertStore, dwFlags, dwCtrlType, pvCtrlPara)
; hCertStore : HCERTSTORE -> "sptr"
; dwFlags : CERT_CONTROL_STORE_FLAGS -> "int"
; dwCtrlType : DWORD -> "int"
; pvCtrlPara : void* optional -> "sptr"; BOOL CertControlStore(HCERTSTORE hCertStore, CERT_CONTROL_STORE_FLAGS dwFlags, DWORD dwCtrlType, void* pvCtrlPara)
#uselib "CRYPT32.dll"
#cfunc global CertControlStore "CertControlStore" intptr, int, int, intptr
; res = CertControlStore(hCertStore, dwFlags, dwCtrlType, pvCtrlPara)
; hCertStore : HCERTSTORE -> "intptr"
; dwFlags : CERT_CONTROL_STORE_FLAGS -> "int"
; dwCtrlType : DWORD -> "int"
; pvCtrlPara : void* optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCertControlStore = crypt32.NewProc("CertControlStore")
)
// hCertStore (HCERTSTORE), dwFlags (CERT_CONTROL_STORE_FLAGS), dwCtrlType (DWORD), pvCtrlPara (void* optional)
r1, _, err := procCertControlStore.Call(
uintptr(hCertStore),
uintptr(dwFlags),
uintptr(dwCtrlType),
uintptr(pvCtrlPara),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CertControlStore(
hCertStore: THandle; // HCERTSTORE
dwFlags: DWORD; // CERT_CONTROL_STORE_FLAGS
dwCtrlType: DWORD; // DWORD
pvCtrlPara: Pointer // void* optional
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CertControlStore';result := DllCall("CRYPT32\CertControlStore"
, "Ptr", hCertStore ; HCERTSTORE
, "UInt", dwFlags ; CERT_CONTROL_STORE_FLAGS
, "UInt", dwCtrlType ; DWORD
, "Ptr", pvCtrlPara ; void* optional
, "Int") ; return: BOOL●CertControlStore(hCertStore, dwFlags, dwCtrlType, pvCtrlPara) = DLL("CRYPT32.dll", "bool CertControlStore(void*, dword, dword, void*)")
# 呼び出し: CertControlStore(hCertStore, dwFlags, dwCtrlType, pvCtrlPara)
# hCertStore : HCERTSTORE -> "void*"
# dwFlags : CERT_CONTROL_STORE_FLAGS -> "dword"
# dwCtrlType : DWORD -> "dword"
# pvCtrlPara : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CertControlStore(
hCertStore: ?*anyopaque, // HCERTSTORE
dwFlags: u32, // CERT_CONTROL_STORE_FLAGS
dwCtrlType: u32, // DWORD
pvCtrlPara: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;proc CertControlStore(
hCertStore: pointer, # HCERTSTORE
dwFlags: uint32, # CERT_CONTROL_STORE_FLAGS
dwCtrlType: uint32, # DWORD
pvCtrlPara: pointer # void* optional
): int32 {.importc: "CertControlStore", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
int CertControlStore(
void* hCertStore, // HCERTSTORE
uint dwFlags, // CERT_CONTROL_STORE_FLAGS
uint dwCtrlType, // DWORD
void* pvCtrlPara // void* optional
);ccall((:CertControlStore, "CRYPT32.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, UInt32, Ptr{Cvoid}),
hCertStore, dwFlags, dwCtrlType, pvCtrlPara)
# hCertStore : HCERTSTORE -> Ptr{Cvoid}
# dwFlags : CERT_CONTROL_STORE_FLAGS -> UInt32
# dwCtrlType : DWORD -> UInt32
# pvCtrlPara : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CertControlStore(
void* hCertStore,
uint32_t dwFlags,
uint32_t dwCtrlType,
void* pvCtrlPara);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CertControlStore(hCertStore, dwFlags, dwCtrlType, pvCtrlPara)
-- hCertStore : HCERTSTORE
-- dwFlags : CERT_CONTROL_STORE_FLAGS
-- dwCtrlType : DWORD
-- pvCtrlPara : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CertControlStore = lib.func('__stdcall', 'CertControlStore', 'int32_t', ['void *', 'uint32_t', 'uint32_t', 'void *']);
// CertControlStore(hCertStore, dwFlags, dwCtrlType, pvCtrlPara)
// hCertStore : HCERTSTORE -> 'void *'
// dwFlags : CERT_CONTROL_STORE_FLAGS -> 'uint32_t'
// dwCtrlType : DWORD -> 'uint32_t'
// pvCtrlPara : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPT32.dll", {
CertControlStore: { parameters: ["pointer", "u32", "u32", "pointer"], result: "i32" },
});
// lib.symbols.CertControlStore(hCertStore, dwFlags, dwCtrlType, pvCtrlPara)
// hCertStore : HCERTSTORE -> "pointer"
// dwFlags : CERT_CONTROL_STORE_FLAGS -> "u32"
// dwCtrlType : DWORD -> "u32"
// pvCtrlPara : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CertControlStore(
void* hCertStore,
uint32_t dwFlags,
uint32_t dwCtrlType,
void* pvCtrlPara);
C, "CRYPT32.dll");
// $ffi->CertControlStore(hCertStore, dwFlags, dwCtrlType, pvCtrlPara);
// hCertStore : HCERTSTORE
// dwFlags : CERT_CONTROL_STORE_FLAGS
// dwCtrlType : DWORD
// pvCtrlPara : void* optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Crypt32 extends StdCallLibrary {
Crypt32 INSTANCE = Native.load("crypt32", Crypt32.class);
boolean CertControlStore(
Pointer hCertStore, // HCERTSTORE
int dwFlags, // CERT_CONTROL_STORE_FLAGS
int dwCtrlType, // DWORD
Pointer pvCtrlPara // void* optional
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CertControlStore = CertControlStore(
hCertStore : Void*, # HCERTSTORE
dwFlags : UInt32, # CERT_CONTROL_STORE_FLAGS
dwCtrlType : UInt32, # DWORD
pvCtrlPara : Void* # void* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CertControlStoreNative = Int32 Function(Pointer<Void>, Uint32, Uint32, Pointer<Void>);
typedef CertControlStoreDart = int Function(Pointer<Void>, int, int, Pointer<Void>);
final CertControlStore = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CertControlStoreNative, CertControlStoreDart>('CertControlStore');
// hCertStore : HCERTSTORE -> Pointer<Void>
// dwFlags : CERT_CONTROL_STORE_FLAGS -> Uint32
// dwCtrlType : DWORD -> Uint32
// pvCtrlPara : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CertControlStore(
hCertStore: THandle; // HCERTSTORE
dwFlags: DWORD; // CERT_CONTROL_STORE_FLAGS
dwCtrlType: DWORD; // DWORD
pvCtrlPara: Pointer // void* optional
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CertControlStore';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CertControlStore"
c_CertControlStore :: Ptr () -> Word32 -> Word32 -> Ptr () -> IO CInt
-- hCertStore : HCERTSTORE -> Ptr ()
-- dwFlags : CERT_CONTROL_STORE_FLAGS -> Word32
-- dwCtrlType : DWORD -> Word32
-- pvCtrlPara : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let certcontrolstore =
foreign "CertControlStore"
((ptr void) @-> uint32_t @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hCertStore : HCERTSTORE -> (ptr void) *)
(* dwFlags : CERT_CONTROL_STORE_FLAGS -> uint32_t *)
(* dwCtrlType : DWORD -> uint32_t *)
(* pvCtrlPara : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)
(cffi:defcfun ("CertControlStore" cert-control-store :convention :stdcall) :int32
(h-cert-store :pointer) ; HCERTSTORE
(dw-flags :uint32) ; CERT_CONTROL_STORE_FLAGS
(dw-ctrl-type :uint32) ; DWORD
(pv-ctrl-para :pointer)) ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CertControlStore = Win32::API::More->new('CRYPT32',
'BOOL CertControlStore(HANDLE hCertStore, DWORD dwFlags, DWORD dwCtrlType, LPVOID pvCtrlPara)');
# my $ret = $CertControlStore->Call($hCertStore, $dwFlags, $dwCtrlType, $pvCtrlPara);
# hCertStore : HCERTSTORE -> HANDLE
# dwFlags : CERT_CONTROL_STORE_FLAGS -> DWORD
# dwCtrlType : DWORD -> DWORD
# pvCtrlPara : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f CreateEventW — 名前付きまたは無名のイベントを作成する(Unicode版)。
- f WaitForSingleObjectEx — 警告可能モードで単一オブジェクトのシグナルを待機する。