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

CertRegisterPhysicalStore

関数
物理証明書ストアを登録する。
DLLCRYPT32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

BOOL CertRegisterPhysicalStore(
    const void* pvSystemStore,
    DWORD dwFlags,
    LPCWSTR pwszStoreName,
    CERT_PHYSICAL_STORE_INFO* pStoreInfo,
    void* pvReserved   // optional
);

パラメーター

名前方向説明
pvSystemStorevoid*in物理ストアを追加する対象のシステムストアコレクション。このパラメーターは、null 終端の Unicode 文字列、または CERT_SYSTEM_STORE_RELOCATE_PARA 構造体のいずれかを指します。この構造体の使用方法、およびシステムストア名文字列の前に ServiceName や ComputerName を追加する方法については、 CertRegisterSystemStore を参照してください。
dwFlagsDWORDin

dwFlags パラメーターの上位ワードは、システムストアの場所を指定します。定義済みの上位ワードフラグ、およびシステムストア名の末尾に ServiceName、UserNames、ComputerNames を付加する方法については、 CertRegisterSystemStore を参照してください。

次の下位ワードフラグも定義されており、ビット単位の OR 演算によって上位ワードフラグと組み合わせることができます。

意味
CERT_SYSTEM_STORE_RELOCATE_FLAG
システムストアが既定のレジストリの場所にないため、pvSystemStore パラメーターは CERT_SYSTEM_STORE_RELOCATE_PARA 構造体へのポインターである必要があります。
CERT_STORE_CREATE_NEW_FLAG
ストアの場所に物理ストアが既に存在する場合、この関数は失敗します。
pwszStoreNameLPCWSTRinシステムストアコレクションに追加する物理ストアの名前を指定する Unicode 文字列へのポインター。システムストアコレクションから物理ストアを削除するには、CertUnregisterPhysicalStore 関数を呼び出します。
pStoreInfoCERT_PHYSICAL_STORE_INFO*in物理ストアに関する基本情報を提供する CERT_PHYSICAL_STORE_INFO 構造体へのポインター。
pvReservedvoid*optional将来の使用のために予約されており、NULL を設定する必要があります。

戻り値の型: BOOL

公式ドキュメント

レジストリのシステムストアコレクションに物理ストアを追加します。

戻り値

関数が成功した場合、非ゼロを返します。

関数が失敗した場合、ゼロを返します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL CertRegisterPhysicalStore(
    const void* pvSystemStore,
    DWORD dwFlags,
    LPCWSTR pwszStoreName,
    CERT_PHYSICAL_STORE_INFO* pStoreInfo,
    void* pvReserved   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", ExactSpelling = true)]
static extern bool CertRegisterPhysicalStore(
    IntPtr pvSystemStore,   // void*
    uint dwFlags,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string pwszStoreName,   // LPCWSTR
    IntPtr pStoreInfo,   // CERT_PHYSICAL_STORE_INFO*
    IntPtr pvReserved   // void* optional
);
<DllImport("CRYPT32.dll", ExactSpelling:=True)>
Public Shared Function CertRegisterPhysicalStore(
    pvSystemStore As IntPtr,   ' void*
    dwFlags As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> pwszStoreName As String,   ' LPCWSTR
    pStoreInfo As IntPtr,   ' CERT_PHYSICAL_STORE_INFO*
    pvReserved As IntPtr   ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' pvSystemStore : void*
' dwFlags : DWORD
' pwszStoreName : LPCWSTR
' pStoreInfo : CERT_PHYSICAL_STORE_INFO*
' pvReserved : void* optional
Declare PtrSafe Function CertRegisterPhysicalStore Lib "crypt32" ( _
    ByVal pvSystemStore As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal pwszStoreName As LongPtr, _
    ByVal pStoreInfo As LongPtr, _
    ByVal pvReserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CertRegisterPhysicalStore = ctypes.windll.crypt32.CertRegisterPhysicalStore
CertRegisterPhysicalStore.restype = wintypes.BOOL
CertRegisterPhysicalStore.argtypes = [
    ctypes.POINTER(None),  # pvSystemStore : void*
    wintypes.DWORD,  # dwFlags : DWORD
    wintypes.LPCWSTR,  # pwszStoreName : LPCWSTR
    ctypes.c_void_p,  # pStoreInfo : CERT_PHYSICAL_STORE_INFO*
    ctypes.POINTER(None),  # pvReserved : void* optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCertRegisterPhysicalStore = crypt32.NewProc("CertRegisterPhysicalStore")
)

// pvSystemStore (void*), dwFlags (DWORD), pwszStoreName (LPCWSTR), pStoreInfo (CERT_PHYSICAL_STORE_INFO*), pvReserved (void* optional)
r1, _, err := procCertRegisterPhysicalStore.Call(
	uintptr(pvSystemStore),
	uintptr(dwFlags),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszStoreName))),
	uintptr(pStoreInfo),
	uintptr(pvReserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CertRegisterPhysicalStore(
  pvSystemStore: Pointer;   // void*
  dwFlags: DWORD;   // DWORD
  pwszStoreName: PWideChar;   // LPCWSTR
  pStoreInfo: Pointer;   // CERT_PHYSICAL_STORE_INFO*
  pvReserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CertRegisterPhysicalStore';
result := DllCall("CRYPT32\CertRegisterPhysicalStore"
    , "Ptr", pvSystemStore   ; void*
    , "UInt", dwFlags   ; DWORD
    , "WStr", pwszStoreName   ; LPCWSTR
    , "Ptr", pStoreInfo   ; CERT_PHYSICAL_STORE_INFO*
    , "Ptr", pvReserved   ; void* optional
    , "Int")   ; return: BOOL
●CertRegisterPhysicalStore(pvSystemStore, dwFlags, pwszStoreName, pStoreInfo, pvReserved) = DLL("CRYPT32.dll", "bool CertRegisterPhysicalStore(void*, dword, char*, void*, void*)")
# 呼び出し: CertRegisterPhysicalStore(pvSystemStore, dwFlags, pwszStoreName, pStoreInfo, pvReserved)
# pvSystemStore : void* -> "void*"
# dwFlags : DWORD -> "dword"
# pwszStoreName : LPCWSTR -> "char*"
# pStoreInfo : CERT_PHYSICAL_STORE_INFO* -> "void*"
# pvReserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "crypt32" fn CertRegisterPhysicalStore(
    pvSystemStore: ?*anyopaque, // void*
    dwFlags: u32, // DWORD
    pwszStoreName: [*c]const u16, // LPCWSTR
    pStoreInfo: [*c]CERT_PHYSICAL_STORE_INFO, // CERT_PHYSICAL_STORE_INFO*
    pvReserved: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
proc CertRegisterPhysicalStore(
    pvSystemStore: pointer,  # void*
    dwFlags: uint32,  # DWORD
    pwszStoreName: WideCString,  # LPCWSTR
    pStoreInfo: ptr CERT_PHYSICAL_STORE_INFO,  # CERT_PHYSICAL_STORE_INFO*
    pvReserved: pointer  # void* optional
): int32 {.importc: "CertRegisterPhysicalStore", stdcall, dynlib: "CRYPT32.dll".}
pragma(lib, "crypt32");
extern(Windows)
int CertRegisterPhysicalStore(
    void* pvSystemStore,   // void*
    uint dwFlags,   // DWORD
    const(wchar)* pwszStoreName,   // LPCWSTR
    CERT_PHYSICAL_STORE_INFO* pStoreInfo,   // CERT_PHYSICAL_STORE_INFO*
    void* pvReserved   // void* optional
);
ccall((:CertRegisterPhysicalStore, "CRYPT32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, Cwstring, Ptr{CERT_PHYSICAL_STORE_INFO}, Ptr{Cvoid}),
      pvSystemStore, dwFlags, pwszStoreName, pStoreInfo, pvReserved)
# pvSystemStore : void* -> Ptr{Cvoid}
# dwFlags : DWORD -> UInt32
# pwszStoreName : LPCWSTR -> Cwstring
# pStoreInfo : CERT_PHYSICAL_STORE_INFO* -> Ptr{CERT_PHYSICAL_STORE_INFO}
# pvReserved : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CertRegisterPhysicalStore(
    void* pvSystemStore,
    uint32_t dwFlags,
    const uint16_t* pwszStoreName,
    void* pStoreInfo,
    void* pvReserved);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CertRegisterPhysicalStore(pvSystemStore, dwFlags, pwszStoreName, pStoreInfo, pvReserved)
-- pvSystemStore : void*
-- dwFlags : DWORD
-- pwszStoreName : LPCWSTR
-- pStoreInfo : CERT_PHYSICAL_STORE_INFO*
-- pvReserved : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CertRegisterPhysicalStore = lib.func('__stdcall', 'CertRegisterPhysicalStore', 'int32_t', ['void *', 'uint32_t', 'str16', 'void *', 'void *']);
// CertRegisterPhysicalStore(pvSystemStore, dwFlags, pwszStoreName, pStoreInfo, pvReserved)
// pvSystemStore : void* -> 'void *'
// dwFlags : DWORD -> 'uint32_t'
// pwszStoreName : LPCWSTR -> 'str16'
// pStoreInfo : CERT_PHYSICAL_STORE_INFO* -> 'void *'
// pvReserved : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CRYPT32.dll", {
  CertRegisterPhysicalStore: { parameters: ["pointer", "u32", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CertRegisterPhysicalStore(pvSystemStore, dwFlags, pwszStoreName, pStoreInfo, pvReserved)
// pvSystemStore : void* -> "pointer"
// dwFlags : DWORD -> "u32"
// pwszStoreName : LPCWSTR -> "buffer"
// pStoreInfo : CERT_PHYSICAL_STORE_INFO* -> "pointer"
// pvReserved : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CertRegisterPhysicalStore(
    void* pvSystemStore,
    uint32_t dwFlags,
    const uint16_t* pwszStoreName,
    void* pStoreInfo,
    void* pvReserved);
C, "CRYPT32.dll");
// $ffi->CertRegisterPhysicalStore(pvSystemStore, dwFlags, pwszStoreName, pStoreInfo, pvReserved);
// pvSystemStore : void*
// dwFlags : DWORD
// pwszStoreName : LPCWSTR
// pStoreInfo : CERT_PHYSICAL_STORE_INFO*
// pvReserved : 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 CertRegisterPhysicalStore(
        Pointer pvSystemStore,   // void*
        int dwFlags,   // DWORD
        WString pwszStoreName,   // LPCWSTR
        Pointer pStoreInfo,   // CERT_PHYSICAL_STORE_INFO*
        Pointer pvReserved   // void* optional
    );
}
@[Link("crypt32")]
lib LibCRYPT32
  fun CertRegisterPhysicalStore = CertRegisterPhysicalStore(
    pvSystemStore : Void*,   # void*
    dwFlags : UInt32,   # DWORD
    pwszStoreName : UInt16*,   # LPCWSTR
    pStoreInfo : CERT_PHYSICAL_STORE_INFO*,   # CERT_PHYSICAL_STORE_INFO*
    pvReserved : 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 CertRegisterPhysicalStoreNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
typedef CertRegisterPhysicalStoreDart = int Function(Pointer<Void>, int, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
final CertRegisterPhysicalStore = DynamicLibrary.open('CRYPT32.dll')
    .lookupFunction<CertRegisterPhysicalStoreNative, CertRegisterPhysicalStoreDart>('CertRegisterPhysicalStore');
// pvSystemStore : void* -> Pointer<Void>
// dwFlags : DWORD -> Uint32
// pwszStoreName : LPCWSTR -> Pointer<Utf16>
// pStoreInfo : CERT_PHYSICAL_STORE_INFO* -> Pointer<Void>
// pvReserved : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CertRegisterPhysicalStore(
  pvSystemStore: Pointer;   // void*
  dwFlags: DWORD;   // DWORD
  pwszStoreName: PWideChar;   // LPCWSTR
  pStoreInfo: Pointer;   // CERT_PHYSICAL_STORE_INFO*
  pvReserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CertRegisterPhysicalStore';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CertRegisterPhysicalStore"
  c_CertRegisterPhysicalStore :: Ptr () -> Word32 -> CWString -> Ptr () -> Ptr () -> IO CInt
-- pvSystemStore : void* -> Ptr ()
-- dwFlags : DWORD -> Word32
-- pwszStoreName : LPCWSTR -> CWString
-- pStoreInfo : CERT_PHYSICAL_STORE_INFO* -> Ptr ()
-- pvReserved : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let certregisterphysicalstore =
  foreign "CertRegisterPhysicalStore"
    ((ptr void) @-> uint32_t @-> (ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* pvSystemStore : void* -> (ptr void) *)
(* dwFlags : DWORD -> uint32_t *)
(* pwszStoreName : LPCWSTR -> (ptr uint16_t) *)
(* pStoreInfo : CERT_PHYSICAL_STORE_INFO* -> (ptr void) *)
(* pvReserved : 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 ("CertRegisterPhysicalStore" cert-register-physical-store :convention :stdcall) :int32
  (pv-system-store :pointer)   ; void*
  (dw-flags :uint32)   ; DWORD
  (pwsz-store-name (:string :encoding :utf-16le))   ; LPCWSTR
  (p-store-info :pointer)   ; CERT_PHYSICAL_STORE_INFO*
  (pv-reserved :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CertRegisterPhysicalStore = Win32::API::More->new('CRYPT32',
    'BOOL CertRegisterPhysicalStore(LPVOID pvSystemStore, DWORD dwFlags, LPCWSTR pwszStoreName, LPVOID pStoreInfo, LPVOID pvReserved)');
# my $ret = $CertRegisterPhysicalStore->Call($pvSystemStore, $dwFlags, $pwszStoreName, $pStoreInfo, $pvReserved);
# pvSystemStore : void* -> LPVOID
# dwFlags : DWORD -> DWORD
# pwszStoreName : LPCWSTR -> LPCWSTR
# pStoreInfo : CERT_PHYSICAL_STORE_INFO* -> LPVOID
# pvReserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型