ホーム › Security.Cryptography › CryptMsgDuplicate
CryptMsgDuplicate
関数暗号メッセージハンドルを複製して参照を増やす。
シグネチャ
// CRYPT32.dll
#include <windows.h>
void* CryptMsgDuplicate(
void* hCryptMsg // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hCryptMsg | void* | inoptional | 複製する暗号メッセージのハンドルです。複製は、メッセージの参照カウントをインクリメントすることで行われます。メッセージのコピーは作成されません。 |
戻り値の型: void*
公式ドキュメント
CryptMsgDuplicate 関数は、暗号メッセージハンドルの参照カウントをインクリメントすることで、ハンドルを複製します。
戻り値
返されるハンドルは、入力したハンドルと同じです。メッセージのコピーは作成されません。複製したメッセージハンドルの使用を終えたら、CryptMsgClose 関数を呼び出して参照カウントを減らしてください。
解説(Remarks)
CryptMsgDuplicate は、HCRYPTMSG ハンドルの参照カウントを増やすために使用されます。これにより、実際にハンドルを解放するには CryptMsgClose を複数回呼び出す必要が生じます。
例
この関数を使用する例については、例: ハッシュ済みメッセージをエンコードおよびデコードする C プログラムを参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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>
void* CryptMsgDuplicate(
void* hCryptMsg // optional
);[DllImport("CRYPT32.dll", ExactSpelling = true)]
static extern IntPtr CryptMsgDuplicate(
IntPtr hCryptMsg // void* optional
);<DllImport("CRYPT32.dll", ExactSpelling:=True)>
Public Shared Function CryptMsgDuplicate(
hCryptMsg As IntPtr ' void* optional
) As IntPtr
End Function' hCryptMsg : void* optional
Declare PtrSafe Function CryptMsgDuplicate Lib "crypt32" ( _
ByVal hCryptMsg As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptMsgDuplicate = ctypes.windll.crypt32.CryptMsgDuplicate
CryptMsgDuplicate.restype = ctypes.c_void_p
CryptMsgDuplicate.argtypes = [
ctypes.POINTER(None), # hCryptMsg : void* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptMsgDuplicate = Fiddle::Function.new(
lib['CryptMsgDuplicate'],
[
Fiddle::TYPE_VOIDP, # hCryptMsg : void* optional
],
Fiddle::TYPE_VOIDP)#[link(name = "crypt32")]
extern "system" {
fn CryptMsgDuplicate(
hCryptMsg: *mut () // void* optional
) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("CRYPT32.dll")]
public static extern IntPtr CryptMsgDuplicate(IntPtr hCryptMsg);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptMsgDuplicate' -Namespace Win32 -PassThru
# $api::CryptMsgDuplicate(hCryptMsg)#uselib "CRYPT32.dll"
#func global CryptMsgDuplicate "CryptMsgDuplicate" sptr
; CryptMsgDuplicate hCryptMsg ; 戻り値は stat
; hCryptMsg : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CRYPT32.dll"
#cfunc global CryptMsgDuplicate "CryptMsgDuplicate" sptr
; res = CryptMsgDuplicate(hCryptMsg)
; hCryptMsg : void* optional -> "sptr"; void* CryptMsgDuplicate(void* hCryptMsg)
#uselib "CRYPT32.dll"
#cfunc global CryptMsgDuplicate "CryptMsgDuplicate" intptr
; res = CryptMsgDuplicate(hCryptMsg)
; hCryptMsg : void* optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptMsgDuplicate = crypt32.NewProc("CryptMsgDuplicate")
)
// hCryptMsg (void* optional)
r1, _, err := procCryptMsgDuplicate.Call(
uintptr(hCryptMsg),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // void*function CryptMsgDuplicate(
hCryptMsg: Pointer // void* optional
): Pointer; stdcall;
external 'CRYPT32.dll' name 'CryptMsgDuplicate';result := DllCall("CRYPT32\CryptMsgDuplicate"
, "Ptr", hCryptMsg ; void* optional
, "Ptr") ; return: void*●CryptMsgDuplicate(hCryptMsg) = DLL("CRYPT32.dll", "void* CryptMsgDuplicate(void*)")
# 呼び出し: CryptMsgDuplicate(hCryptMsg)
# hCryptMsg : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CryptMsgDuplicate(
hCryptMsg: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc CryptMsgDuplicate(
hCryptMsg: pointer # void* optional
): pointer {.importc: "CryptMsgDuplicate", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
void* CryptMsgDuplicate(
void* hCryptMsg // void* optional
);ccall((:CryptMsgDuplicate, "CRYPT32.dll"), stdcall, Ptr{Cvoid},
(Ptr{Cvoid},),
hCryptMsg)
# hCryptMsg : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* CryptMsgDuplicate(
void* hCryptMsg);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptMsgDuplicate(hCryptMsg)
-- hCryptMsg : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptMsgDuplicate = lib.func('__stdcall', 'CryptMsgDuplicate', 'void *', ['void *']);
// CryptMsgDuplicate(hCryptMsg)
// hCryptMsg : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPT32.dll", {
CryptMsgDuplicate: { parameters: ["pointer"], result: "pointer" },
});
// lib.symbols.CryptMsgDuplicate(hCryptMsg)
// hCryptMsg : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* CryptMsgDuplicate(
void* hCryptMsg);
C, "CRYPT32.dll");
// $ffi->CryptMsgDuplicate(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);
Pointer CryptMsgDuplicate(
Pointer hCryptMsg // void* optional
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CryptMsgDuplicate = CryptMsgDuplicate(
hCryptMsg : Void* # void* optional
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CryptMsgDuplicateNative = Pointer<Void> Function(Pointer<Void>);
typedef CryptMsgDuplicateDart = Pointer<Void> Function(Pointer<Void>);
final CryptMsgDuplicate = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CryptMsgDuplicateNative, CryptMsgDuplicateDart>('CryptMsgDuplicate');
// hCryptMsg : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptMsgDuplicate(
hCryptMsg: Pointer // void* optional
): Pointer; stdcall;
external 'CRYPT32.dll' name 'CryptMsgDuplicate';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptMsgDuplicate"
c_CryptMsgDuplicate :: Ptr () -> IO (Ptr ())
-- hCryptMsg : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cryptmsgduplicate =
foreign "CryptMsgDuplicate"
((ptr void) @-> returning (ptr void))
(* 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 ("CryptMsgDuplicate" crypt-msg-duplicate :convention :stdcall) :pointer
(h-crypt-msg :pointer)) ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptMsgDuplicate = Win32::API::More->new('CRYPT32',
'LPVOID CryptMsgDuplicate(LPVOID hCryptMsg)');
# my $ret = $CryptMsgDuplicate->Call($hCryptMsg);
# hCryptMsg : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f CryptMsgClose — 暗号メッセージハンドルを閉じて解放する。