TdhFormatProperty
関数シグネチャ
// TDH.dll
#include <windows.h>
DWORD TdhFormatProperty(
TRACE_EVENT_INFO* EventInfo,
EVENT_MAP_INFO* MapInfo, // optional
DWORD PointerSize,
WORD PropertyInType,
WORD PropertyOutType,
WORD PropertyLength,
WORD UserDataLength,
BYTE* UserData,
DWORD* BufferSize,
LPWSTR Buffer, // optional
WORD* UserDataConsumed
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| EventInfo | TRACE_EVENT_INFO* | in | イベント情報を格納する TRACE_EVENT_INFO 構造体。この構造体を取得するには、TdhGetEventInformation 関数を呼び出します。 |
| MapInfo | EVENT_MAP_INFO* | inoptional | 整数値およびビット値を文字列に対応付ける EVENT_MAP_INFO 構造体。この構造体を取得するには、TdhGetEventMapInformation 関数を呼び出します。マップの名前を取得するには、EVENT_PROPERTY_INFO 構造体の MapNameOffset メンバーを使用します。対応付けされたプロパティに対してマップ情報を指定しない場合、関数は整数値またはビット値を書式設定します。 |
| PointerSize | DWORD | in | イベントデータ内のポインター値のサイズ。サイズを取得するには、EVENT_RECORD.EventHeader.Flags メンバーにアクセスします。EVENT_HEADER_FLAG_32_BIT_HEADER フラグが設定されている場合、ポインターサイズは 4 バイトです。それ以外で EVENT_HEADER_FLAG_64_BIT_HEADER フラグが設定されている場合は 8 バイトです。EVENT_RECORD 構造体 (evntcons.h) は [PEVENT_RECORD_CALLBACK コールバック関数] に渡されます。 |
| PropertyInType | WORD | in | プロパティの入力型。このパラメーターを設定するには、EVENT_PROPERTY_INFO 構造体の InType メンバーを使用します。 |
| PropertyOutType | WORD | in | プロパティの出力型。このパラメーターを設定するには、EVENT_PROPERTY_INFO 構造体の OutType メンバーを使用します。 |
| PropertyLength | WORD | in | プロパティの長さ (バイト単位)。このパラメーターを設定するには、EVENT_PROPERTY_INFO 構造体の Length メンバーを使用します。 |
| UserDataLength | WORD | in | UserData バッファーのサイズ (バイト単位)。「解説」を参照してください。 |
| UserData | BYTE* | in | イベントデータを格納するバッファー。「解説」を参照してください。 |
| BufferSize | DWORD* | inout | Buffer バッファーのサイズ (バイト単位)。関数が成功した場合、このパラメーターには使用されたバッファーのサイズが格納されます。バッファーが小さすぎる場合、関数は ERROR_INSUFFICIENT_BUFFER を返し、このパラメーターに必要なバッファーサイズを設定します。入力時にバッファーサイズが 0 の場合、バッファーにはデータが返されず、このパラメーターには必要なバッファーサイズが格納されます。 |
| Buffer | LPWSTR | outoptional | 書式設定されたプロパティ値を格納する、呼び出し元が割り当てたバッファー。必要なバッファーサイズを確認するには、このパラメーターを NULL に、BufferSize を 0 に設定します。 |
| UserDataConsumed | WORD* | out | 消費されたイベントデータの長さ (バイト単位)。この値を使用して UserData および UserDataLength パラメーターの値を調整します。「解説」を参照してください。 |
戻り値の型: DWORD
公式ドキュメント
プロパティ値を表示用に書式設定します。
戻り値
成功した場合は ERROR_SUCCESS を返します。それ以外の場合、この関数は次のいずれかの戻り値コード (その他のコードを含む) を返します。
| 戻り値コード | 説明 |
|---|---|
| ERROR_INSUFFICIENT_BUFFER | pBuffer バッファーのサイズが小さすぎます。pBufferSize に設定された必要なバッファーサイズを使用して、新しいバッファーを割り当ててください。 |
| ERROR_INVALID_PARAMETER | 1 つ以上のパラメーターが無効です。 |
| ERROR_EVT_INVALID_EVENT_DATA | イベントデータがマニフェスト内のイベント定義と一致しません。 |
解説(Remarks)
通常、この関数はループ内で呼び出します。ループを制御するには、TRACE_EVENT_INFO.TopLevelPropertyCount メンバーを使用します (TdhGetEventInformation 関数は TRACE_EVENT_INFO 構造体を返します)。ループに入る前に、UserData および UserDataLength パラメーターを、それぞれ EVENT_RECORD 構造体の UserData および UserDataLength メンバーの値に設定します。EVENT_RECORD 構造体 は [PEVENT_RECORD_CALLBACK コールバック関数] に渡されます。
プロパティが配列かどうかを判定します。EVENT_PROPERTY_INFO.Flags メンバーが PropertyParamCount に設定されているか、EVENT_PROPERTY_INFO.count メンバーが 1 より大きい場合、そのプロパティは配列です。配列内の要素数に基づいて、TdhFormatProperty 関数をループ内で呼び出します。
TdhFormatProperty 関数を呼び出した後、UserDataConsumed パラメーターの値を使用して、UserData および UserDataLength パラメーターの新しい値を設定します (UserDataLength から UserDataConsumed を減算し、UserDataLength を使用して UserData ポインターを進めます)。
プロパティが IPv6 アドレスの場合は、PropertyLength パラメーターを IN6_ADDR 構造体のサイズに設定する必要があります。次の条件をすべて満たす場合、プロパティは IPv6 アドレスと見なされます。
- EVENT_PROPERTY_INFO 構造体の InType メンバーが TDH_INTYPE_BINARY である
- EVENT_PROPERTY_INFO 構造体の OutType メンバーが TDH_OUTTYPE_IPV6 である
- EVENT_PROPERTY_INFO 構造体の Length メンバーが 0 である
例
この関数の呼び出し方法を示す例については、「TdhFormatProperty を使用したイベントデータの消費」を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// TDH.dll
#include <windows.h>
DWORD TdhFormatProperty(
TRACE_EVENT_INFO* EventInfo,
EVENT_MAP_INFO* MapInfo, // optional
DWORD PointerSize,
WORD PropertyInType,
WORD PropertyOutType,
WORD PropertyLength,
WORD UserDataLength,
BYTE* UserData,
DWORD* BufferSize,
LPWSTR Buffer, // optional
WORD* UserDataConsumed
);[DllImport("TDH.dll", ExactSpelling = true)]
static extern uint TdhFormatProperty(
IntPtr EventInfo, // TRACE_EVENT_INFO*
IntPtr MapInfo, // EVENT_MAP_INFO* optional
uint PointerSize, // DWORD
ushort PropertyInType, // WORD
ushort PropertyOutType, // WORD
ushort PropertyLength, // WORD
ushort UserDataLength, // WORD
IntPtr UserData, // BYTE*
ref uint BufferSize, // DWORD* in/out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder Buffer, // LPWSTR optional, out
out ushort UserDataConsumed // WORD* out
);<DllImport("TDH.dll", ExactSpelling:=True)>
Public Shared Function TdhFormatProperty(
EventInfo As IntPtr, ' TRACE_EVENT_INFO*
MapInfo As IntPtr, ' EVENT_MAP_INFO* optional
PointerSize As UInteger, ' DWORD
PropertyInType As UShort, ' WORD
PropertyOutType As UShort, ' WORD
PropertyLength As UShort, ' WORD
UserDataLength As UShort, ' WORD
UserData As IntPtr, ' BYTE*
ByRef BufferSize As UInteger, ' DWORD* in/out
<MarshalAs(UnmanagedType.LPWStr)> Buffer As System.Text.StringBuilder, ' LPWSTR optional, out
<Out> ByRef UserDataConsumed As UShort ' WORD* out
) As UInteger
End Function' EventInfo : TRACE_EVENT_INFO*
' MapInfo : EVENT_MAP_INFO* optional
' PointerSize : DWORD
' PropertyInType : WORD
' PropertyOutType : WORD
' PropertyLength : WORD
' UserDataLength : WORD
' UserData : BYTE*
' BufferSize : DWORD* in/out
' Buffer : LPWSTR optional, out
' UserDataConsumed : WORD* out
Declare PtrSafe Function TdhFormatProperty Lib "tdh" ( _
ByVal EventInfo As LongPtr, _
ByVal MapInfo As LongPtr, _
ByVal PointerSize As Long, _
ByVal PropertyInType As Integer, _
ByVal PropertyOutType As Integer, _
ByVal PropertyLength As Integer, _
ByVal UserDataLength As Integer, _
ByVal UserData As LongPtr, _
ByRef BufferSize As Long, _
ByVal Buffer As LongPtr, _
ByRef UserDataConsumed As Integer) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
TdhFormatProperty = ctypes.windll.tdh.TdhFormatProperty
TdhFormatProperty.restype = wintypes.DWORD
TdhFormatProperty.argtypes = [
ctypes.c_void_p, # EventInfo : TRACE_EVENT_INFO*
ctypes.c_void_p, # MapInfo : EVENT_MAP_INFO* optional
wintypes.DWORD, # PointerSize : DWORD
ctypes.c_ushort, # PropertyInType : WORD
ctypes.c_ushort, # PropertyOutType : WORD
ctypes.c_ushort, # PropertyLength : WORD
ctypes.c_ushort, # UserDataLength : WORD
ctypes.POINTER(ctypes.c_ubyte), # UserData : BYTE*
ctypes.POINTER(wintypes.DWORD), # BufferSize : DWORD* in/out
wintypes.LPWSTR, # Buffer : LPWSTR optional, out
ctypes.POINTER(ctypes.c_ushort), # UserDataConsumed : WORD* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('TDH.dll')
TdhFormatProperty = Fiddle::Function.new(
lib['TdhFormatProperty'],
[
Fiddle::TYPE_VOIDP, # EventInfo : TRACE_EVENT_INFO*
Fiddle::TYPE_VOIDP, # MapInfo : EVENT_MAP_INFO* optional
-Fiddle::TYPE_INT, # PointerSize : DWORD
-Fiddle::TYPE_SHORT, # PropertyInType : WORD
-Fiddle::TYPE_SHORT, # PropertyOutType : WORD
-Fiddle::TYPE_SHORT, # PropertyLength : WORD
-Fiddle::TYPE_SHORT, # UserDataLength : WORD
Fiddle::TYPE_VOIDP, # UserData : BYTE*
Fiddle::TYPE_VOIDP, # BufferSize : DWORD* in/out
Fiddle::TYPE_VOIDP, # Buffer : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # UserDataConsumed : WORD* out
],
-Fiddle::TYPE_INT)#[link(name = "tdh")]
extern "system" {
fn TdhFormatProperty(
EventInfo: *mut TRACE_EVENT_INFO, // TRACE_EVENT_INFO*
MapInfo: *mut EVENT_MAP_INFO, // EVENT_MAP_INFO* optional
PointerSize: u32, // DWORD
PropertyInType: u16, // WORD
PropertyOutType: u16, // WORD
PropertyLength: u16, // WORD
UserDataLength: u16, // WORD
UserData: *mut u8, // BYTE*
BufferSize: *mut u32, // DWORD* in/out
Buffer: *mut u16, // LPWSTR optional, out
UserDataConsumed: *mut u16 // WORD* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("TDH.dll")]
public static extern uint TdhFormatProperty(IntPtr EventInfo, IntPtr MapInfo, uint PointerSize, ushort PropertyInType, ushort PropertyOutType, ushort PropertyLength, ushort UserDataLength, IntPtr UserData, ref uint BufferSize, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder Buffer, out ushort UserDataConsumed);
"@
$api = Add-Type -MemberDefinition $sig -Name 'TDH_TdhFormatProperty' -Namespace Win32 -PassThru
# $api::TdhFormatProperty(EventInfo, MapInfo, PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, UserData, BufferSize, Buffer, UserDataConsumed)#uselib "TDH.dll"
#func global TdhFormatProperty "TdhFormatProperty" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; TdhFormatProperty varptr(EventInfo), varptr(MapInfo), PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, varptr(UserData), varptr(BufferSize), varptr(Buffer), varptr(UserDataConsumed) ; 戻り値は stat
; EventInfo : TRACE_EVENT_INFO* -> "sptr"
; MapInfo : EVENT_MAP_INFO* optional -> "sptr"
; PointerSize : DWORD -> "sptr"
; PropertyInType : WORD -> "sptr"
; PropertyOutType : WORD -> "sptr"
; PropertyLength : WORD -> "sptr"
; UserDataLength : WORD -> "sptr"
; UserData : BYTE* -> "sptr"
; BufferSize : DWORD* in/out -> "sptr"
; Buffer : LPWSTR optional, out -> "sptr"
; UserDataConsumed : WORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "TDH.dll" #cfunc global TdhFormatProperty "TdhFormatProperty" var, var, int, int, int, int, int, var, var, var, var ; res = TdhFormatProperty(EventInfo, MapInfo, PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, UserData, BufferSize, Buffer, UserDataConsumed) ; EventInfo : TRACE_EVENT_INFO* -> "var" ; MapInfo : EVENT_MAP_INFO* optional -> "var" ; PointerSize : DWORD -> "int" ; PropertyInType : WORD -> "int" ; PropertyOutType : WORD -> "int" ; PropertyLength : WORD -> "int" ; UserDataLength : WORD -> "int" ; UserData : BYTE* -> "var" ; BufferSize : DWORD* in/out -> "var" ; Buffer : LPWSTR optional, out -> "var" ; UserDataConsumed : WORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "TDH.dll" #cfunc global TdhFormatProperty "TdhFormatProperty" sptr, sptr, int, int, int, int, int, sptr, sptr, sptr, sptr ; res = TdhFormatProperty(varptr(EventInfo), varptr(MapInfo), PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, varptr(UserData), varptr(BufferSize), varptr(Buffer), varptr(UserDataConsumed)) ; EventInfo : TRACE_EVENT_INFO* -> "sptr" ; MapInfo : EVENT_MAP_INFO* optional -> "sptr" ; PointerSize : DWORD -> "int" ; PropertyInType : WORD -> "int" ; PropertyOutType : WORD -> "int" ; PropertyLength : WORD -> "int" ; UserDataLength : WORD -> "int" ; UserData : BYTE* -> "sptr" ; BufferSize : DWORD* in/out -> "sptr" ; Buffer : LPWSTR optional, out -> "sptr" ; UserDataConsumed : WORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD TdhFormatProperty(TRACE_EVENT_INFO* EventInfo, EVENT_MAP_INFO* MapInfo, DWORD PointerSize, WORD PropertyInType, WORD PropertyOutType, WORD PropertyLength, WORD UserDataLength, BYTE* UserData, DWORD* BufferSize, LPWSTR Buffer, WORD* UserDataConsumed) #uselib "TDH.dll" #cfunc global TdhFormatProperty "TdhFormatProperty" var, var, int, int, int, int, int, var, var, var, var ; res = TdhFormatProperty(EventInfo, MapInfo, PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, UserData, BufferSize, Buffer, UserDataConsumed) ; EventInfo : TRACE_EVENT_INFO* -> "var" ; MapInfo : EVENT_MAP_INFO* optional -> "var" ; PointerSize : DWORD -> "int" ; PropertyInType : WORD -> "int" ; PropertyOutType : WORD -> "int" ; PropertyLength : WORD -> "int" ; UserDataLength : WORD -> "int" ; UserData : BYTE* -> "var" ; BufferSize : DWORD* in/out -> "var" ; Buffer : LPWSTR optional, out -> "var" ; UserDataConsumed : WORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD TdhFormatProperty(TRACE_EVENT_INFO* EventInfo, EVENT_MAP_INFO* MapInfo, DWORD PointerSize, WORD PropertyInType, WORD PropertyOutType, WORD PropertyLength, WORD UserDataLength, BYTE* UserData, DWORD* BufferSize, LPWSTR Buffer, WORD* UserDataConsumed) #uselib "TDH.dll" #cfunc global TdhFormatProperty "TdhFormatProperty" intptr, intptr, int, int, int, int, int, intptr, intptr, intptr, intptr ; res = TdhFormatProperty(varptr(EventInfo), varptr(MapInfo), PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, varptr(UserData), varptr(BufferSize), varptr(Buffer), varptr(UserDataConsumed)) ; EventInfo : TRACE_EVENT_INFO* -> "intptr" ; MapInfo : EVENT_MAP_INFO* optional -> "intptr" ; PointerSize : DWORD -> "int" ; PropertyInType : WORD -> "int" ; PropertyOutType : WORD -> "int" ; PropertyLength : WORD -> "int" ; UserDataLength : WORD -> "int" ; UserData : BYTE* -> "intptr" ; BufferSize : DWORD* in/out -> "intptr" ; Buffer : LPWSTR optional, out -> "intptr" ; UserDataConsumed : WORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
tdh = windows.NewLazySystemDLL("TDH.dll")
procTdhFormatProperty = tdh.NewProc("TdhFormatProperty")
)
// EventInfo (TRACE_EVENT_INFO*), MapInfo (EVENT_MAP_INFO* optional), PointerSize (DWORD), PropertyInType (WORD), PropertyOutType (WORD), PropertyLength (WORD), UserDataLength (WORD), UserData (BYTE*), BufferSize (DWORD* in/out), Buffer (LPWSTR optional, out), UserDataConsumed (WORD* out)
r1, _, err := procTdhFormatProperty.Call(
uintptr(EventInfo),
uintptr(MapInfo),
uintptr(PointerSize),
uintptr(PropertyInType),
uintptr(PropertyOutType),
uintptr(PropertyLength),
uintptr(UserDataLength),
uintptr(UserData),
uintptr(BufferSize),
uintptr(Buffer),
uintptr(UserDataConsumed),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction TdhFormatProperty(
EventInfo: Pointer; // TRACE_EVENT_INFO*
MapInfo: Pointer; // EVENT_MAP_INFO* optional
PointerSize: DWORD; // DWORD
PropertyInType: Word; // WORD
PropertyOutType: Word; // WORD
PropertyLength: Word; // WORD
UserDataLength: Word; // WORD
UserData: Pointer; // BYTE*
BufferSize: Pointer; // DWORD* in/out
Buffer: PWideChar; // LPWSTR optional, out
UserDataConsumed: Pointer // WORD* out
): DWORD; stdcall;
external 'TDH.dll' name 'TdhFormatProperty';result := DllCall("TDH\TdhFormatProperty"
, "Ptr", EventInfo ; TRACE_EVENT_INFO*
, "Ptr", MapInfo ; EVENT_MAP_INFO* optional
, "UInt", PointerSize ; DWORD
, "UShort", PropertyInType ; WORD
, "UShort", PropertyOutType ; WORD
, "UShort", PropertyLength ; WORD
, "UShort", UserDataLength ; WORD
, "Ptr", UserData ; BYTE*
, "Ptr", BufferSize ; DWORD* in/out
, "Ptr", Buffer ; LPWSTR optional, out
, "Ptr", UserDataConsumed ; WORD* out
, "UInt") ; return: DWORD●TdhFormatProperty(EventInfo, MapInfo, PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, UserData, BufferSize, Buffer, UserDataConsumed) = DLL("TDH.dll", "dword TdhFormatProperty(void*, void*, dword, int, int, int, int, void*, void*, char*, void*)")
# 呼び出し: TdhFormatProperty(EventInfo, MapInfo, PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, UserData, BufferSize, Buffer, UserDataConsumed)
# EventInfo : TRACE_EVENT_INFO* -> "void*"
# MapInfo : EVENT_MAP_INFO* optional -> "void*"
# PointerSize : DWORD -> "dword"
# PropertyInType : WORD -> "int"
# PropertyOutType : WORD -> "int"
# PropertyLength : WORD -> "int"
# UserDataLength : WORD -> "int"
# UserData : BYTE* -> "void*"
# BufferSize : DWORD* in/out -> "void*"
# Buffer : LPWSTR optional, out -> "char*"
# UserDataConsumed : WORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "tdh" fn TdhFormatProperty(
EventInfo: [*c]TRACE_EVENT_INFO, // TRACE_EVENT_INFO*
MapInfo: [*c]EVENT_MAP_INFO, // EVENT_MAP_INFO* optional
PointerSize: u32, // DWORD
PropertyInType: u16, // WORD
PropertyOutType: u16, // WORD
PropertyLength: u16, // WORD
UserDataLength: u16, // WORD
UserData: [*c]u8, // BYTE*
BufferSize: [*c]u32, // DWORD* in/out
Buffer: [*c]u16, // LPWSTR optional, out
UserDataConsumed: [*c]u16 // WORD* out
) callconv(std.os.windows.WINAPI) u32;proc TdhFormatProperty(
EventInfo: ptr TRACE_EVENT_INFO, # TRACE_EVENT_INFO*
MapInfo: ptr EVENT_MAP_INFO, # EVENT_MAP_INFO* optional
PointerSize: uint32, # DWORD
PropertyInType: uint16, # WORD
PropertyOutType: uint16, # WORD
PropertyLength: uint16, # WORD
UserDataLength: uint16, # WORD
UserData: ptr uint8, # BYTE*
BufferSize: ptr uint32, # DWORD* in/out
Buffer: ptr uint16, # LPWSTR optional, out
UserDataConsumed: ptr uint16 # WORD* out
): uint32 {.importc: "TdhFormatProperty", stdcall, dynlib: "TDH.dll".}pragma(lib, "tdh");
extern(Windows)
uint TdhFormatProperty(
TRACE_EVENT_INFO* EventInfo, // TRACE_EVENT_INFO*
EVENT_MAP_INFO* MapInfo, // EVENT_MAP_INFO* optional
uint PointerSize, // DWORD
ushort PropertyInType, // WORD
ushort PropertyOutType, // WORD
ushort PropertyLength, // WORD
ushort UserDataLength, // WORD
ubyte* UserData, // BYTE*
uint* BufferSize, // DWORD* in/out
wchar* Buffer, // LPWSTR optional, out
ushort* UserDataConsumed // WORD* out
);ccall((:TdhFormatProperty, "TDH.dll"), stdcall, UInt32,
(Ptr{TRACE_EVENT_INFO}, Ptr{EVENT_MAP_INFO}, UInt32, UInt16, UInt16, UInt16, UInt16, Ptr{UInt8}, Ptr{UInt32}, Ptr{UInt16}, Ptr{UInt16}),
EventInfo, MapInfo, PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, UserData, BufferSize, Buffer, UserDataConsumed)
# EventInfo : TRACE_EVENT_INFO* -> Ptr{TRACE_EVENT_INFO}
# MapInfo : EVENT_MAP_INFO* optional -> Ptr{EVENT_MAP_INFO}
# PointerSize : DWORD -> UInt32
# PropertyInType : WORD -> UInt16
# PropertyOutType : WORD -> UInt16
# PropertyLength : WORD -> UInt16
# UserDataLength : WORD -> UInt16
# UserData : BYTE* -> Ptr{UInt8}
# BufferSize : DWORD* in/out -> Ptr{UInt32}
# Buffer : LPWSTR optional, out -> Ptr{UInt16}
# UserDataConsumed : WORD* out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t TdhFormatProperty(
void* EventInfo,
void* MapInfo,
uint32_t PointerSize,
uint16_t PropertyInType,
uint16_t PropertyOutType,
uint16_t PropertyLength,
uint16_t UserDataLength,
uint8_t* UserData,
uint32_t* BufferSize,
uint16_t* Buffer,
uint16_t* UserDataConsumed);
]]
local tdh = ffi.load("tdh")
-- tdh.TdhFormatProperty(EventInfo, MapInfo, PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, UserData, BufferSize, Buffer, UserDataConsumed)
-- EventInfo : TRACE_EVENT_INFO*
-- MapInfo : EVENT_MAP_INFO* optional
-- PointerSize : DWORD
-- PropertyInType : WORD
-- PropertyOutType : WORD
-- PropertyLength : WORD
-- UserDataLength : WORD
-- UserData : BYTE*
-- BufferSize : DWORD* in/out
-- Buffer : LPWSTR optional, out
-- UserDataConsumed : WORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('TDH.dll');
const TdhFormatProperty = lib.func('__stdcall', 'TdhFormatProperty', 'uint32_t', ['void *', 'void *', 'uint32_t', 'uint16_t', 'uint16_t', 'uint16_t', 'uint16_t', 'uint8_t *', 'uint32_t *', 'uint16_t *', 'uint16_t *']);
// TdhFormatProperty(EventInfo, MapInfo, PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, UserData, BufferSize, Buffer, UserDataConsumed)
// EventInfo : TRACE_EVENT_INFO* -> 'void *'
// MapInfo : EVENT_MAP_INFO* optional -> 'void *'
// PointerSize : DWORD -> 'uint32_t'
// PropertyInType : WORD -> 'uint16_t'
// PropertyOutType : WORD -> 'uint16_t'
// PropertyLength : WORD -> 'uint16_t'
// UserDataLength : WORD -> 'uint16_t'
// UserData : BYTE* -> 'uint8_t *'
// BufferSize : DWORD* in/out -> 'uint32_t *'
// Buffer : LPWSTR optional, out -> 'uint16_t *'
// UserDataConsumed : WORD* out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("TDH.dll", {
TdhFormatProperty: { parameters: ["pointer", "pointer", "u32", "u16", "u16", "u16", "u16", "pointer", "pointer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.TdhFormatProperty(EventInfo, MapInfo, PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, UserData, BufferSize, Buffer, UserDataConsumed)
// EventInfo : TRACE_EVENT_INFO* -> "pointer"
// MapInfo : EVENT_MAP_INFO* optional -> "pointer"
// PointerSize : DWORD -> "u32"
// PropertyInType : WORD -> "u16"
// PropertyOutType : WORD -> "u16"
// PropertyLength : WORD -> "u16"
// UserDataLength : WORD -> "u16"
// UserData : BYTE* -> "pointer"
// BufferSize : DWORD* in/out -> "pointer"
// Buffer : LPWSTR optional, out -> "buffer"
// UserDataConsumed : WORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t TdhFormatProperty(
void* EventInfo,
void* MapInfo,
uint32_t PointerSize,
uint16_t PropertyInType,
uint16_t PropertyOutType,
uint16_t PropertyLength,
uint16_t UserDataLength,
uint8_t* UserData,
uint32_t* BufferSize,
uint16_t* Buffer,
uint16_t* UserDataConsumed);
C, "TDH.dll");
// $ffi->TdhFormatProperty(EventInfo, MapInfo, PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, UserData, BufferSize, Buffer, UserDataConsumed);
// EventInfo : TRACE_EVENT_INFO*
// MapInfo : EVENT_MAP_INFO* optional
// PointerSize : DWORD
// PropertyInType : WORD
// PropertyOutType : WORD
// PropertyLength : WORD
// UserDataLength : WORD
// UserData : BYTE*
// BufferSize : DWORD* in/out
// Buffer : LPWSTR optional, out
// UserDataConsumed : WORD* 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 Tdh extends StdCallLibrary {
Tdh INSTANCE = Native.load("tdh", Tdh.class);
int TdhFormatProperty(
Pointer EventInfo, // TRACE_EVENT_INFO*
Pointer MapInfo, // EVENT_MAP_INFO* optional
int PointerSize, // DWORD
short PropertyInType, // WORD
short PropertyOutType, // WORD
short PropertyLength, // WORD
short UserDataLength, // WORD
byte[] UserData, // BYTE*
IntByReference BufferSize, // DWORD* in/out
char[] Buffer, // LPWSTR optional, out
ShortByReference UserDataConsumed // WORD* out
);
}@[Link("tdh")]
lib LibTDH
fun TdhFormatProperty = TdhFormatProperty(
EventInfo : TRACE_EVENT_INFO*, # TRACE_EVENT_INFO*
MapInfo : EVENT_MAP_INFO*, # EVENT_MAP_INFO* optional
PointerSize : UInt32, # DWORD
PropertyInType : UInt16, # WORD
PropertyOutType : UInt16, # WORD
PropertyLength : UInt16, # WORD
UserDataLength : UInt16, # WORD
UserData : UInt8*, # BYTE*
BufferSize : UInt32*, # DWORD* in/out
Buffer : UInt16*, # LPWSTR optional, out
UserDataConsumed : UInt16* # WORD* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef TdhFormatPropertyNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Uint32, Uint16, Uint16, Uint16, Uint16, Pointer<Uint8>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint16>);
typedef TdhFormatPropertyDart = int Function(Pointer<Void>, Pointer<Void>, int, int, int, int, int, Pointer<Uint8>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint16>);
final TdhFormatProperty = DynamicLibrary.open('TDH.dll')
.lookupFunction<TdhFormatPropertyNative, TdhFormatPropertyDart>('TdhFormatProperty');
// EventInfo : TRACE_EVENT_INFO* -> Pointer<Void>
// MapInfo : EVENT_MAP_INFO* optional -> Pointer<Void>
// PointerSize : DWORD -> Uint32
// PropertyInType : WORD -> Uint16
// PropertyOutType : WORD -> Uint16
// PropertyLength : WORD -> Uint16
// UserDataLength : WORD -> Uint16
// UserData : BYTE* -> Pointer<Uint8>
// BufferSize : DWORD* in/out -> Pointer<Uint32>
// Buffer : LPWSTR optional, out -> Pointer<Utf16>
// UserDataConsumed : WORD* out -> Pointer<Uint16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function TdhFormatProperty(
EventInfo: Pointer; // TRACE_EVENT_INFO*
MapInfo: Pointer; // EVENT_MAP_INFO* optional
PointerSize: DWORD; // DWORD
PropertyInType: Word; // WORD
PropertyOutType: Word; // WORD
PropertyLength: Word; // WORD
UserDataLength: Word; // WORD
UserData: Pointer; // BYTE*
BufferSize: Pointer; // DWORD* in/out
Buffer: PWideChar; // LPWSTR optional, out
UserDataConsumed: Pointer // WORD* out
): DWORD; stdcall;
external 'TDH.dll' name 'TdhFormatProperty';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "TdhFormatProperty"
c_TdhFormatProperty :: Ptr () -> Ptr () -> Word32 -> Word16 -> Word16 -> Word16 -> Word16 -> Ptr Word8 -> Ptr Word32 -> CWString -> Ptr Word16 -> IO Word32
-- EventInfo : TRACE_EVENT_INFO* -> Ptr ()
-- MapInfo : EVENT_MAP_INFO* optional -> Ptr ()
-- PointerSize : DWORD -> Word32
-- PropertyInType : WORD -> Word16
-- PropertyOutType : WORD -> Word16
-- PropertyLength : WORD -> Word16
-- UserDataLength : WORD -> Word16
-- UserData : BYTE* -> Ptr Word8
-- BufferSize : DWORD* in/out -> Ptr Word32
-- Buffer : LPWSTR optional, out -> CWString
-- UserDataConsumed : WORD* out -> Ptr Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let tdhformatproperty =
foreign "TdhFormatProperty"
((ptr void) @-> (ptr void) @-> uint32_t @-> uint16_t @-> uint16_t @-> uint16_t @-> uint16_t @-> (ptr uint8_t) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* EventInfo : TRACE_EVENT_INFO* -> (ptr void) *)
(* MapInfo : EVENT_MAP_INFO* optional -> (ptr void) *)
(* PointerSize : DWORD -> uint32_t *)
(* PropertyInType : WORD -> uint16_t *)
(* PropertyOutType : WORD -> uint16_t *)
(* PropertyLength : WORD -> uint16_t *)
(* UserDataLength : WORD -> uint16_t *)
(* UserData : BYTE* -> (ptr uint8_t) *)
(* BufferSize : DWORD* in/out -> (ptr uint32_t) *)
(* Buffer : LPWSTR optional, out -> (ptr uint16_t) *)
(* UserDataConsumed : WORD* out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library tdh (t "TDH.dll"))
(cffi:use-foreign-library tdh)
(cffi:defcfun ("TdhFormatProperty" tdh-format-property :convention :stdcall) :uint32
(event-info :pointer) ; TRACE_EVENT_INFO*
(map-info :pointer) ; EVENT_MAP_INFO* optional
(pointer-size :uint32) ; DWORD
(property-in-type :uint16) ; WORD
(property-out-type :uint16) ; WORD
(property-length :uint16) ; WORD
(user-data-length :uint16) ; WORD
(user-data :pointer) ; BYTE*
(buffer-size :pointer) ; DWORD* in/out
(buffer :pointer) ; LPWSTR optional, out
(user-data-consumed :pointer)) ; WORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $TdhFormatProperty = Win32::API::More->new('TDH',
'DWORD TdhFormatProperty(LPVOID EventInfo, LPVOID MapInfo, DWORD PointerSize, WORD PropertyInType, WORD PropertyOutType, WORD PropertyLength, WORD UserDataLength, LPVOID UserData, LPVOID BufferSize, LPWSTR Buffer, LPVOID UserDataConsumed)');
# my $ret = $TdhFormatProperty->Call($EventInfo, $MapInfo, $PointerSize, $PropertyInType, $PropertyOutType, $PropertyLength, $UserDataLength, $UserData, $BufferSize, $Buffer, $UserDataConsumed);
# EventInfo : TRACE_EVENT_INFO* -> LPVOID
# MapInfo : EVENT_MAP_INFO* optional -> LPVOID
# PointerSize : DWORD -> DWORD
# PropertyInType : WORD -> WORD
# PropertyOutType : WORD -> WORD
# PropertyLength : WORD -> WORD
# UserDataLength : WORD -> WORD
# UserData : BYTE* -> LPVOID
# BufferSize : DWORD* in/out -> LPVOID
# Buffer : LPWSTR optional, out -> LPWSTR
# UserDataConsumed : WORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。