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

CertFreeCertificateContext

関数
証明書コンテキストを解放する。
DLLCRYPT32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

BOOL CertFreeCertificateContext(
    const CERT_CONTEXT* pCertContext   // optional
);

パラメーター

名前方向説明
pCertContextCERT_CONTEXT*inoptional解放する CERT_CONTEXT へのポインター。

戻り値の型: BOOL

公式ドキュメント

参照カウントをデクリメントすることで証明書コンテキストを解放します。参照カウントが 0 になると、CertFreeCertificateContext は証明書コンテキストが使用しているメモリを解放します。

戻り値

この関数は常に 0 以外の値を返します。

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

各言語での呼び出し定義

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

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

CertFreeCertificateContext = ctypes.windll.crypt32.CertFreeCertificateContext
CertFreeCertificateContext.restype = wintypes.BOOL
CertFreeCertificateContext.argtypes = [
    ctypes.c_void_p,  # pCertContext : CERT_CONTEXT* optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCertFreeCertificateContext = crypt32.NewProc("CertFreeCertificateContext")
)

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

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

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

foreign import stdcall safe "CertFreeCertificateContext"
  c_CertFreeCertificateContext :: Ptr () -> IO CInt
-- pCertContext : CERT_CONTEXT* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let certfreecertificatecontext =
  foreign "CertFreeCertificateContext"
    ((ptr void) @-> returning int32_t)
(* pCertContext : CERT_CONTEXT* 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 ("CertFreeCertificateContext" cert-free-certificate-context :convention :stdcall) :int32
  (p-cert-context :pointer))   ; CERT_CONTEXT* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CertFreeCertificateContext = Win32::API::More->new('CRYPT32',
    'BOOL CertFreeCertificateContext(LPVOID pCertContext)');
# my $ret = $CertFreeCertificateContext->Call($pCertContext);
# pCertContext : CERT_CONTEXT* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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