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

CertCreateCertificateChainEngine

関数
証明書チェーン構築用のチェーンエンジンを作成する。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CertCreateCertificateChainEngine(
    CERT_CHAIN_ENGINE_CONFIG* pConfig,
    HCERTCHAINENGINE* phChainEngine
);

パラメーター

名前方向説明
pConfigCERT_CHAIN_ENGINE_CONFIG*inチェーンエンジンのパラメーターを指定する CERT_CHAIN_ENGINE_CONFIG データ構造体へのポインターです。
phChainEngineHCERTCHAINENGINE*out作成されたチェーンエンジンのハンドルへのポインターです。チェーンエンジンの使用を終えたら、CertFreeCertificateChainEngine 関数を呼び出してチェーンエンジンを解放してください。

戻り値の型: BOOL

公式ドキュメント

CertCreateCertificateChainEngine 関数は、アプリケーション用の新しい非既定のチェーンエンジンを作成します。

戻り値

関数が成功した場合は、0 以外の値(TRUE)を返します。

関数が失敗した場合は、0(FALSE)を返します。拡張エラー情報を取得するには、 GetLastError を呼び出します。

phChainEngine パラメーターはチェーンエンジンのハンドルを返します。

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

各言語での呼び出し定義

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

BOOL CertCreateCertificateChainEngine(
    CERT_CHAIN_ENGINE_CONFIG* pConfig,
    HCERTCHAINENGINE* phChainEngine
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CertCreateCertificateChainEngine(
    IntPtr pConfig,   // CERT_CHAIN_ENGINE_CONFIG*
    IntPtr phChainEngine   // HCERTCHAINENGINE* out
);
<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CertCreateCertificateChainEngine(
    pConfig As IntPtr,   ' CERT_CHAIN_ENGINE_CONFIG*
    phChainEngine As IntPtr   ' HCERTCHAINENGINE* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' pConfig : CERT_CHAIN_ENGINE_CONFIG*
' phChainEngine : HCERTCHAINENGINE* out
Declare PtrSafe Function CertCreateCertificateChainEngine Lib "crypt32" ( _
    ByVal pConfig As LongPtr, _
    ByVal phChainEngine As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CertCreateCertificateChainEngine = ctypes.windll.crypt32.CertCreateCertificateChainEngine
CertCreateCertificateChainEngine.restype = wintypes.BOOL
CertCreateCertificateChainEngine.argtypes = [
    ctypes.c_void_p,  # pConfig : CERT_CHAIN_ENGINE_CONFIG*
    ctypes.c_void_p,  # phChainEngine : HCERTCHAINENGINE* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCertCreateCertificateChainEngine = crypt32.NewProc("CertCreateCertificateChainEngine")
)

// pConfig (CERT_CHAIN_ENGINE_CONFIG*), phChainEngine (HCERTCHAINENGINE* out)
r1, _, err := procCertCreateCertificateChainEngine.Call(
	uintptr(pConfig),
	uintptr(phChainEngine),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CertCreateCertificateChainEngine(
  pConfig: Pointer;   // CERT_CHAIN_ENGINE_CONFIG*
  phChainEngine: Pointer   // HCERTCHAINENGINE* out
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CertCreateCertificateChainEngine';
result := DllCall("CRYPT32\CertCreateCertificateChainEngine"
    , "Ptr", pConfig   ; CERT_CHAIN_ENGINE_CONFIG*
    , "Ptr", phChainEngine   ; HCERTCHAINENGINE* out
    , "Int")   ; return: BOOL
●CertCreateCertificateChainEngine(pConfig, phChainEngine) = DLL("CRYPT32.dll", "bool CertCreateCertificateChainEngine(void*, void*)")
# 呼び出し: CertCreateCertificateChainEngine(pConfig, phChainEngine)
# pConfig : CERT_CHAIN_ENGINE_CONFIG* -> "void*"
# phChainEngine : HCERTCHAINENGINE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "crypt32" fn CertCreateCertificateChainEngine(
    pConfig: [*c]CERT_CHAIN_ENGINE_CONFIG, // CERT_CHAIN_ENGINE_CONFIG*
    phChainEngine: ?*anyopaque // HCERTCHAINENGINE* out
) callconv(std.os.windows.WINAPI) i32;
proc CertCreateCertificateChainEngine(
    pConfig: ptr CERT_CHAIN_ENGINE_CONFIG,  # CERT_CHAIN_ENGINE_CONFIG*
    phChainEngine: pointer  # HCERTCHAINENGINE* out
): int32 {.importc: "CertCreateCertificateChainEngine", stdcall, dynlib: "CRYPT32.dll".}
pragma(lib, "crypt32");
extern(Windows)
int CertCreateCertificateChainEngine(
    CERT_CHAIN_ENGINE_CONFIG* pConfig,   // CERT_CHAIN_ENGINE_CONFIG*
    void* phChainEngine   // HCERTCHAINENGINE* out
);
ccall((:CertCreateCertificateChainEngine, "CRYPT32.dll"), stdcall, Int32,
      (Ptr{CERT_CHAIN_ENGINE_CONFIG}, Ptr{Cvoid}),
      pConfig, phChainEngine)
# pConfig : CERT_CHAIN_ENGINE_CONFIG* -> Ptr{CERT_CHAIN_ENGINE_CONFIG}
# phChainEngine : HCERTCHAINENGINE* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CertCreateCertificateChainEngine(
    void* pConfig,
    void* phChainEngine);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CertCreateCertificateChainEngine(pConfig, phChainEngine)
-- pConfig : CERT_CHAIN_ENGINE_CONFIG*
-- phChainEngine : HCERTCHAINENGINE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CertCreateCertificateChainEngine = lib.func('__stdcall', 'CertCreateCertificateChainEngine', 'int32_t', ['void *', 'void *']);
// CertCreateCertificateChainEngine(pConfig, phChainEngine)
// pConfig : CERT_CHAIN_ENGINE_CONFIG* -> 'void *'
// phChainEngine : HCERTCHAINENGINE* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CRYPT32.dll", {
  CertCreateCertificateChainEngine: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.CertCreateCertificateChainEngine(pConfig, phChainEngine)
// pConfig : CERT_CHAIN_ENGINE_CONFIG* -> "pointer"
// phChainEngine : HCERTCHAINENGINE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CertCreateCertificateChainEngine(
    void* pConfig,
    void* phChainEngine);
C, "CRYPT32.dll");
// $ffi->CertCreateCertificateChainEngine(pConfig, phChainEngine);
// pConfig : CERT_CHAIN_ENGINE_CONFIG*
// phChainEngine : HCERTCHAINENGINE* out
// 構造体/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 CertCreateCertificateChainEngine(
        Pointer pConfig,   // CERT_CHAIN_ENGINE_CONFIG*
        Pointer phChainEngine   // HCERTCHAINENGINE* out
    );
}
@[Link("crypt32")]
lib LibCRYPT32
  fun CertCreateCertificateChainEngine = CertCreateCertificateChainEngine(
    pConfig : CERT_CHAIN_ENGINE_CONFIG*,   # CERT_CHAIN_ENGINE_CONFIG*
    phChainEngine : Void*   # HCERTCHAINENGINE* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CertCreateCertificateChainEngineNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef CertCreateCertificateChainEngineDart = int Function(Pointer<Void>, Pointer<Void>);
final CertCreateCertificateChainEngine = DynamicLibrary.open('CRYPT32.dll')
    .lookupFunction<CertCreateCertificateChainEngineNative, CertCreateCertificateChainEngineDart>('CertCreateCertificateChainEngine');
// pConfig : CERT_CHAIN_ENGINE_CONFIG* -> Pointer<Void>
// phChainEngine : HCERTCHAINENGINE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CertCreateCertificateChainEngine(
  pConfig: Pointer;   // CERT_CHAIN_ENGINE_CONFIG*
  phChainEngine: Pointer   // HCERTCHAINENGINE* out
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CertCreateCertificateChainEngine';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CertCreateCertificateChainEngine"
  c_CertCreateCertificateChainEngine :: Ptr () -> Ptr () -> IO CInt
-- pConfig : CERT_CHAIN_ENGINE_CONFIG* -> Ptr ()
-- phChainEngine : HCERTCHAINENGINE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let certcreatecertificatechainengine =
  foreign "CertCreateCertificateChainEngine"
    ((ptr void) @-> (ptr void) @-> returning int32_t)
(* pConfig : CERT_CHAIN_ENGINE_CONFIG* -> (ptr void) *)
(* phChainEngine : HCERTCHAINENGINE* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)

(cffi:defcfun ("CertCreateCertificateChainEngine" cert-create-certificate-chain-engine :convention :stdcall) :int32
  (p-config :pointer)   ; CERT_CHAIN_ENGINE_CONFIG*
  (ph-chain-engine :pointer))   ; HCERTCHAINENGINE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CertCreateCertificateChainEngine = Win32::API::More->new('CRYPT32',
    'BOOL CertCreateCertificateChainEngine(LPVOID pConfig, HANDLE phChainEngine)');
# my $ret = $CertCreateCertificateChainEngine->Call($pConfig, $phChainEngine);
# pConfig : CERT_CHAIN_ENGINE_CONFIG* -> LPVOID
# phChainEngine : HCERTCHAINENGINE* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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