ホーム › Security.Cryptography › CryptMsgClose
CryptMsgClose
関数暗号メッセージハンドルを閉じて解放する。
シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptMsgClose(
void* hCryptMsg // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hCryptMsg | void* | inoptional | 閉じる暗号メッセージのハンドル。 |
戻り値の型: BOOL
公式ドキュメント
CryptMsgClose 関数は、暗号メッセージのハンドルを閉じます。この関数を呼び出すたびに、メッセージの参照カウントが 1 つ減ります。参照カウントが 0 に達すると、メッセージは完全に解放されます。
戻り値
関数が成功した場合は、0 以外の値 (TRUE) を返します。
関数が失敗した場合は、0 (FALSE) を返します。拡張エラー情報を取得するには、 GetLastError を呼び出します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptMsgClose(
void* hCryptMsg // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptMsgClose(
IntPtr hCryptMsg // void* optional
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptMsgClose(
hCryptMsg As IntPtr ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hCryptMsg : void* optional
Declare PtrSafe Function CryptMsgClose Lib "crypt32" ( _
ByVal hCryptMsg As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptMsgClose = ctypes.windll.crypt32.CryptMsgClose
CryptMsgClose.restype = wintypes.BOOL
CryptMsgClose.argtypes = [
ctypes.POINTER(None), # hCryptMsg : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptMsgClose = Fiddle::Function.new(
lib['CryptMsgClose'],
[
Fiddle::TYPE_VOIDP, # hCryptMsg : void* optional
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptMsgClose(
hCryptMsg: *mut () // 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 CryptMsgClose(IntPtr hCryptMsg);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptMsgClose' -Namespace Win32 -PassThru
# $api::CryptMsgClose(hCryptMsg)#uselib "CRYPT32.dll"
#func global CryptMsgClose "CryptMsgClose" sptr
; CryptMsgClose hCryptMsg ; 戻り値は stat
; hCryptMsg : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CRYPT32.dll"
#cfunc global CryptMsgClose "CryptMsgClose" sptr
; res = CryptMsgClose(hCryptMsg)
; hCryptMsg : void* optional -> "sptr"; BOOL CryptMsgClose(void* hCryptMsg)
#uselib "CRYPT32.dll"
#cfunc global CryptMsgClose "CryptMsgClose" intptr
; res = CryptMsgClose(hCryptMsg)
; hCryptMsg : void* optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptMsgClose = crypt32.NewProc("CryptMsgClose")
)
// hCryptMsg (void* optional)
r1, _, err := procCryptMsgClose.Call(
uintptr(hCryptMsg),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptMsgClose(
hCryptMsg: Pointer // void* optional
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptMsgClose';result := DllCall("CRYPT32\CryptMsgClose"
, "Ptr", hCryptMsg ; void* optional
, "Int") ; return: BOOL●CryptMsgClose(hCryptMsg) = DLL("CRYPT32.dll", "bool CryptMsgClose(void*)")
# 呼び出し: CryptMsgClose(hCryptMsg)
# hCryptMsg : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CryptMsgClose(
hCryptMsg: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;proc CryptMsgClose(
hCryptMsg: pointer # void* optional
): int32 {.importc: "CryptMsgClose", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
int CryptMsgClose(
void* hCryptMsg // void* optional
);ccall((:CryptMsgClose, "CRYPT32.dll"), stdcall, Int32,
(Ptr{Cvoid},),
hCryptMsg)
# hCryptMsg : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CryptMsgClose(
void* hCryptMsg);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptMsgClose(hCryptMsg)
-- hCryptMsg : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptMsgClose = lib.func('__stdcall', 'CryptMsgClose', 'int32_t', ['void *']);
// CryptMsgClose(hCryptMsg)
// hCryptMsg : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPT32.dll", {
CryptMsgClose: { parameters: ["pointer"], result: "i32" },
});
// lib.symbols.CryptMsgClose(hCryptMsg)
// hCryptMsg : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CryptMsgClose(
void* hCryptMsg);
C, "CRYPT32.dll");
// $ffi->CryptMsgClose(hCryptMsg);
// hCryptMsg : 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 CryptMsgClose(
Pointer hCryptMsg // void* optional
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CryptMsgClose = CryptMsgClose(
hCryptMsg : 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 CryptMsgCloseNative = Int32 Function(Pointer<Void>);
typedef CryptMsgCloseDart = int Function(Pointer<Void>);
final CryptMsgClose = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CryptMsgCloseNative, CryptMsgCloseDart>('CryptMsgClose');
// hCryptMsg : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptMsgClose(
hCryptMsg: Pointer // void* optional
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptMsgClose';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptMsgClose"
c_CryptMsgClose :: Ptr () -> IO CInt
-- hCryptMsg : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cryptmsgclose =
foreign "CryptMsgClose"
((ptr void) @-> returning int32_t)
(* hCryptMsg : 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 ("CryptMsgClose" crypt-msg-close :convention :stdcall) :int32
(h-crypt-msg :pointer)) ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptMsgClose = Win32::API::More->new('CRYPT32',
'BOOL CryptMsgClose(LPVOID hCryptMsg)');
# my $ret = $CryptMsgClose->Call($hCryptMsg);
# hCryptMsg : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f CryptMsgOpenToDecode — デコード用の暗号メッセージを開く。
- f CryptMsgOpenToEncode — エンコード用の暗号メッセージ(PKCS#7/CMS)を開く。