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

CryptMsgCountersign

関数
暗号メッセージの署名者に副署名を付与する。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CryptMsgCountersign(
    void* hCryptMsg,
    DWORD dwIndex,
    DWORD cCountersigners,
    CMSG_SIGNER_ENCODE_INFO* rgCountersigners
);

パラメーター

名前方向
hCryptMsgvoid*in
dwIndexDWORDin
cCountersignersDWORDin
rgCountersignersCMSG_SIGNER_ENCODE_INFO*in

戻り値の型: BOOL

各言語での呼び出し定義

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

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

CryptMsgCountersign = ctypes.windll.crypt32.CryptMsgCountersign
CryptMsgCountersign.restype = wintypes.BOOL
CryptMsgCountersign.argtypes = [
    ctypes.POINTER(None),  # hCryptMsg : void*
    wintypes.DWORD,  # dwIndex : DWORD
    wintypes.DWORD,  # cCountersigners : DWORD
    ctypes.c_void_p,  # rgCountersigners : CMSG_SIGNER_ENCODE_INFO*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCryptMsgCountersign = crypt32.NewProc("CryptMsgCountersign")
)

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