ホーム › Security.Cryptography › CryptMsgCalculateEncodedLength
CryptMsgCalculateEncodedLength
関数エンコードされる暗号メッセージの長さを算出する。
シグネチャ
// CRYPT32.dll
#include <windows.h>
DWORD CryptMsgCalculateEncodedLength(
DWORD dwMsgEncodingType,
DWORD dwFlags,
DWORD dwMsgType,
const void* pvMsgEncodeInfo,
LPSTR pszInnerContentObjID, // optional
DWORD cbData
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dwMsgEncodingType | DWORD | in |
| dwFlags | DWORD | in |
| dwMsgType | DWORD | in |
| pvMsgEncodeInfo | void* | in |
| pszInnerContentObjID | LPSTR | inoptional |
| cbData | DWORD | in |
戻り値の型: DWORD
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
DWORD CryptMsgCalculateEncodedLength(
DWORD dwMsgEncodingType,
DWORD dwFlags,
DWORD dwMsgType,
const void* pvMsgEncodeInfo,
LPSTR pszInnerContentObjID, // optional
DWORD cbData
);[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern uint CryptMsgCalculateEncodedLength(
uint dwMsgEncodingType, // DWORD
uint dwFlags, // DWORD
uint dwMsgType, // DWORD
IntPtr pvMsgEncodeInfo, // void*
[MarshalAs(UnmanagedType.LPStr)] string pszInnerContentObjID, // LPSTR optional
uint cbData // DWORD
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptMsgCalculateEncodedLength(
dwMsgEncodingType As UInteger, ' DWORD
dwFlags As UInteger, ' DWORD
dwMsgType As UInteger, ' DWORD
pvMsgEncodeInfo As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPStr)> pszInnerContentObjID As String, ' LPSTR optional
cbData As UInteger ' DWORD
) As UInteger
End Function' dwMsgEncodingType : DWORD
' dwFlags : DWORD
' dwMsgType : DWORD
' pvMsgEncodeInfo : void*
' pszInnerContentObjID : LPSTR optional
' cbData : DWORD
Declare PtrSafe Function CryptMsgCalculateEncodedLength Lib "crypt32" ( _
ByVal dwMsgEncodingType As Long, _
ByVal dwFlags As Long, _
ByVal dwMsgType As Long, _
ByVal pvMsgEncodeInfo As LongPtr, _
ByVal pszInnerContentObjID As String, _
ByVal cbData As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptMsgCalculateEncodedLength = ctypes.windll.crypt32.CryptMsgCalculateEncodedLength
CryptMsgCalculateEncodedLength.restype = wintypes.DWORD
CryptMsgCalculateEncodedLength.argtypes = [
wintypes.DWORD, # dwMsgEncodingType : DWORD
wintypes.DWORD, # dwFlags : DWORD
wintypes.DWORD, # dwMsgType : DWORD
ctypes.POINTER(None), # pvMsgEncodeInfo : void*
wintypes.LPCSTR, # pszInnerContentObjID : LPSTR optional
wintypes.DWORD, # cbData : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptMsgCalculateEncodedLength = Fiddle::Function.new(
lib['CryptMsgCalculateEncodedLength'],
[
-Fiddle::TYPE_INT, # dwMsgEncodingType : DWORD
-Fiddle::TYPE_INT, # dwFlags : DWORD
-Fiddle::TYPE_INT, # dwMsgType : DWORD
Fiddle::TYPE_VOIDP, # pvMsgEncodeInfo : void*
Fiddle::TYPE_VOIDP, # pszInnerContentObjID : LPSTR optional
-Fiddle::TYPE_INT, # cbData : DWORD
],
-Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptMsgCalculateEncodedLength(
dwMsgEncodingType: u32, // DWORD
dwFlags: u32, // DWORD
dwMsgType: u32, // DWORD
pvMsgEncodeInfo: *const (), // void*
pszInnerContentObjID: *mut u8, // LPSTR optional
cbData: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("CRYPT32.dll", SetLastError = true)]
public static extern uint CryptMsgCalculateEncodedLength(uint dwMsgEncodingType, uint dwFlags, uint dwMsgType, IntPtr pvMsgEncodeInfo, [MarshalAs(UnmanagedType.LPStr)] string pszInnerContentObjID, uint cbData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptMsgCalculateEncodedLength' -Namespace Win32 -PassThru
# $api::CryptMsgCalculateEncodedLength(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, cbData)#uselib "CRYPT32.dll"
#func global CryptMsgCalculateEncodedLength "CryptMsgCalculateEncodedLength" sptr, sptr, sptr, sptr, sptr, sptr
; CryptMsgCalculateEncodedLength dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, cbData ; 戻り値は stat
; dwMsgEncodingType : DWORD -> "sptr"
; dwFlags : DWORD -> "sptr"
; dwMsgType : DWORD -> "sptr"
; pvMsgEncodeInfo : void* -> "sptr"
; pszInnerContentObjID : LPSTR optional -> "sptr"
; cbData : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CRYPT32.dll"
#cfunc global CryptMsgCalculateEncodedLength "CryptMsgCalculateEncodedLength" int, int, int, sptr, str, int
; res = CryptMsgCalculateEncodedLength(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, cbData)
; dwMsgEncodingType : DWORD -> "int"
; dwFlags : DWORD -> "int"
; dwMsgType : DWORD -> "int"
; pvMsgEncodeInfo : void* -> "sptr"
; pszInnerContentObjID : LPSTR optional -> "str"
; cbData : DWORD -> "int"; DWORD CryptMsgCalculateEncodedLength(DWORD dwMsgEncodingType, DWORD dwFlags, DWORD dwMsgType, void* pvMsgEncodeInfo, LPSTR pszInnerContentObjID, DWORD cbData)
#uselib "CRYPT32.dll"
#cfunc global CryptMsgCalculateEncodedLength "CryptMsgCalculateEncodedLength" int, int, int, intptr, str, int
; res = CryptMsgCalculateEncodedLength(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, cbData)
; dwMsgEncodingType : DWORD -> "int"
; dwFlags : DWORD -> "int"
; dwMsgType : DWORD -> "int"
; pvMsgEncodeInfo : void* -> "intptr"
; pszInnerContentObjID : LPSTR optional -> "str"
; cbData : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptMsgCalculateEncodedLength = crypt32.NewProc("CryptMsgCalculateEncodedLength")
)
// dwMsgEncodingType (DWORD), dwFlags (DWORD), dwMsgType (DWORD), pvMsgEncodeInfo (void*), pszInnerContentObjID (LPSTR optional), cbData (DWORD)
r1, _, err := procCryptMsgCalculateEncodedLength.Call(
uintptr(dwMsgEncodingType),
uintptr(dwFlags),
uintptr(dwMsgType),
uintptr(pvMsgEncodeInfo),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszInnerContentObjID))),
uintptr(cbData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction CryptMsgCalculateEncodedLength(
dwMsgEncodingType: DWORD; // DWORD
dwFlags: DWORD; // DWORD
dwMsgType: DWORD; // DWORD
pvMsgEncodeInfo: Pointer; // void*
pszInnerContentObjID: PAnsiChar; // LPSTR optional
cbData: DWORD // DWORD
): DWORD; stdcall;
external 'CRYPT32.dll' name 'CryptMsgCalculateEncodedLength';result := DllCall("CRYPT32\CryptMsgCalculateEncodedLength"
, "UInt", dwMsgEncodingType ; DWORD
, "UInt", dwFlags ; DWORD
, "UInt", dwMsgType ; DWORD
, "Ptr", pvMsgEncodeInfo ; void*
, "AStr", pszInnerContentObjID ; LPSTR optional
, "UInt", cbData ; DWORD
, "UInt") ; return: DWORD●CryptMsgCalculateEncodedLength(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, cbData) = DLL("CRYPT32.dll", "dword CryptMsgCalculateEncodedLength(dword, dword, dword, void*, char*, dword)")
# 呼び出し: CryptMsgCalculateEncodedLength(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, cbData)
# dwMsgEncodingType : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# dwMsgType : DWORD -> "dword"
# pvMsgEncodeInfo : void* -> "void*"
# pszInnerContentObjID : LPSTR optional -> "char*"
# cbData : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。