RegisterTraceGuidsW
関数シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
DWORD RegisterTraceGuidsW(
WMIDPREQUEST RequestAddress,
void* RequestContext, // optional
const GUID* ControlGuid,
DWORD GuidCount,
TRACE_GUID_REGISTRATION* TraceGuidReg, // optional
LPCWSTR MofImagePath, // optional
LPCWSTR MofResourceName, // optional
ULONGLONG* RegistrationHandle
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| RequestAddress | WMIDPREQUEST | in | イベント トレース セッションによってプロバイダーが有効または無効にされたときに通知を受け取る ControlCallback 関数への ポインター。 EnableTrace 関数が このコールバックをトリガーします。 |
| RequestContext | void* | inoptional | RequestAddress で指定した関数に ETW が渡す、省略可能なプロバイダー定義のコンテキストへの ポインター。 |
| ControlGuid | GUID* | in | 登録するプロバイダーのコントロール GUID (プロバイダー ID)。 |
| GuidCount | DWORD | in | TraceGuidReg 配列の要素数。TraceGuidReg が NULL の場合は、 このパラメーターに 0 を設定します。 |
| TraceGuidReg | TRACE_GUID_REGISTRATION* | inoptional | TRACE_GUID_REGISTRATION 各要素は、プロバイダーが提供するイベントのカテゴリを識別します。 入力時、各構造体の Guid メンバーには、登録するプロバイダーが割り当てたイベント トレース クラス GUID を格納します。クラス GUID は、プロバイダーが提供するイベントのカテゴリを 識別します。プロバイダーは、イベントをログに記録するために TraceEvent 関数を呼び出すときに、 同じクラス GUID を使用して EVENT_TRACE_HEADER の Guid メンバーを設定します。 出力時、RegHandle メンバーは、そのイベントのクラス GUID 登録に対するハンドルを 受け取ります。プロバイダーが TraceEventInstance 関数を呼び出す場合は、 TRACE_GUID_REGISTRATION の RegHandle メンバーを使用して、 EVENT_INSTANCE_HEADER の RegHandle メンバーを設定します。 プロバイダーがイベントをログに記録するために TraceEvent 関数のみを呼び出す場合、 このパラメーターは NULL にできます。プロバイダーがイベントをログに記録するために TraceEventInstance 関数を呼び出す場合、このパラメーターを NULL にすることはできません。 |
| MofImagePath | LPCWSTR | inoptional | このパラメーターはサポートされていません。NULL を設定してください。アプリケーションの セットアップ時に Mofcomp.exe を使用して MOF リソースを登録してください。詳細については、 イベント スキーマの公開 を参照してください。 Windows XP with SP1、Windows XP、および Windows 2000: MofResourceName で指定された リソースを含む DLL または実行可能プログラムのパスを指定する、省略可能な文字列への ポインター。イベント プロバイダーとコンシューマーが、プロバイダーの使用するイベント トレース クラスに関する情報を共有するために別の仕組みを使用する場合、このパラメーターは NULL に できます。 |
| MofResourceName | LPCWSTR | inoptional | このパラメーターはサポートされていません。NULL を設定してください。アプリケーションの セットアップ時に Mofcomp.exe を使用して MOF リソースを登録してください。詳細については、 イベント スキーマの公開 を参照してください。 Windows XP with SP1、Windows XP、および Windows 2000: MofImagePath の文字列リソースを 指定する、省略可能な文字列へのポインター。この文字列リソースには、プロバイダーがサポートする イベント トレース クラスを記述したバイナリ MOF ファイルの名前が含まれます。 |
| RegistrationHandle | ULONGLONG* | out | プロバイダーの登録ハンドルを受け取ります。返されたハンドルは、 UnregisterTraceGuids 関数を呼び出すときに使用します。 重要
DLL またはドライバーが作成したすべての登録ハンドルは、その DLL またはドライバーが アンロードされる前に登録解除する必要があります。プロバイダーが登録解除されていない場合、 ETW がプロバイダーのコールバックを呼び出そうとしたときにクラッシュが発生します。 |
戻り値の型: DWORD
公式ドキュメント
RegisterTraceGuidsW (Unicode) 関数 (evntrace.h) は今後使用しない関数であり、新しいコードでは代替として提供されている関数を使用してください。
戻り値
関数が成功した場合、戻り値は ERROR_SUCCESS です。
関数が失敗した場合、戻り値は システム エラー コード のいずれかです。 以下に、代表的なエラーとその原因を示します。
コントローラーがプロバイダーを有効にするために EnableTrace を呼び出した時点で プロバイダーがまだ RegisterTraceGuids を呼び出していない場合、この関数は ControlCallback が返した値を 返すこともあります。この場合、登録が成功していれば、RegisterTraceGuids は そのコールバックの戻り値を返します。
-
次のいずれかに該当します。
- RequestAddress が NULL である。
- ControlGuid が NULL である。
- RegistrationHandle が NULL である。
Windows XP および Windows 2000: TraceGuidReg が NULL であるか、GuidCount が 0 以下である。
解説(Remarks)
ほとんどの開発者は、この関数を直接呼び出すことはありません。通常、開発者は ETW フレームワークを使用します。たとえば、TMF ベースの WPP は、RegisterTraceGuids、 TraceMessage、および UnregisterTraceGuids の呼び出しを代わりに管理します。
この関数は、クラシック (Windows 2000 スタイル) の イベント プロバイダー ハンドルを開きます。このハンドルを使用すると、 TraceEvent、 TraceEventInstance、 TraceMessage、および TraceMessageVa を介して、 MOF ベースおよび TMF ベースの WPP ETW イベントを書き込めます。
EventWrite を介して マニフェスト ベースまたは TraceLogging ベースの ETW イベントを書き込む Windows Vista スタイル のプロバイダー ハンドルを開くには、 EventRegister を使用します。
プロバイダーの ControlGuid が既に登録されて有効になっている場合、同じ ControlGuid を 参照する以降の登録は自動的に有効になります。
1 つのプロセスは最大 1,024 個のプロバイダー GUID を登録できますが、プロセスが登録する プロバイダーの数は 1 つか 2 つに抑えてください。この上限には、この関数および EventRegister 関数を使用して 登録したものが含まれます。
Windows Vista より前: プロセスが登録できるプロバイダーの数に制限はありません。
例
RegisterTraceGuids を使用する例については、 クラシック イベントの書き込み を参照してください。
evntrace.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版と Unicode 版を自動的に選択するエイリアスとして RegisterTraceGuids を定義しています。 エンコード ニュートラルなエイリアスの使用と、エンコード ニュートラルでないコードを 混在させると、不一致によりコンパイル エラーまたは実行時エラーが発生する可能性が あります。詳細については、 関数プロトタイプの規則 を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
DWORD RegisterTraceGuidsW(
WMIDPREQUEST RequestAddress,
void* RequestContext, // optional
const GUID* ControlGuid,
DWORD GuidCount,
TRACE_GUID_REGISTRATION* TraceGuidReg, // optional
LPCWSTR MofImagePath, // optional
LPCWSTR MofResourceName, // optional
ULONGLONG* RegistrationHandle
);[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RegisterTraceGuidsW(
IntPtr RequestAddress, // WMIDPREQUEST
IntPtr RequestContext, // void* optional
ref Guid ControlGuid, // GUID*
uint GuidCount, // DWORD
IntPtr TraceGuidReg, // TRACE_GUID_REGISTRATION* optional
[MarshalAs(UnmanagedType.LPWStr)] string MofImagePath, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string MofResourceName, // LPCWSTR optional
out ulong RegistrationHandle // ULONGLONG* out
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegisterTraceGuidsW(
RequestAddress As IntPtr, ' WMIDPREQUEST
RequestContext As IntPtr, ' void* optional
ByRef ControlGuid As Guid, ' GUID*
GuidCount As UInteger, ' DWORD
TraceGuidReg As IntPtr, ' TRACE_GUID_REGISTRATION* optional
<MarshalAs(UnmanagedType.LPWStr)> MofImagePath As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> MofResourceName As String, ' LPCWSTR optional
<Out> ByRef RegistrationHandle As ULong ' ULONGLONG* out
) As UInteger
End Function' RequestAddress : WMIDPREQUEST
' RequestContext : void* optional
' ControlGuid : GUID*
' GuidCount : DWORD
' TraceGuidReg : TRACE_GUID_REGISTRATION* optional
' MofImagePath : LPCWSTR optional
' MofResourceName : LPCWSTR optional
' RegistrationHandle : ULONGLONG* out
Declare PtrSafe Function RegisterTraceGuidsW Lib "advapi32" ( _
ByVal RequestAddress As LongPtr, _
ByVal RequestContext As LongPtr, _
ByVal ControlGuid As LongPtr, _
ByVal GuidCount As Long, _
ByVal TraceGuidReg As LongPtr, _
ByVal MofImagePath As LongPtr, _
ByVal MofResourceName As LongPtr, _
ByRef RegistrationHandle As LongLong) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RegisterTraceGuidsW = ctypes.windll.advapi32.RegisterTraceGuidsW
RegisterTraceGuidsW.restype = wintypes.DWORD
RegisterTraceGuidsW.argtypes = [
ctypes.c_void_p, # RequestAddress : WMIDPREQUEST
ctypes.POINTER(None), # RequestContext : void* optional
ctypes.c_void_p, # ControlGuid : GUID*
wintypes.DWORD, # GuidCount : DWORD
ctypes.c_void_p, # TraceGuidReg : TRACE_GUID_REGISTRATION* optional
wintypes.LPCWSTR, # MofImagePath : LPCWSTR optional
wintypes.LPCWSTR, # MofResourceName : LPCWSTR optional
ctypes.POINTER(ctypes.c_ulonglong), # RegistrationHandle : ULONGLONG* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
RegisterTraceGuidsW = Fiddle::Function.new(
lib['RegisterTraceGuidsW'],
[
Fiddle::TYPE_VOIDP, # RequestAddress : WMIDPREQUEST
Fiddle::TYPE_VOIDP, # RequestContext : void* optional
Fiddle::TYPE_VOIDP, # ControlGuid : GUID*
-Fiddle::TYPE_INT, # GuidCount : DWORD
Fiddle::TYPE_VOIDP, # TraceGuidReg : TRACE_GUID_REGISTRATION* optional
Fiddle::TYPE_VOIDP, # MofImagePath : LPCWSTR optional
Fiddle::TYPE_VOIDP, # MofResourceName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # RegistrationHandle : ULONGLONG* out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advapi32")]
extern "system" {
fn RegisterTraceGuidsW(
RequestAddress: *const core::ffi::c_void, // WMIDPREQUEST
RequestContext: *mut (), // void* optional
ControlGuid: *const GUID, // GUID*
GuidCount: u32, // DWORD
TraceGuidReg: *mut TRACE_GUID_REGISTRATION, // TRACE_GUID_REGISTRATION* optional
MofImagePath: *const u16, // LPCWSTR optional
MofResourceName: *const u16, // LPCWSTR optional
RegistrationHandle: *mut u64 // ULONGLONG* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint RegisterTraceGuidsW(IntPtr RequestAddress, IntPtr RequestContext, ref Guid ControlGuid, uint GuidCount, IntPtr TraceGuidReg, [MarshalAs(UnmanagedType.LPWStr)] string MofImagePath, [MarshalAs(UnmanagedType.LPWStr)] string MofResourceName, out ulong RegistrationHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegisterTraceGuidsW' -Namespace Win32 -PassThru
# $api::RegisterTraceGuidsW(RequestAddress, RequestContext, ControlGuid, GuidCount, TraceGuidReg, MofImagePath, MofResourceName, RegistrationHandle)#uselib "ADVAPI32.dll"
#func global RegisterTraceGuidsW "RegisterTraceGuidsW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; RegisterTraceGuidsW RequestAddress, RequestContext, varptr(ControlGuid), GuidCount, varptr(TraceGuidReg), MofImagePath, MofResourceName, varptr(RegistrationHandle) ; 戻り値は stat
; RequestAddress : WMIDPREQUEST -> "wptr"
; RequestContext : void* optional -> "wptr"
; ControlGuid : GUID* -> "wptr"
; GuidCount : DWORD -> "wptr"
; TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> "wptr"
; MofImagePath : LPCWSTR optional -> "wptr"
; MofResourceName : LPCWSTR optional -> "wptr"
; RegistrationHandle : ULONGLONG* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll" #cfunc global RegisterTraceGuidsW "RegisterTraceGuidsW" sptr, sptr, var, int, var, wstr, wstr, var ; res = RegisterTraceGuidsW(RequestAddress, RequestContext, ControlGuid, GuidCount, TraceGuidReg, MofImagePath, MofResourceName, RegistrationHandle) ; RequestAddress : WMIDPREQUEST -> "sptr" ; RequestContext : void* optional -> "sptr" ; ControlGuid : GUID* -> "var" ; GuidCount : DWORD -> "int" ; TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> "var" ; MofImagePath : LPCWSTR optional -> "wstr" ; MofResourceName : LPCWSTR optional -> "wstr" ; RegistrationHandle : ULONGLONG* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global RegisterTraceGuidsW "RegisterTraceGuidsW" sptr, sptr, sptr, int, sptr, wstr, wstr, sptr ; res = RegisterTraceGuidsW(RequestAddress, RequestContext, varptr(ControlGuid), GuidCount, varptr(TraceGuidReg), MofImagePath, MofResourceName, varptr(RegistrationHandle)) ; RequestAddress : WMIDPREQUEST -> "sptr" ; RequestContext : void* optional -> "sptr" ; ControlGuid : GUID* -> "sptr" ; GuidCount : DWORD -> "int" ; TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> "sptr" ; MofImagePath : LPCWSTR optional -> "wstr" ; MofResourceName : LPCWSTR optional -> "wstr" ; RegistrationHandle : ULONGLONG* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD RegisterTraceGuidsW(WMIDPREQUEST RequestAddress, void* RequestContext, GUID* ControlGuid, DWORD GuidCount, TRACE_GUID_REGISTRATION* TraceGuidReg, LPCWSTR MofImagePath, LPCWSTR MofResourceName, ULONGLONG* RegistrationHandle) #uselib "ADVAPI32.dll" #cfunc global RegisterTraceGuidsW "RegisterTraceGuidsW" intptr, intptr, var, int, var, wstr, wstr, var ; res = RegisterTraceGuidsW(RequestAddress, RequestContext, ControlGuid, GuidCount, TraceGuidReg, MofImagePath, MofResourceName, RegistrationHandle) ; RequestAddress : WMIDPREQUEST -> "intptr" ; RequestContext : void* optional -> "intptr" ; ControlGuid : GUID* -> "var" ; GuidCount : DWORD -> "int" ; TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> "var" ; MofImagePath : LPCWSTR optional -> "wstr" ; MofResourceName : LPCWSTR optional -> "wstr" ; RegistrationHandle : ULONGLONG* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD RegisterTraceGuidsW(WMIDPREQUEST RequestAddress, void* RequestContext, GUID* ControlGuid, DWORD GuidCount, TRACE_GUID_REGISTRATION* TraceGuidReg, LPCWSTR MofImagePath, LPCWSTR MofResourceName, ULONGLONG* RegistrationHandle) #uselib "ADVAPI32.dll" #cfunc global RegisterTraceGuidsW "RegisterTraceGuidsW" intptr, intptr, intptr, int, intptr, wstr, wstr, intptr ; res = RegisterTraceGuidsW(RequestAddress, RequestContext, varptr(ControlGuid), GuidCount, varptr(TraceGuidReg), MofImagePath, MofResourceName, varptr(RegistrationHandle)) ; RequestAddress : WMIDPREQUEST -> "intptr" ; RequestContext : void* optional -> "intptr" ; ControlGuid : GUID* -> "intptr" ; GuidCount : DWORD -> "int" ; TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> "intptr" ; MofImagePath : LPCWSTR optional -> "wstr" ; MofResourceName : LPCWSTR optional -> "wstr" ; RegistrationHandle : ULONGLONG* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procRegisterTraceGuidsW = advapi32.NewProc("RegisterTraceGuidsW")
)
// RequestAddress (WMIDPREQUEST), RequestContext (void* optional), ControlGuid (GUID*), GuidCount (DWORD), TraceGuidReg (TRACE_GUID_REGISTRATION* optional), MofImagePath (LPCWSTR optional), MofResourceName (LPCWSTR optional), RegistrationHandle (ULONGLONG* out)
r1, _, err := procRegisterTraceGuidsW.Call(
uintptr(RequestAddress),
uintptr(RequestContext),
uintptr(ControlGuid),
uintptr(GuidCount),
uintptr(TraceGuidReg),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(MofImagePath))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(MofResourceName))),
uintptr(RegistrationHandle),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction RegisterTraceGuidsW(
RequestAddress: Pointer; // WMIDPREQUEST
RequestContext: Pointer; // void* optional
ControlGuid: PGUID; // GUID*
GuidCount: DWORD; // DWORD
TraceGuidReg: Pointer; // TRACE_GUID_REGISTRATION* optional
MofImagePath: PWideChar; // LPCWSTR optional
MofResourceName: PWideChar; // LPCWSTR optional
RegistrationHandle: Pointer // ULONGLONG* out
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'RegisterTraceGuidsW';result := DllCall("ADVAPI32\RegisterTraceGuidsW"
, "Ptr", RequestAddress ; WMIDPREQUEST
, "Ptr", RequestContext ; void* optional
, "Ptr", ControlGuid ; GUID*
, "UInt", GuidCount ; DWORD
, "Ptr", TraceGuidReg ; TRACE_GUID_REGISTRATION* optional
, "WStr", MofImagePath ; LPCWSTR optional
, "WStr", MofResourceName ; LPCWSTR optional
, "Ptr", RegistrationHandle ; ULONGLONG* out
, "UInt") ; return: DWORD●RegisterTraceGuidsW(RequestAddress, RequestContext, ControlGuid, GuidCount, TraceGuidReg, MofImagePath, MofResourceName, RegistrationHandle) = DLL("ADVAPI32.dll", "dword RegisterTraceGuidsW(void*, void*, void*, dword, void*, char*, char*, void*)")
# 呼び出し: RegisterTraceGuidsW(RequestAddress, RequestContext, ControlGuid, GuidCount, TraceGuidReg, MofImagePath, MofResourceName, RegistrationHandle)
# RequestAddress : WMIDPREQUEST -> "void*"
# RequestContext : void* optional -> "void*"
# ControlGuid : GUID* -> "void*"
# GuidCount : DWORD -> "dword"
# TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> "void*"
# MofImagePath : LPCWSTR optional -> "char*"
# MofResourceName : LPCWSTR optional -> "char*"
# RegistrationHandle : ULONGLONG* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "advapi32" fn RegisterTraceGuidsW(
RequestAddress: ?*anyopaque, // WMIDPREQUEST
RequestContext: ?*anyopaque, // void* optional
ControlGuid: [*c]GUID, // GUID*
GuidCount: u32, // DWORD
TraceGuidReg: [*c]TRACE_GUID_REGISTRATION, // TRACE_GUID_REGISTRATION* optional
MofImagePath: [*c]const u16, // LPCWSTR optional
MofResourceName: [*c]const u16, // LPCWSTR optional
RegistrationHandle: [*c]u64 // ULONGLONG* out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc RegisterTraceGuidsW(
RequestAddress: pointer, # WMIDPREQUEST
RequestContext: pointer, # void* optional
ControlGuid: ptr GUID, # GUID*
GuidCount: uint32, # DWORD
TraceGuidReg: ptr TRACE_GUID_REGISTRATION, # TRACE_GUID_REGISTRATION* optional
MofImagePath: WideCString, # LPCWSTR optional
MofResourceName: WideCString, # LPCWSTR optional
RegistrationHandle: ptr uint64 # ULONGLONG* out
): uint32 {.importc: "RegisterTraceGuidsW", stdcall, dynlib: "ADVAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "advapi32");
extern(Windows)
uint RegisterTraceGuidsW(
void* RequestAddress, // WMIDPREQUEST
void* RequestContext, // void* optional
GUID* ControlGuid, // GUID*
uint GuidCount, // DWORD
TRACE_GUID_REGISTRATION* TraceGuidReg, // TRACE_GUID_REGISTRATION* optional
const(wchar)* MofImagePath, // LPCWSTR optional
const(wchar)* MofResourceName, // LPCWSTR optional
ulong* RegistrationHandle // ULONGLONG* out
);ccall((:RegisterTraceGuidsW, "ADVAPI32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{GUID}, UInt32, Ptr{TRACE_GUID_REGISTRATION}, Cwstring, Cwstring, Ptr{UInt64}),
RequestAddress, RequestContext, ControlGuid, GuidCount, TraceGuidReg, MofImagePath, MofResourceName, RegistrationHandle)
# RequestAddress : WMIDPREQUEST -> Ptr{Cvoid}
# RequestContext : void* optional -> Ptr{Cvoid}
# ControlGuid : GUID* -> Ptr{GUID}
# GuidCount : DWORD -> UInt32
# TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> Ptr{TRACE_GUID_REGISTRATION}
# MofImagePath : LPCWSTR optional -> Cwstring
# MofResourceName : LPCWSTR optional -> Cwstring
# RegistrationHandle : ULONGLONG* out -> Ptr{UInt64}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t RegisterTraceGuidsW(
void* RequestAddress,
void* RequestContext,
void* ControlGuid,
uint32_t GuidCount,
void* TraceGuidReg,
const uint16_t* MofImagePath,
const uint16_t* MofResourceName,
uint64_t* RegistrationHandle);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.RegisterTraceGuidsW(RequestAddress, RequestContext, ControlGuid, GuidCount, TraceGuidReg, MofImagePath, MofResourceName, RegistrationHandle)
-- RequestAddress : WMIDPREQUEST
-- RequestContext : void* optional
-- ControlGuid : GUID*
-- GuidCount : DWORD
-- TraceGuidReg : TRACE_GUID_REGISTRATION* optional
-- MofImagePath : LPCWSTR optional
-- MofResourceName : LPCWSTR optional
-- RegistrationHandle : ULONGLONG* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const RegisterTraceGuidsW = lib.func('__stdcall', 'RegisterTraceGuidsW', 'uint32_t', ['void *', 'void *', 'void *', 'uint32_t', 'void *', 'str16', 'str16', 'uint64_t *']);
// RegisterTraceGuidsW(RequestAddress, RequestContext, ControlGuid, GuidCount, TraceGuidReg, MofImagePath, MofResourceName, RegistrationHandle)
// RequestAddress : WMIDPREQUEST -> 'void *'
// RequestContext : void* optional -> 'void *'
// ControlGuid : GUID* -> 'void *'
// GuidCount : DWORD -> 'uint32_t'
// TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> 'void *'
// MofImagePath : LPCWSTR optional -> 'str16'
// MofResourceName : LPCWSTR optional -> 'str16'
// RegistrationHandle : ULONGLONG* out -> 'uint64_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("ADVAPI32.dll", {
RegisterTraceGuidsW: { parameters: ["pointer", "pointer", "pointer", "u32", "pointer", "buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.RegisterTraceGuidsW(RequestAddress, RequestContext, ControlGuid, GuidCount, TraceGuidReg, MofImagePath, MofResourceName, RegistrationHandle)
// RequestAddress : WMIDPREQUEST -> "pointer"
// RequestContext : void* optional -> "pointer"
// ControlGuid : GUID* -> "pointer"
// GuidCount : DWORD -> "u32"
// TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> "pointer"
// MofImagePath : LPCWSTR optional -> "buffer"
// MofResourceName : LPCWSTR optional -> "buffer"
// RegistrationHandle : ULONGLONG* out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t RegisterTraceGuidsW(
void* RequestAddress,
void* RequestContext,
void* ControlGuid,
uint32_t GuidCount,
void* TraceGuidReg,
const uint16_t* MofImagePath,
const uint16_t* MofResourceName,
uint64_t* RegistrationHandle);
C, "ADVAPI32.dll");
// $ffi->RegisterTraceGuidsW(RequestAddress, RequestContext, ControlGuid, GuidCount, TraceGuidReg, MofImagePath, MofResourceName, RegistrationHandle);
// RequestAddress : WMIDPREQUEST
// RequestContext : void* optional
// ControlGuid : GUID*
// GuidCount : DWORD
// TraceGuidReg : TRACE_GUID_REGISTRATION* optional
// MofImagePath : LPCWSTR optional
// MofResourceName : LPCWSTR optional
// RegistrationHandle : ULONGLONG* 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 Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
int RegisterTraceGuidsW(
Callback RequestAddress, // WMIDPREQUEST
Pointer RequestContext, // void* optional
Pointer ControlGuid, // GUID*
int GuidCount, // DWORD
Pointer TraceGuidReg, // TRACE_GUID_REGISTRATION* optional
WString MofImagePath, // LPCWSTR optional
WString MofResourceName, // LPCWSTR optional
LongByReference RegistrationHandle // ULONGLONG* out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("advapi32")]
lib LibADVAPI32
fun RegisterTraceGuidsW = RegisterTraceGuidsW(
RequestAddress : Void*, # WMIDPREQUEST
RequestContext : Void*, # void* optional
ControlGuid : GUID*, # GUID*
GuidCount : UInt32, # DWORD
TraceGuidReg : TRACE_GUID_REGISTRATION*, # TRACE_GUID_REGISTRATION* optional
MofImagePath : UInt16*, # LPCWSTR optional
MofResourceName : UInt16*, # LPCWSTR optional
RegistrationHandle : UInt64* # ULONGLONG* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RegisterTraceGuidsWNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint32, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint64>);
typedef RegisterTraceGuidsWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint64>);
final RegisterTraceGuidsW = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<RegisterTraceGuidsWNative, RegisterTraceGuidsWDart>('RegisterTraceGuidsW');
// RequestAddress : WMIDPREQUEST -> Pointer<Void>
// RequestContext : void* optional -> Pointer<Void>
// ControlGuid : GUID* -> Pointer<Void>
// GuidCount : DWORD -> Uint32
// TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> Pointer<Void>
// MofImagePath : LPCWSTR optional -> Pointer<Utf16>
// MofResourceName : LPCWSTR optional -> Pointer<Utf16>
// RegistrationHandle : ULONGLONG* out -> Pointer<Uint64>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RegisterTraceGuidsW(
RequestAddress: Pointer; // WMIDPREQUEST
RequestContext: Pointer; // void* optional
ControlGuid: PGUID; // GUID*
GuidCount: DWORD; // DWORD
TraceGuidReg: Pointer; // TRACE_GUID_REGISTRATION* optional
MofImagePath: PWideChar; // LPCWSTR optional
MofResourceName: PWideChar; // LPCWSTR optional
RegistrationHandle: Pointer // ULONGLONG* out
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'RegisterTraceGuidsW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RegisterTraceGuidsW"
c_RegisterTraceGuidsW :: Ptr () -> Ptr () -> Ptr () -> Word32 -> Ptr () -> CWString -> CWString -> Ptr Word64 -> IO Word32
-- RequestAddress : WMIDPREQUEST -> Ptr ()
-- RequestContext : void* optional -> Ptr ()
-- ControlGuid : GUID* -> Ptr ()
-- GuidCount : DWORD -> Word32
-- TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> Ptr ()
-- MofImagePath : LPCWSTR optional -> CWString
-- MofResourceName : LPCWSTR optional -> CWString
-- RegistrationHandle : ULONGLONG* out -> Ptr Word64
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let registertraceguidsw =
foreign "RegisterTraceGuidsW"
((ptr void) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint64_t) @-> returning uint32_t)
(* RequestAddress : WMIDPREQUEST -> (ptr void) *)
(* RequestContext : void* optional -> (ptr void) *)
(* ControlGuid : GUID* -> (ptr void) *)
(* GuidCount : DWORD -> uint32_t *)
(* TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> (ptr void) *)
(* MofImagePath : LPCWSTR optional -> (ptr uint16_t) *)
(* MofResourceName : LPCWSTR optional -> (ptr uint16_t) *)
(* RegistrationHandle : ULONGLONG* out -> (ptr uint64_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("RegisterTraceGuidsW" register-trace-guids-w :convention :stdcall) :uint32
(request-address :pointer) ; WMIDPREQUEST
(request-context :pointer) ; void* optional
(control-guid :pointer) ; GUID*
(guid-count :uint32) ; DWORD
(trace-guid-reg :pointer) ; TRACE_GUID_REGISTRATION* optional
(mof-image-path (:string :encoding :utf-16le)) ; LPCWSTR optional
(mof-resource-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(registration-handle :pointer)) ; ULONGLONG* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RegisterTraceGuidsW = Win32::API::More->new('ADVAPI32',
'DWORD RegisterTraceGuidsW(LPVOID RequestAddress, LPVOID RequestContext, LPVOID ControlGuid, DWORD GuidCount, LPVOID TraceGuidReg, LPCWSTR MofImagePath, LPCWSTR MofResourceName, LPVOID RegistrationHandle)');
# my $ret = $RegisterTraceGuidsW->Call($RequestAddress, $RequestContext, $ControlGuid, $GuidCount, $TraceGuidReg, $MofImagePath, $MofResourceName, $RegistrationHandle);
# RequestAddress : WMIDPREQUEST -> LPVOID
# RequestContext : void* optional -> LPVOID
# ControlGuid : GUID* -> LPVOID
# GuidCount : DWORD -> DWORD
# TraceGuidReg : TRACE_GUID_REGISTRATION* optional -> LPVOID
# MofImagePath : LPCWSTR optional -> LPCWSTR
# MofResourceName : LPCWSTR optional -> LPCWSTR
# RegistrationHandle : ULONGLONG* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f RegisterTraceGuidsA (ANSI版) — クラシックETWプロバイダーのトレースGUIDを登録する(ANSI版)。