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

CertAddEncodedCTLToStore

関数
エンコードされたCTLをストアに追加する。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CertAddEncodedCTLToStore(
    HCERTSTORE hCertStore,   // optional
    CERT_QUERY_ENCODING_TYPE dwMsgAndCertEncodingType,
    const BYTE* pbCtlEncoded,
    DWORD cbCtlEncoded,
    DWORD dwAddDisposition,
    CTL_CONTEXT** ppCtlContext   // optional
);

パラメーター

名前方向
hCertStoreHCERTSTOREinoptional
dwMsgAndCertEncodingTypeCERT_QUERY_ENCODING_TYPEin
pbCtlEncodedBYTE*in
cbCtlEncodedDWORDin
dwAddDispositionDWORDin
ppCtlContextCTL_CONTEXT**outoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL CertAddEncodedCTLToStore(
    HCERTSTORE hCertStore,   // optional
    CERT_QUERY_ENCODING_TYPE dwMsgAndCertEncodingType,
    const BYTE* pbCtlEncoded,
    DWORD cbCtlEncoded,
    DWORD dwAddDisposition,
    CTL_CONTEXT** ppCtlContext   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CertAddEncodedCTLToStore(
    IntPtr hCertStore,   // HCERTSTORE optional
    uint dwMsgAndCertEncodingType,   // CERT_QUERY_ENCODING_TYPE
    IntPtr pbCtlEncoded,   // BYTE*
    uint cbCtlEncoded,   // DWORD
    uint dwAddDisposition,   // DWORD
    IntPtr ppCtlContext   // CTL_CONTEXT** optional, out
);
<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CertAddEncodedCTLToStore(
    hCertStore As IntPtr,   ' HCERTSTORE optional
    dwMsgAndCertEncodingType As UInteger,   ' CERT_QUERY_ENCODING_TYPE
    pbCtlEncoded As IntPtr,   ' BYTE*
    cbCtlEncoded As UInteger,   ' DWORD
    dwAddDisposition As UInteger,   ' DWORD
    ppCtlContext As IntPtr   ' CTL_CONTEXT** optional, out
) As Boolean
End Function
' hCertStore : HCERTSTORE optional
' dwMsgAndCertEncodingType : CERT_QUERY_ENCODING_TYPE
' pbCtlEncoded : BYTE*
' cbCtlEncoded : DWORD
' dwAddDisposition : DWORD
' ppCtlContext : CTL_CONTEXT** optional, out
Declare PtrSafe Function CertAddEncodedCTLToStore Lib "crypt32" ( _
    ByVal hCertStore As LongPtr, _
    ByVal dwMsgAndCertEncodingType As Long, _
    ByVal pbCtlEncoded As LongPtr, _
    ByVal cbCtlEncoded As Long, _
    ByVal dwAddDisposition As Long, _
    ByVal ppCtlContext As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CertAddEncodedCTLToStore = ctypes.windll.crypt32.CertAddEncodedCTLToStore
CertAddEncodedCTLToStore.restype = wintypes.BOOL
CertAddEncodedCTLToStore.argtypes = [
    wintypes.HANDLE,  # hCertStore : HCERTSTORE optional
    wintypes.DWORD,  # dwMsgAndCertEncodingType : CERT_QUERY_ENCODING_TYPE
    ctypes.POINTER(ctypes.c_ubyte),  # pbCtlEncoded : BYTE*
    wintypes.DWORD,  # cbCtlEncoded : DWORD
    wintypes.DWORD,  # dwAddDisposition : DWORD
    ctypes.c_void_p,  # ppCtlContext : CTL_CONTEXT** optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CRYPT32.dll')
CertAddEncodedCTLToStore = Fiddle::Function.new(
  lib['CertAddEncodedCTLToStore'],
  [
    Fiddle::TYPE_VOIDP,  # hCertStore : HCERTSTORE optional
    -Fiddle::TYPE_INT,  # dwMsgAndCertEncodingType : CERT_QUERY_ENCODING_TYPE
    Fiddle::TYPE_VOIDP,  # pbCtlEncoded : BYTE*
    -Fiddle::TYPE_INT,  # cbCtlEncoded : DWORD
    -Fiddle::TYPE_INT,  # dwAddDisposition : DWORD
    Fiddle::TYPE_VOIDP,  # ppCtlContext : CTL_CONTEXT** optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "crypt32")]
extern "system" {
    fn CertAddEncodedCTLToStore(
        hCertStore: *mut core::ffi::c_void,  // HCERTSTORE optional
        dwMsgAndCertEncodingType: u32,  // CERT_QUERY_ENCODING_TYPE
        pbCtlEncoded: *const u8,  // BYTE*
        cbCtlEncoded: u32,  // DWORD
        dwAddDisposition: u32,  // DWORD
        ppCtlContext: *mut *mut CTL_CONTEXT  // CTL_CONTEXT** optional, 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 CertAddEncodedCTLToStore(IntPtr hCertStore, uint dwMsgAndCertEncodingType, IntPtr pbCtlEncoded, uint cbCtlEncoded, uint dwAddDisposition, IntPtr ppCtlContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CertAddEncodedCTLToStore' -Namespace Win32 -PassThru
# $api::CertAddEncodedCTLToStore(hCertStore, dwMsgAndCertEncodingType, pbCtlEncoded, cbCtlEncoded, dwAddDisposition, ppCtlContext)
#uselib "CRYPT32.dll"
#func global CertAddEncodedCTLToStore "CertAddEncodedCTLToStore" sptr, sptr, sptr, sptr, sptr, sptr
; CertAddEncodedCTLToStore hCertStore, dwMsgAndCertEncodingType, varptr(pbCtlEncoded), cbCtlEncoded, dwAddDisposition, varptr(ppCtlContext)   ; 戻り値は stat
; hCertStore : HCERTSTORE optional -> "sptr"
; dwMsgAndCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "sptr"
; pbCtlEncoded : BYTE* -> "sptr"
; cbCtlEncoded : DWORD -> "sptr"
; dwAddDisposition : DWORD -> "sptr"
; ppCtlContext : CTL_CONTEXT** optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CRYPT32.dll"
#cfunc global CertAddEncodedCTLToStore "CertAddEncodedCTLToStore" sptr, int, var, int, int, var
; res = CertAddEncodedCTLToStore(hCertStore, dwMsgAndCertEncodingType, pbCtlEncoded, cbCtlEncoded, dwAddDisposition, ppCtlContext)
; hCertStore : HCERTSTORE optional -> "sptr"
; dwMsgAndCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int"
; pbCtlEncoded : BYTE* -> "var"
; cbCtlEncoded : DWORD -> "int"
; dwAddDisposition : DWORD -> "int"
; ppCtlContext : CTL_CONTEXT** optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CertAddEncodedCTLToStore(HCERTSTORE hCertStore, CERT_QUERY_ENCODING_TYPE dwMsgAndCertEncodingType, BYTE* pbCtlEncoded, DWORD cbCtlEncoded, DWORD dwAddDisposition, CTL_CONTEXT** ppCtlContext)
#uselib "CRYPT32.dll"
#cfunc global CertAddEncodedCTLToStore "CertAddEncodedCTLToStore" intptr, int, var, int, int, var
; res = CertAddEncodedCTLToStore(hCertStore, dwMsgAndCertEncodingType, pbCtlEncoded, cbCtlEncoded, dwAddDisposition, ppCtlContext)
; hCertStore : HCERTSTORE optional -> "intptr"
; dwMsgAndCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int"
; pbCtlEncoded : BYTE* -> "var"
; cbCtlEncoded : DWORD -> "int"
; dwAddDisposition : DWORD -> "int"
; ppCtlContext : CTL_CONTEXT** optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCertAddEncodedCTLToStore = crypt32.NewProc("CertAddEncodedCTLToStore")
)

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