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

CryptMsgCountersignEncoded

関数
エンコードされた署名者情報に副署名を付与する。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CryptMsgCountersignEncoded(
    DWORD dwEncodingType,
    BYTE* pbSignerInfo,
    DWORD cbSignerInfo,
    DWORD cCountersigners,
    CMSG_SIGNER_ENCODE_INFO* rgCountersigners,
    BYTE* pbCountersignature,   // optional
    DWORD* pcbCountersignature
);

パラメーター

名前方向
dwEncodingTypeDWORDin
pbSignerInfoBYTE*in
cbSignerInfoDWORDin
cCountersignersDWORDin
rgCountersignersCMSG_SIGNER_ENCODE_INFO*in
pbCountersignatureBYTE*outoptional
pcbCountersignatureDWORD*inout

戻り値の型: BOOL

各言語での呼び出し定義

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

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

CryptMsgCountersignEncoded = ctypes.windll.crypt32.CryptMsgCountersignEncoded
CryptMsgCountersignEncoded.restype = wintypes.BOOL
CryptMsgCountersignEncoded.argtypes = [
    wintypes.DWORD,  # dwEncodingType : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # pbSignerInfo : BYTE*
    wintypes.DWORD,  # cbSignerInfo : DWORD
    wintypes.DWORD,  # cCountersigners : DWORD
    ctypes.c_void_p,  # rgCountersigners : CMSG_SIGNER_ENCODE_INFO*
    ctypes.POINTER(ctypes.c_ubyte),  # pbCountersignature : BYTE* optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcbCountersignature : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCryptMsgCountersignEncoded = crypt32.NewProc("CryptMsgCountersignEncoded")
)

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