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

CryptMsgUpdate

関数
暗号メッセージにデータを追加して処理を更新する。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CryptMsgUpdate(
    void* hCryptMsg,
    const BYTE* pbData,   // optional
    DWORD cbData,
    BOOL fFinal
);

パラメーター

名前方向
hCryptMsgvoid*in
pbDataBYTE*inoptional
cbDataDWORDin
fFinalBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

CryptMsgUpdate = ctypes.windll.crypt32.CryptMsgUpdate
CryptMsgUpdate.restype = wintypes.BOOL
CryptMsgUpdate.argtypes = [
    ctypes.POINTER(None),  # hCryptMsg : void*
    ctypes.POINTER(ctypes.c_ubyte),  # pbData : BYTE* optional
    wintypes.DWORD,  # cbData : DWORD
    wintypes.BOOL,  # fFinal : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCryptMsgUpdate = crypt32.NewProc("CryptMsgUpdate")
)

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