CryptFormatObject
関数シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptFormatObject(
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
DWORD dwFormatType,
DWORD dwFormatStrType,
void* pFormatStruct, // optional
LPCSTR lpszStructType, // optional
const BYTE* pbEncoded,
DWORD cbEncoded,
void* pbFormat, // optional
DWORD* pcbFormat
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| dwCertEncodingType | CERT_QUERY_ENCODING_TYPE | in | 証明書で使用されるエンコードの種別です。現在定義されている証明書エンコード種別として使用されるのは X509_ASN_ENCODING です。 | ||||||||
| dwFormatType | DWORD | in | 書式種別の値です。使用されません。0 を設定してください。 | ||||||||
| dwFormatStrType | DWORD | in | 構造体の書式種別の値です。このパラメーターには 0 を指定できるほか、ビットごとの OR 演算子で組み合わせることにより、次のフラグを 1 つ以上指定できます。
| ||||||||
| pFormatStruct | void* | inoptional | 構造体の書式へのポインターです。使用されません。NULL を設定してください。 | ||||||||
| lpszStructType | LPCSTR | inoptional | エンコードされたデータを定義する OID へのポインターです。lpszStructType パラメーターの上位ワードが 0 の場合、下位ワードは指定された構造体の種別を表す整数識別子を指定します。そうでない場合、このパラメーターは null で終端された文字列へのロングポインターです。 次の表に、サポートされる OID とそれに関連付けられた OID 拡張を示します。 | ||||||||
| pbEncoded | BYTE* | in | 書式化対象のエンコードされたデータへのポインターです。lpszStructType が上記の OID のいずれかである場合、pbEncoded はエンコードされた拡張です。 | ||||||||
| cbEncoded | DWORD | in | pbEncoded 構造体のサイズ (バイト単位) です。 | ||||||||
| pbFormat | void* | outoptional | 書式化された文字列を受け取るバッファーへのポインターです。指定されたバッファーがデコードされた構造体を受け取るのに十分な大きさでない場合、関数は ERROR_MORE_DATA を設定し、必要なバッファーサイズ (バイト単位) を pcbFormat が指す変数に格納します。このパラメーターは、メモリ割り当てを目的として情報のサイズを取得するために NULL にすることができます。詳細については「Retrieving Data of Unknown Length」を参照してください。 | ||||||||
| pcbFormat | DWORD* | inout | pbFormat パラメーターが指すバッファーのサイズ (バイト単位) を指定する変数へのポインターです。関数が戻ると、pcbFormat パラメーターが指す変数には、バッファーに格納されたバイト数が格納されます。このパラメーターは、pbFormat が NULL の場合に限り NULL にできます。 注 バッファーで返されたデータを処理する際、アプリケーションは実際に返されたデータのサイズを使用する必要があります。実際のサイズは、入力時に指定されたバッファーのサイズよりわずかに小さい場合があります。(入力時には、想定される最大の出力データが収まるように、バッファーサイズを十分大きく指定するのが通例です。) 出力時には、このパラメーターが指す変数が、バッファーにコピーされたデータの実際のサイズを反映するように更新されます。
|
戻り値の型: BOOL
公式ドキュメント
CryptFormatObject 関数は、エンコードされたデータを書式化し、証明書のエンコード種別に従って、割り当てられたバッファーに Unicode 文字列を返します。
戻り値
関数が成功した場合、戻り値は TRUE です。成功しなかった場合、戻り値は FALSE です。拡張エラー情報を取得するには、GetLastError 関数を使用してください。
解説(Remarks)
この関数の既定の動作は、エンコードされたデータを 1 行で表示すること、すなわち各サブフィールドを 1 行上でコンマ (,) で連結して返すことです。データを複数行で表示したい場合は、CRYPT_FORMAT_STR_MULTI_LINE フラグを設定してください。これにより、各サブフィールドが別々の行に表示されます。
lpszStructType パラメーターに対して書式化ルーチンがインストールまたは登録されていない場合、エンコードされた CRYPT_INTEGER_BLOB の 16 進ダンプが返されます。CRYPT_FORMAT_STR_NO_HEX フラグを設定すると、16 進ダンプを無効にできます。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptFormatObject(
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
DWORD dwFormatType,
DWORD dwFormatStrType,
void* pFormatStruct, // optional
LPCSTR lpszStructType, // optional
const BYTE* pbEncoded,
DWORD cbEncoded,
void* pbFormat, // optional
DWORD* pcbFormat
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptFormatObject(
uint dwCertEncodingType, // CERT_QUERY_ENCODING_TYPE
uint dwFormatType, // DWORD
uint dwFormatStrType, // DWORD
IntPtr pFormatStruct, // void* optional
[MarshalAs(UnmanagedType.LPStr)] string lpszStructType, // LPCSTR optional
IntPtr pbEncoded, // BYTE*
uint cbEncoded, // DWORD
IntPtr pbFormat, // void* optional, out
ref uint pcbFormat // DWORD* in/out
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptFormatObject(
dwCertEncodingType As UInteger, ' CERT_QUERY_ENCODING_TYPE
dwFormatType As UInteger, ' DWORD
dwFormatStrType As UInteger, ' DWORD
pFormatStruct As IntPtr, ' void* optional
<MarshalAs(UnmanagedType.LPStr)> lpszStructType As String, ' LPCSTR optional
pbEncoded As IntPtr, ' BYTE*
cbEncoded As UInteger, ' DWORD
pbFormat As IntPtr, ' void* optional, out
ByRef pcbFormat As UInteger ' DWORD* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
' dwFormatType : DWORD
' dwFormatStrType : DWORD
' pFormatStruct : void* optional
' lpszStructType : LPCSTR optional
' pbEncoded : BYTE*
' cbEncoded : DWORD
' pbFormat : void* optional, out
' pcbFormat : DWORD* in/out
Declare PtrSafe Function CryptFormatObject Lib "crypt32" ( _
ByVal dwCertEncodingType As Long, _
ByVal dwFormatType As Long, _
ByVal dwFormatStrType As Long, _
ByVal pFormatStruct As LongPtr, _
ByVal lpszStructType As String, _
ByVal pbEncoded As LongPtr, _
ByVal cbEncoded As Long, _
ByVal pbFormat As LongPtr, _
ByRef pcbFormat As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptFormatObject = ctypes.windll.crypt32.CryptFormatObject
CryptFormatObject.restype = wintypes.BOOL
CryptFormatObject.argtypes = [
wintypes.DWORD, # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
wintypes.DWORD, # dwFormatType : DWORD
wintypes.DWORD, # dwFormatStrType : DWORD
ctypes.POINTER(None), # pFormatStruct : void* optional
wintypes.LPCSTR, # lpszStructType : LPCSTR optional
ctypes.POINTER(ctypes.c_ubyte), # pbEncoded : BYTE*
wintypes.DWORD, # cbEncoded : DWORD
ctypes.POINTER(None), # pbFormat : void* optional, out
ctypes.POINTER(wintypes.DWORD), # pcbFormat : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptFormatObject = Fiddle::Function.new(
lib['CryptFormatObject'],
[
-Fiddle::TYPE_INT, # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
-Fiddle::TYPE_INT, # dwFormatType : DWORD
-Fiddle::TYPE_INT, # dwFormatStrType : DWORD
Fiddle::TYPE_VOIDP, # pFormatStruct : void* optional
Fiddle::TYPE_VOIDP, # lpszStructType : LPCSTR optional
Fiddle::TYPE_VOIDP, # pbEncoded : BYTE*
-Fiddle::TYPE_INT, # cbEncoded : DWORD
Fiddle::TYPE_VOIDP, # pbFormat : void* optional, out
Fiddle::TYPE_VOIDP, # pcbFormat : DWORD* in/out
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptFormatObject(
dwCertEncodingType: u32, // CERT_QUERY_ENCODING_TYPE
dwFormatType: u32, // DWORD
dwFormatStrType: u32, // DWORD
pFormatStruct: *mut (), // void* optional
lpszStructType: *const u8, // LPCSTR optional
pbEncoded: *const u8, // BYTE*
cbEncoded: u32, // DWORD
pbFormat: *mut (), // void* optional, out
pcbFormat: *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 CryptFormatObject(uint dwCertEncodingType, uint dwFormatType, uint dwFormatStrType, IntPtr pFormatStruct, [MarshalAs(UnmanagedType.LPStr)] string lpszStructType, IntPtr pbEncoded, uint cbEncoded, IntPtr pbFormat, ref uint pcbFormat);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptFormatObject' -Namespace Win32 -PassThru
# $api::CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat)#uselib "CRYPT32.dll"
#func global CryptFormatObject "CryptFormatObject" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CryptFormatObject dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, varptr(pbEncoded), cbEncoded, pbFormat, varptr(pcbFormat) ; 戻り値は stat
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "sptr"
; dwFormatType : DWORD -> "sptr"
; dwFormatStrType : DWORD -> "sptr"
; pFormatStruct : void* optional -> "sptr"
; lpszStructType : LPCSTR optional -> "sptr"
; pbEncoded : BYTE* -> "sptr"
; cbEncoded : DWORD -> "sptr"
; pbFormat : void* optional, out -> "sptr"
; pcbFormat : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CRYPT32.dll" #cfunc global CryptFormatObject "CryptFormatObject" int, int, int, sptr, str, var, int, sptr, var ; res = CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; dwFormatType : DWORD -> "int" ; dwFormatStrType : DWORD -> "int" ; pFormatStruct : void* optional -> "sptr" ; lpszStructType : LPCSTR optional -> "str" ; pbEncoded : BYTE* -> "var" ; cbEncoded : DWORD -> "int" ; pbFormat : void* optional, out -> "sptr" ; pcbFormat : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CryptFormatObject "CryptFormatObject" int, int, int, sptr, str, sptr, int, sptr, sptr ; res = CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, varptr(pbEncoded), cbEncoded, pbFormat, varptr(pcbFormat)) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; dwFormatType : DWORD -> "int" ; dwFormatStrType : DWORD -> "int" ; pFormatStruct : void* optional -> "sptr" ; lpszStructType : LPCSTR optional -> "str" ; pbEncoded : BYTE* -> "sptr" ; cbEncoded : DWORD -> "int" ; pbFormat : void* optional, out -> "sptr" ; pcbFormat : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL CryptFormatObject(CERT_QUERY_ENCODING_TYPE dwCertEncodingType, DWORD dwFormatType, DWORD dwFormatStrType, void* pFormatStruct, LPCSTR lpszStructType, BYTE* pbEncoded, DWORD cbEncoded, void* pbFormat, DWORD* pcbFormat) #uselib "CRYPT32.dll" #cfunc global CryptFormatObject "CryptFormatObject" int, int, int, intptr, str, var, int, intptr, var ; res = CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; dwFormatType : DWORD -> "int" ; dwFormatStrType : DWORD -> "int" ; pFormatStruct : void* optional -> "intptr" ; lpszStructType : LPCSTR optional -> "str" ; pbEncoded : BYTE* -> "var" ; cbEncoded : DWORD -> "int" ; pbFormat : void* optional, out -> "intptr" ; pcbFormat : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CryptFormatObject(CERT_QUERY_ENCODING_TYPE dwCertEncodingType, DWORD dwFormatType, DWORD dwFormatStrType, void* pFormatStruct, LPCSTR lpszStructType, BYTE* pbEncoded, DWORD cbEncoded, void* pbFormat, DWORD* pcbFormat) #uselib "CRYPT32.dll" #cfunc global CryptFormatObject "CryptFormatObject" int, int, int, intptr, str, intptr, int, intptr, intptr ; res = CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, varptr(pbEncoded), cbEncoded, pbFormat, varptr(pcbFormat)) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; dwFormatType : DWORD -> "int" ; dwFormatStrType : DWORD -> "int" ; pFormatStruct : void* optional -> "intptr" ; lpszStructType : LPCSTR optional -> "str" ; pbEncoded : BYTE* -> "intptr" ; cbEncoded : DWORD -> "int" ; pbFormat : void* optional, out -> "intptr" ; pcbFormat : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptFormatObject = crypt32.NewProc("CryptFormatObject")
)
// dwCertEncodingType (CERT_QUERY_ENCODING_TYPE), dwFormatType (DWORD), dwFormatStrType (DWORD), pFormatStruct (void* optional), lpszStructType (LPCSTR optional), pbEncoded (BYTE*), cbEncoded (DWORD), pbFormat (void* optional, out), pcbFormat (DWORD* in/out)
r1, _, err := procCryptFormatObject.Call(
uintptr(dwCertEncodingType),
uintptr(dwFormatType),
uintptr(dwFormatStrType),
uintptr(pFormatStruct),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszStructType))),
uintptr(pbEncoded),
uintptr(cbEncoded),
uintptr(pbFormat),
uintptr(pcbFormat),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptFormatObject(
dwCertEncodingType: DWORD; // CERT_QUERY_ENCODING_TYPE
dwFormatType: DWORD; // DWORD
dwFormatStrType: DWORD; // DWORD
pFormatStruct: Pointer; // void* optional
lpszStructType: PAnsiChar; // LPCSTR optional
pbEncoded: Pointer; // BYTE*
cbEncoded: DWORD; // DWORD
pbFormat: Pointer; // void* optional, out
pcbFormat: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptFormatObject';result := DllCall("CRYPT32\CryptFormatObject"
, "UInt", dwCertEncodingType ; CERT_QUERY_ENCODING_TYPE
, "UInt", dwFormatType ; DWORD
, "UInt", dwFormatStrType ; DWORD
, "Ptr", pFormatStruct ; void* optional
, "AStr", lpszStructType ; LPCSTR optional
, "Ptr", pbEncoded ; BYTE*
, "UInt", cbEncoded ; DWORD
, "Ptr", pbFormat ; void* optional, out
, "Ptr", pcbFormat ; DWORD* in/out
, "Int") ; return: BOOL●CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat) = DLL("CRYPT32.dll", "bool CryptFormatObject(dword, dword, dword, void*, char*, void*, dword, void*, void*)")
# 呼び出し: CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat)
# dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "dword"
# dwFormatType : DWORD -> "dword"
# dwFormatStrType : DWORD -> "dword"
# pFormatStruct : void* optional -> "void*"
# lpszStructType : LPCSTR optional -> "char*"
# pbEncoded : BYTE* -> "void*"
# cbEncoded : DWORD -> "dword"
# pbFormat : void* optional, out -> "void*"
# pcbFormat : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CryptFormatObject(
dwCertEncodingType: u32, // CERT_QUERY_ENCODING_TYPE
dwFormatType: u32, // DWORD
dwFormatStrType: u32, // DWORD
pFormatStruct: ?*anyopaque, // void* optional
lpszStructType: [*c]const u8, // LPCSTR optional
pbEncoded: [*c]u8, // BYTE*
cbEncoded: u32, // DWORD
pbFormat: ?*anyopaque, // void* optional, out
pcbFormat: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;proc CryptFormatObject(
dwCertEncodingType: uint32, # CERT_QUERY_ENCODING_TYPE
dwFormatType: uint32, # DWORD
dwFormatStrType: uint32, # DWORD
pFormatStruct: pointer, # void* optional
lpszStructType: cstring, # LPCSTR optional
pbEncoded: ptr uint8, # BYTE*
cbEncoded: uint32, # DWORD
pbFormat: pointer, # void* optional, out
pcbFormat: ptr uint32 # DWORD* in/out
): int32 {.importc: "CryptFormatObject", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
int CryptFormatObject(
uint dwCertEncodingType, // CERT_QUERY_ENCODING_TYPE
uint dwFormatType, // DWORD
uint dwFormatStrType, // DWORD
void* pFormatStruct, // void* optional
const(char)* lpszStructType, // LPCSTR optional
ubyte* pbEncoded, // BYTE*
uint cbEncoded, // DWORD
void* pbFormat, // void* optional, out
uint* pcbFormat // DWORD* in/out
);ccall((:CryptFormatObject, "CRYPT32.dll"), stdcall, Int32,
(UInt32, UInt32, UInt32, Ptr{Cvoid}, Cstring, Ptr{UInt8}, UInt32, Ptr{Cvoid}, Ptr{UInt32}),
dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat)
# dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> UInt32
# dwFormatType : DWORD -> UInt32
# dwFormatStrType : DWORD -> UInt32
# pFormatStruct : void* optional -> Ptr{Cvoid}
# lpszStructType : LPCSTR optional -> Cstring
# pbEncoded : BYTE* -> Ptr{UInt8}
# cbEncoded : DWORD -> UInt32
# pbFormat : void* optional, out -> Ptr{Cvoid}
# pcbFormat : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CryptFormatObject(
uint32_t dwCertEncodingType,
uint32_t dwFormatType,
uint32_t dwFormatStrType,
void* pFormatStruct,
const char* lpszStructType,
uint8_t* pbEncoded,
uint32_t cbEncoded,
void* pbFormat,
uint32_t* pcbFormat);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat)
-- dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
-- dwFormatType : DWORD
-- dwFormatStrType : DWORD
-- pFormatStruct : void* optional
-- lpszStructType : LPCSTR optional
-- pbEncoded : BYTE*
-- cbEncoded : DWORD
-- pbFormat : void* optional, out
-- pcbFormat : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptFormatObject = lib.func('__stdcall', 'CryptFormatObject', 'int32_t', ['uint32_t', 'uint32_t', 'uint32_t', 'void *', 'str', 'uint8_t *', 'uint32_t', 'void *', 'uint32_t *']);
// CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat)
// dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> 'uint32_t'
// dwFormatType : DWORD -> 'uint32_t'
// dwFormatStrType : DWORD -> 'uint32_t'
// pFormatStruct : void* optional -> 'void *'
// lpszStructType : LPCSTR optional -> 'str'
// pbEncoded : BYTE* -> 'uint8_t *'
// cbEncoded : DWORD -> 'uint32_t'
// pbFormat : void* optional, out -> 'void *'
// pcbFormat : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPT32.dll", {
CryptFormatObject: { parameters: ["u32", "u32", "u32", "pointer", "buffer", "pointer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat)
// dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "u32"
// dwFormatType : DWORD -> "u32"
// dwFormatStrType : DWORD -> "u32"
// pFormatStruct : void* optional -> "pointer"
// lpszStructType : LPCSTR optional -> "buffer"
// pbEncoded : BYTE* -> "pointer"
// cbEncoded : DWORD -> "u32"
// pbFormat : void* optional, out -> "pointer"
// pcbFormat : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CryptFormatObject(
uint32_t dwCertEncodingType,
uint32_t dwFormatType,
uint32_t dwFormatStrType,
void* pFormatStruct,
const char* lpszStructType,
uint8_t* pbEncoded,
uint32_t cbEncoded,
void* pbFormat,
uint32_t* pcbFormat);
C, "CRYPT32.dll");
// $ffi->CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat);
// dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
// dwFormatType : DWORD
// dwFormatStrType : DWORD
// pFormatStruct : void* optional
// lpszStructType : LPCSTR optional
// pbEncoded : BYTE*
// cbEncoded : DWORD
// pbFormat : void* optional, out
// pcbFormat : DWORD* in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Crypt32 extends StdCallLibrary {
Crypt32 INSTANCE = Native.load("crypt32", Crypt32.class);
boolean CryptFormatObject(
int dwCertEncodingType, // CERT_QUERY_ENCODING_TYPE
int dwFormatType, // DWORD
int dwFormatStrType, // DWORD
Pointer pFormatStruct, // void* optional
String lpszStructType, // LPCSTR optional
byte[] pbEncoded, // BYTE*
int cbEncoded, // DWORD
Pointer pbFormat, // void* optional, out
IntByReference pcbFormat // DWORD* in/out
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CryptFormatObject = CryptFormatObject(
dwCertEncodingType : UInt32, # CERT_QUERY_ENCODING_TYPE
dwFormatType : UInt32, # DWORD
dwFormatStrType : UInt32, # DWORD
pFormatStruct : Void*, # void* optional
lpszStructType : UInt8*, # LPCSTR optional
pbEncoded : UInt8*, # BYTE*
cbEncoded : UInt32, # DWORD
pbFormat : Void*, # void* optional, out
pcbFormat : UInt32* # DWORD* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CryptFormatObjectNative = Int32 Function(Uint32, Uint32, Uint32, Pointer<Void>, Pointer<Utf8>, Pointer<Uint8>, Uint32, Pointer<Void>, Pointer<Uint32>);
typedef CryptFormatObjectDart = int Function(int, int, int, Pointer<Void>, Pointer<Utf8>, Pointer<Uint8>, int, Pointer<Void>, Pointer<Uint32>);
final CryptFormatObject = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CryptFormatObjectNative, CryptFormatObjectDart>('CryptFormatObject');
// dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> Uint32
// dwFormatType : DWORD -> Uint32
// dwFormatStrType : DWORD -> Uint32
// pFormatStruct : void* optional -> Pointer<Void>
// lpszStructType : LPCSTR optional -> Pointer<Utf8>
// pbEncoded : BYTE* -> Pointer<Uint8>
// cbEncoded : DWORD -> Uint32
// pbFormat : void* optional, out -> Pointer<Void>
// pcbFormat : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptFormatObject(
dwCertEncodingType: DWORD; // CERT_QUERY_ENCODING_TYPE
dwFormatType: DWORD; // DWORD
dwFormatStrType: DWORD; // DWORD
pFormatStruct: Pointer; // void* optional
lpszStructType: PAnsiChar; // LPCSTR optional
pbEncoded: Pointer; // BYTE*
cbEncoded: DWORD; // DWORD
pbFormat: Pointer; // void* optional, out
pcbFormat: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptFormatObject';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptFormatObject"
c_CryptFormatObject :: Word32 -> Word32 -> Word32 -> Ptr () -> CString -> Ptr Word8 -> Word32 -> Ptr () -> Ptr Word32 -> IO CInt
-- dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> Word32
-- dwFormatType : DWORD -> Word32
-- dwFormatStrType : DWORD -> Word32
-- pFormatStruct : void* optional -> Ptr ()
-- lpszStructType : LPCSTR optional -> CString
-- pbEncoded : BYTE* -> Ptr Word8
-- cbEncoded : DWORD -> Word32
-- pbFormat : void* optional, out -> Ptr ()
-- pcbFormat : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cryptformatobject =
foreign "CryptFormatObject"
(uint32_t @-> uint32_t @-> uint32_t @-> (ptr void) @-> string @-> (ptr uint8_t) @-> uint32_t @-> (ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> uint32_t *)
(* dwFormatType : DWORD -> uint32_t *)
(* dwFormatStrType : DWORD -> uint32_t *)
(* pFormatStruct : void* optional -> (ptr void) *)
(* lpszStructType : LPCSTR optional -> string *)
(* pbEncoded : BYTE* -> (ptr uint8_t) *)
(* cbEncoded : DWORD -> uint32_t *)
(* pbFormat : void* optional, out -> (ptr void) *)
(* pcbFormat : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)
(cffi:defcfun ("CryptFormatObject" crypt-format-object :convention :stdcall) :int32
(dw-cert-encoding-type :uint32) ; CERT_QUERY_ENCODING_TYPE
(dw-format-type :uint32) ; DWORD
(dw-format-str-type :uint32) ; DWORD
(p-format-struct :pointer) ; void* optional
(lpsz-struct-type :string) ; LPCSTR optional
(pb-encoded :pointer) ; BYTE*
(cb-encoded :uint32) ; DWORD
(pb-format :pointer) ; void* optional, out
(pcb-format :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptFormatObject = Win32::API::More->new('CRYPT32',
'BOOL CryptFormatObject(DWORD dwCertEncodingType, DWORD dwFormatType, DWORD dwFormatStrType, LPVOID pFormatStruct, LPCSTR lpszStructType, LPVOID pbEncoded, DWORD cbEncoded, LPVOID pbFormat, LPVOID pcbFormat)');
# my $ret = $CryptFormatObject->Call($dwCertEncodingType, $dwFormatType, $dwFormatStrType, $pFormatStruct, $lpszStructType, $pbEncoded, $cbEncoded, $pbFormat, $pcbFormat);
# dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> DWORD
# dwFormatType : DWORD -> DWORD
# dwFormatStrType : DWORD -> DWORD
# pFormatStruct : void* optional -> LPVOID
# lpszStructType : LPCSTR optional -> LPCSTR
# pbEncoded : BYTE* -> LPVOID
# cbEncoded : DWORD -> DWORD
# pbFormat : void* optional, out -> LPVOID
# pcbFormat : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。