ホーム › System.Diagnostics.Etw › ControlTraceA
ControlTraceA
関数制御コードを指定してトレースセッションを制御する(ANSI版)。
シグネチャ
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR ControlTraceA(
ULONGLONG TraceId,
LPCSTR InstanceName, // optional
EVENT_TRACE_PROPERTIES* Properties,
EVENT_TRACE_CONTROL ControlCode
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| TraceId | ULONGLONG | in |
| InstanceName | LPCSTR | inoptional |
| Properties | EVENT_TRACE_PROPERTIES* | inout |
| ControlCode | EVENT_TRACE_CONTROL | in |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR ControlTraceA(
ULONGLONG TraceId,
LPCSTR InstanceName, // optional
EVENT_TRACE_PROPERTIES* Properties,
EVENT_TRACE_CONTROL ControlCode
);[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint ControlTraceA(
ulong TraceId, // ULONGLONG
[MarshalAs(UnmanagedType.LPStr)] string InstanceName, // LPCSTR optional
IntPtr Properties, // EVENT_TRACE_PROPERTIES* in/out
uint ControlCode // EVENT_TRACE_CONTROL
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function ControlTraceA(
TraceId As ULong, ' ULONGLONG
<MarshalAs(UnmanagedType.LPStr)> InstanceName As String, ' LPCSTR optional
Properties As IntPtr, ' EVENT_TRACE_PROPERTIES* in/out
ControlCode As UInteger ' EVENT_TRACE_CONTROL
) As UInteger
End Function' TraceId : ULONGLONG
' InstanceName : LPCSTR optional
' Properties : EVENT_TRACE_PROPERTIES* in/out
' ControlCode : EVENT_TRACE_CONTROL
Declare PtrSafe Function ControlTraceA Lib "advapi32" ( _
ByVal TraceId As LongLong, _
ByVal InstanceName As String, _
ByVal Properties As LongPtr, _
ByVal ControlCode As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ControlTraceA = ctypes.windll.advapi32.ControlTraceA
ControlTraceA.restype = wintypes.DWORD
ControlTraceA.argtypes = [
ctypes.c_ulonglong, # TraceId : ULONGLONG
wintypes.LPCSTR, # InstanceName : LPCSTR optional
ctypes.c_void_p, # Properties : EVENT_TRACE_PROPERTIES* in/out
wintypes.DWORD, # ControlCode : EVENT_TRACE_CONTROL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
ControlTraceA = Fiddle::Function.new(
lib['ControlTraceA'],
[
-Fiddle::TYPE_LONG_LONG, # TraceId : ULONGLONG
Fiddle::TYPE_VOIDP, # InstanceName : LPCSTR optional
Fiddle::TYPE_VOIDP, # Properties : EVENT_TRACE_PROPERTIES* in/out
-Fiddle::TYPE_INT, # ControlCode : EVENT_TRACE_CONTROL
],
-Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn ControlTraceA(
TraceId: u64, // ULONGLONG
InstanceName: *const u8, // LPCSTR optional
Properties: *mut EVENT_TRACE_PROPERTIES, // EVENT_TRACE_PROPERTIES* in/out
ControlCode: u32 // EVENT_TRACE_CONTROL
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi)]
public static extern uint ControlTraceA(ulong TraceId, [MarshalAs(UnmanagedType.LPStr)] string InstanceName, IntPtr Properties, uint ControlCode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_ControlTraceA' -Namespace Win32 -PassThru
# $api::ControlTraceA(TraceId, InstanceName, Properties, ControlCode)#uselib "ADVAPI32.dll"
#func global ControlTraceA "ControlTraceA" sptr, sptr, sptr, sptr
; ControlTraceA TraceId, InstanceName, varptr(Properties), ControlCode ; 戻り値は stat
; TraceId : ULONGLONG -> "sptr"
; InstanceName : LPCSTR optional -> "sptr"
; Properties : EVENT_TRACE_PROPERTIES* in/out -> "sptr"
; ControlCode : EVENT_TRACE_CONTROL -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global ControlTraceA "ControlTraceA" int64, str, var, int ; res = ControlTraceA(TraceId, InstanceName, Properties, ControlCode) ; TraceId : ULONGLONG -> "int64" ; InstanceName : LPCSTR optional -> "str" ; Properties : EVENT_TRACE_PROPERTIES* in/out -> "var" ; ControlCode : EVENT_TRACE_CONTROL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。#uselib "ADVAPI32.dll" #cfunc global ControlTraceA "ControlTraceA" int64, str, sptr, int ; res = ControlTraceA(TraceId, InstanceName, varptr(Properties), ControlCode) ; TraceId : ULONGLONG -> "int64" ; InstanceName : LPCSTR optional -> "str" ; Properties : EVENT_TRACE_PROPERTIES* in/out -> "sptr" ; ControlCode : EVENT_TRACE_CONTROL -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; WIN32_ERROR ControlTraceA(ULONGLONG TraceId, LPCSTR InstanceName, EVENT_TRACE_PROPERTIES* Properties, EVENT_TRACE_CONTROL ControlCode) #uselib "ADVAPI32.dll" #cfunc global ControlTraceA "ControlTraceA" int64, str, var, int ; res = ControlTraceA(TraceId, InstanceName, Properties, ControlCode) ; TraceId : ULONGLONG -> "int64" ; InstanceName : LPCSTR optional -> "str" ; Properties : EVENT_TRACE_PROPERTIES* in/out -> "var" ; ControlCode : EVENT_TRACE_CONTROL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR ControlTraceA(ULONGLONG TraceId, LPCSTR InstanceName, EVENT_TRACE_PROPERTIES* Properties, EVENT_TRACE_CONTROL ControlCode) #uselib "ADVAPI32.dll" #cfunc global ControlTraceA "ControlTraceA" int64, str, intptr, int ; res = ControlTraceA(TraceId, InstanceName, varptr(Properties), ControlCode) ; TraceId : ULONGLONG -> "int64" ; InstanceName : LPCSTR optional -> "str" ; Properties : EVENT_TRACE_PROPERTIES* in/out -> "intptr" ; ControlCode : EVENT_TRACE_CONTROL -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procControlTraceA = advapi32.NewProc("ControlTraceA")
)
// TraceId (ULONGLONG), InstanceName (LPCSTR optional), Properties (EVENT_TRACE_PROPERTIES* in/out), ControlCode (EVENT_TRACE_CONTROL)
r1, _, err := procControlTraceA.Call(
uintptr(TraceId),
uintptr(unsafe.Pointer(windows.BytePtrFromString(InstanceName))),
uintptr(Properties),
uintptr(ControlCode),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction ControlTraceA(
TraceId: UInt64; // ULONGLONG
InstanceName: PAnsiChar; // LPCSTR optional
Properties: Pointer; // EVENT_TRACE_PROPERTIES* in/out
ControlCode: DWORD // EVENT_TRACE_CONTROL
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'ControlTraceA';result := DllCall("ADVAPI32\ControlTraceA"
, "Int64", TraceId ; ULONGLONG
, "AStr", InstanceName ; LPCSTR optional
, "Ptr", Properties ; EVENT_TRACE_PROPERTIES* in/out
, "UInt", ControlCode ; EVENT_TRACE_CONTROL
, "UInt") ; return: WIN32_ERROR●ControlTraceA(TraceId, InstanceName, Properties, ControlCode) = DLL("ADVAPI32.dll", "dword ControlTraceA(qword, char*, void*, dword)")
# 呼び出し: ControlTraceA(TraceId, InstanceName, Properties, ControlCode)
# TraceId : ULONGLONG -> "qword"
# InstanceName : LPCSTR optional -> "char*"
# Properties : EVENT_TRACE_PROPERTIES* in/out -> "void*"
# ControlCode : EVENT_TRACE_CONTROL -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。