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

CryptDuplicateHash

関数
ハッシュオブジェクトを複製して状態をコピーする。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CryptDuplicateHash(
    UINT_PTR hHash,
    DWORD* pdwReserved,   // optional
    DWORD dwFlags,
    UINT_PTR* phHash
);

パラメーター

名前方向
hHashUINT_PTRin
pdwReservedDWORD*optional
dwFlagsDWORDin
phHashUINT_PTR*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL CryptDuplicateHash(
    UINT_PTR hHash,
    DWORD* pdwReserved,   // optional
    DWORD dwFlags,
    UINT_PTR* phHash
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptDuplicateHash(
    UIntPtr hHash,   // UINT_PTR
    IntPtr pdwReserved,   // DWORD* optional
    uint dwFlags,   // DWORD
    out UIntPtr phHash   // UINT_PTR* out
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptDuplicateHash(
    hHash As UIntPtr,   ' UINT_PTR
    pdwReserved As IntPtr,   ' DWORD* optional
    dwFlags As UInteger,   ' DWORD
    <Out> ByRef phHash As UIntPtr   ' UINT_PTR* out
) As Boolean
End Function
' hHash : UINT_PTR
' pdwReserved : DWORD* optional
' dwFlags : DWORD
' phHash : UINT_PTR* out
Declare PtrSafe Function CryptDuplicateHash Lib "advapi32" ( _
    ByVal hHash As LongPtr, _
    ByVal pdwReserved As LongPtr, _
    ByVal dwFlags As Long, _
    ByRef phHash As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CryptDuplicateHash = ctypes.windll.advapi32.CryptDuplicateHash
CryptDuplicateHash.restype = wintypes.BOOL
CryptDuplicateHash.argtypes = [
    ctypes.c_size_t,  # hHash : UINT_PTR
    ctypes.POINTER(wintypes.DWORD),  # pdwReserved : DWORD* optional
    wintypes.DWORD,  # dwFlags : DWORD
    ctypes.POINTER(ctypes.c_size_t),  # phHash : UINT_PTR* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procCryptDuplicateHash = advapi32.NewProc("CryptDuplicateHash")
)

// hHash (UINT_PTR), pdwReserved (DWORD* optional), dwFlags (DWORD), phHash (UINT_PTR* out)
r1, _, err := procCryptDuplicateHash.Call(
	uintptr(hHash),
	uintptr(pdwReserved),
	uintptr(dwFlags),
	uintptr(phHash),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CryptDuplicateHash(
  hHash: NativeUInt;   // UINT_PTR
  pdwReserved: Pointer;   // DWORD* optional
  dwFlags: DWORD;   // DWORD
  phHash: Pointer   // UINT_PTR* out
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'CryptDuplicateHash';
result := DllCall("ADVAPI32\CryptDuplicateHash"
    , "UPtr", hHash   ; UINT_PTR
    , "Ptr", pdwReserved   ; DWORD* optional
    , "UInt", dwFlags   ; DWORD
    , "Ptr", phHash   ; UINT_PTR* out
    , "Int")   ; return: BOOL
●CryptDuplicateHash(hHash, pdwReserved, dwFlags, phHash) = DLL("ADVAPI32.dll", "bool CryptDuplicateHash(int, void*, dword, void*)")
# 呼び出し: CryptDuplicateHash(hHash, pdwReserved, dwFlags, phHash)
# hHash : UINT_PTR -> "int"
# pdwReserved : DWORD* optional -> "void*"
# dwFlags : DWORD -> "dword"
# phHash : UINT_PTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。