Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Etw › TraceQueryInformation

TraceQueryInformation

関数
トレースセッションの設定情報や状態を照会する。
DLLADVAPI32.dll呼出規約winapi対応OSwindows8.0

シグネチャ

// ADVAPI32.dll
#include <windows.h>

WIN32_ERROR TraceQueryInformation(
    ULONGLONG TraceId,
    TRACE_QUERY_INFO_CLASS InformationClass,
    void* TraceInformation,
    DWORD InformationLength,
    DWORD* ReturnLength   // optional
);

パラメーター

名前方向説明
TraceIdULONGLONGin情報を取得する対象トレースセッションのハンドル。
InformationClassTRACE_QUERY_INFO_CLASSin照会する情報クラスです。クラスがキャプチャする情報は、イベントの拡張データ セクションに含まれます。照会可能な情報クラスの一覧については、 TRACE_QUERY_INFO_CLASS 列挙型を 参照してください。
TraceInformationvoid*out返される情報クラス固有のデータを受け取るバッファーへのポインターです。 このパラメーターの内容は情報クラスによって決まります。たとえば、 TraceStackTracingInfo 情報クラスの場合、このパラメーターは CLASSIC_EVENT_ID 構造体の配列です。 これらの構造体は、スタック トレースが有効になっているイベント GUID を指定します。 配列は最大 256 要素に制限されます。
InformationLengthDWORDinTraceInformation バッファーに返されるデータのサイズ (バイト単位) です。 関数が失敗した場合、この値は必要となる TraceInformation バッファーのサイズを 示します。
ReturnLengthDWORD*outoptionalTraceInformation バッファーに返される固有データのサイズ (バイト単位) を 受け取る値へのポインターです。

戻り値の型: WIN32_ERROR

公式ドキュメント

イベント トレース セッションに関する情報を提供します。

戻り値

関数が成功した場合、戻り値は ERROR_SUCCESS です。

関数が失敗した場合、戻り値は次のいずれかのエラー コードになります。

解説(Remarks)

TraceQueryInformation 関数は、トレース セッションからイベント トレース セッションの設定を照会します。この関数は StartTrace を呼び出した後に呼び出してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// ADVAPI32.dll
#include <windows.h>

WIN32_ERROR TraceQueryInformation(
    ULONGLONG TraceId,
    TRACE_QUERY_INFO_CLASS InformationClass,
    void* TraceInformation,
    DWORD InformationLength,
    DWORD* ReturnLength   // optional
);
[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern uint TraceQueryInformation(
    ulong TraceId,   // ULONGLONG
    int InformationClass,   // TRACE_QUERY_INFO_CLASS
    IntPtr TraceInformation,   // void* out
    uint InformationLength,   // DWORD
    IntPtr ReturnLength   // DWORD* optional, out
);
<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function TraceQueryInformation(
    TraceId As ULong,   ' ULONGLONG
    InformationClass As Integer,   ' TRACE_QUERY_INFO_CLASS
    TraceInformation As IntPtr,   ' void* out
    InformationLength As UInteger,   ' DWORD
    ReturnLength As IntPtr   ' DWORD* optional, out
) As UInteger
End Function
' TraceId : ULONGLONG
' InformationClass : TRACE_QUERY_INFO_CLASS
' TraceInformation : void* out
' InformationLength : DWORD
' ReturnLength : DWORD* optional, out
Declare PtrSafe Function TraceQueryInformation Lib "advapi32" ( _
    ByVal TraceId As LongLong, _
    ByVal InformationClass As Long, _
    ByVal TraceInformation As LongPtr, _
    ByVal InformationLength As Long, _
    ByVal ReturnLength As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

TraceQueryInformation = ctypes.windll.advapi32.TraceQueryInformation
TraceQueryInformation.restype = wintypes.DWORD
TraceQueryInformation.argtypes = [
    ctypes.c_ulonglong,  # TraceId : ULONGLONG
    ctypes.c_int,  # InformationClass : TRACE_QUERY_INFO_CLASS
    ctypes.POINTER(None),  # TraceInformation : void* out
    wintypes.DWORD,  # InformationLength : DWORD
    ctypes.POINTER(wintypes.DWORD),  # ReturnLength : DWORD* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
TraceQueryInformation = Fiddle::Function.new(
  lib['TraceQueryInformation'],
  [
    -Fiddle::TYPE_LONG_LONG,  # TraceId : ULONGLONG
    Fiddle::TYPE_INT,  # InformationClass : TRACE_QUERY_INFO_CLASS
    Fiddle::TYPE_VOIDP,  # TraceInformation : void* out
    -Fiddle::TYPE_INT,  # InformationLength : DWORD
    Fiddle::TYPE_VOIDP,  # ReturnLength : DWORD* optional, out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn TraceQueryInformation(
        TraceId: u64,  // ULONGLONG
        InformationClass: i32,  // TRACE_QUERY_INFO_CLASS
        TraceInformation: *mut (),  // void* out
        InformationLength: u32,  // DWORD
        ReturnLength: *mut u32  // DWORD* optional, out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll")]
public static extern uint TraceQueryInformation(ulong TraceId, int InformationClass, IntPtr TraceInformation, uint InformationLength, IntPtr ReturnLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_TraceQueryInformation' -Namespace Win32 -PassThru
# $api::TraceQueryInformation(TraceId, InformationClass, TraceInformation, InformationLength, ReturnLength)
#uselib "ADVAPI32.dll"
#func global TraceQueryInformation "TraceQueryInformation" sptr, sptr, sptr, sptr, sptr
; TraceQueryInformation TraceId, InformationClass, TraceInformation, InformationLength, varptr(ReturnLength)   ; 戻り値は stat
; TraceId : ULONGLONG -> "sptr"
; InformationClass : TRACE_QUERY_INFO_CLASS -> "sptr"
; TraceInformation : void* out -> "sptr"
; InformationLength : DWORD -> "sptr"
; ReturnLength : DWORD* optional, out -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global TraceQueryInformation "TraceQueryInformation" int64, int, sptr, int, var
; res = TraceQueryInformation(TraceId, InformationClass, TraceInformation, InformationLength, ReturnLength)
; TraceId : ULONGLONG -> "int64"
; InformationClass : TRACE_QUERY_INFO_CLASS -> "int"
; TraceInformation : void* out -> "sptr"
; InformationLength : DWORD -> "int"
; ReturnLength : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; WIN32_ERROR TraceQueryInformation(ULONGLONG TraceId, TRACE_QUERY_INFO_CLASS InformationClass, void* TraceInformation, DWORD InformationLength, DWORD* ReturnLength)
#uselib "ADVAPI32.dll"
#cfunc global TraceQueryInformation "TraceQueryInformation" int64, int, intptr, int, var
; res = TraceQueryInformation(TraceId, InformationClass, TraceInformation, InformationLength, ReturnLength)
; TraceId : ULONGLONG -> "int64"
; InformationClass : TRACE_QUERY_INFO_CLASS -> "int"
; TraceInformation : void* out -> "intptr"
; InformationLength : DWORD -> "int"
; ReturnLength : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procTraceQueryInformation = advapi32.NewProc("TraceQueryInformation")
)

// TraceId (ULONGLONG), InformationClass (TRACE_QUERY_INFO_CLASS), TraceInformation (void* out), InformationLength (DWORD), ReturnLength (DWORD* optional, out)
r1, _, err := procTraceQueryInformation.Call(
	uintptr(TraceId),
	uintptr(InformationClass),
	uintptr(TraceInformation),
	uintptr(InformationLength),
	uintptr(ReturnLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function TraceQueryInformation(
  TraceId: UInt64;   // ULONGLONG
  InformationClass: Integer;   // TRACE_QUERY_INFO_CLASS
  TraceInformation: Pointer;   // void* out
  InformationLength: DWORD;   // DWORD
  ReturnLength: Pointer   // DWORD* optional, out
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'TraceQueryInformation';
result := DllCall("ADVAPI32\TraceQueryInformation"
    , "Int64", TraceId   ; ULONGLONG
    , "Int", InformationClass   ; TRACE_QUERY_INFO_CLASS
    , "Ptr", TraceInformation   ; void* out
    , "UInt", InformationLength   ; DWORD
    , "Ptr", ReturnLength   ; DWORD* optional, out
    , "UInt")   ; return: WIN32_ERROR
●TraceQueryInformation(TraceId, InformationClass, TraceInformation, InformationLength, ReturnLength) = DLL("ADVAPI32.dll", "dword TraceQueryInformation(qword, int, void*, dword, void*)")
# 呼び出し: TraceQueryInformation(TraceId, InformationClass, TraceInformation, InformationLength, ReturnLength)
# TraceId : ULONGLONG -> "qword"
# InformationClass : TRACE_QUERY_INFO_CLASS -> "int"
# TraceInformation : void* out -> "void*"
# InformationLength : DWORD -> "dword"
# ReturnLength : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "advapi32" fn TraceQueryInformation(
    TraceId: u64, // ULONGLONG
    InformationClass: i32, // TRACE_QUERY_INFO_CLASS
    TraceInformation: ?*anyopaque, // void* out
    InformationLength: u32, // DWORD
    ReturnLength: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) u32;
proc TraceQueryInformation(
    TraceId: uint64,  # ULONGLONG
    InformationClass: int32,  # TRACE_QUERY_INFO_CLASS
    TraceInformation: pointer,  # void* out
    InformationLength: uint32,  # DWORD
    ReturnLength: ptr uint32  # DWORD* optional, out
): uint32 {.importc: "TraceQueryInformation", stdcall, dynlib: "ADVAPI32.dll".}
pragma(lib, "advapi32");
extern(Windows)
uint TraceQueryInformation(
    ulong TraceId,   // ULONGLONG
    int InformationClass,   // TRACE_QUERY_INFO_CLASS
    void* TraceInformation,   // void* out
    uint InformationLength,   // DWORD
    uint* ReturnLength   // DWORD* optional, out
);
ccall((:TraceQueryInformation, "ADVAPI32.dll"), stdcall, UInt32,
      (UInt64, Int32, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
      TraceId, InformationClass, TraceInformation, InformationLength, ReturnLength)
# TraceId : ULONGLONG -> UInt64
# InformationClass : TRACE_QUERY_INFO_CLASS -> Int32
# TraceInformation : void* out -> Ptr{Cvoid}
# InformationLength : DWORD -> UInt32
# ReturnLength : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t TraceQueryInformation(
    uint64_t TraceId,
    int32_t InformationClass,
    void* TraceInformation,
    uint32_t InformationLength,
    uint32_t* ReturnLength);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.TraceQueryInformation(TraceId, InformationClass, TraceInformation, InformationLength, ReturnLength)
-- TraceId : ULONGLONG
-- InformationClass : TRACE_QUERY_INFO_CLASS
-- TraceInformation : void* out
-- InformationLength : DWORD
-- ReturnLength : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const TraceQueryInformation = lib.func('__stdcall', 'TraceQueryInformation', 'uint32_t', ['uint64_t', 'int32_t', 'void *', 'uint32_t', 'uint32_t *']);
// TraceQueryInformation(TraceId, InformationClass, TraceInformation, InformationLength, ReturnLength)
// TraceId : ULONGLONG -> 'uint64_t'
// InformationClass : TRACE_QUERY_INFO_CLASS -> 'int32_t'
// TraceInformation : void* out -> 'void *'
// InformationLength : DWORD -> 'uint32_t'
// ReturnLength : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ADVAPI32.dll", {
  TraceQueryInformation: { parameters: ["u64", "i32", "pointer", "u32", "pointer"], result: "u32" },
});
// lib.symbols.TraceQueryInformation(TraceId, InformationClass, TraceInformation, InformationLength, ReturnLength)
// TraceId : ULONGLONG -> "u64"
// InformationClass : TRACE_QUERY_INFO_CLASS -> "i32"
// TraceInformation : void* out -> "pointer"
// InformationLength : DWORD -> "u32"
// ReturnLength : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t TraceQueryInformation(
    uint64_t TraceId,
    int32_t InformationClass,
    void* TraceInformation,
    uint32_t InformationLength,
    uint32_t* ReturnLength);
C, "ADVAPI32.dll");
// $ffi->TraceQueryInformation(TraceId, InformationClass, TraceInformation, InformationLength, ReturnLength);
// TraceId : ULONGLONG
// InformationClass : TRACE_QUERY_INFO_CLASS
// TraceInformation : void* out
// InformationLength : DWORD
// ReturnLength : DWORD* optional, 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);
    int TraceQueryInformation(
        long TraceId,   // ULONGLONG
        int InformationClass,   // TRACE_QUERY_INFO_CLASS
        Pointer TraceInformation,   // void* out
        int InformationLength,   // DWORD
        IntByReference ReturnLength   // DWORD* optional, out
    );
}
@[Link("advapi32")]
lib LibADVAPI32
  fun TraceQueryInformation = TraceQueryInformation(
    TraceId : UInt64,   # ULONGLONG
    InformationClass : Int32,   # TRACE_QUERY_INFO_CLASS
    TraceInformation : Void*,   # void* out
    InformationLength : UInt32,   # DWORD
    ReturnLength : UInt32*   # DWORD* optional, out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef TraceQueryInformationNative = Uint32 Function(Uint64, Int32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef TraceQueryInformationDart = int Function(int, int, Pointer<Void>, int, Pointer<Uint32>);
final TraceQueryInformation = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<TraceQueryInformationNative, TraceQueryInformationDart>('TraceQueryInformation');
// TraceId : ULONGLONG -> Uint64
// InformationClass : TRACE_QUERY_INFO_CLASS -> Int32
// TraceInformation : void* out -> Pointer<Void>
// InformationLength : DWORD -> Uint32
// ReturnLength : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function TraceQueryInformation(
  TraceId: UInt64;   // ULONGLONG
  InformationClass: Integer;   // TRACE_QUERY_INFO_CLASS
  TraceInformation: Pointer;   // void* out
  InformationLength: DWORD;   // DWORD
  ReturnLength: Pointer   // DWORD* optional, out
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'TraceQueryInformation';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "TraceQueryInformation"
  c_TraceQueryInformation :: Word64 -> Int32 -> Ptr () -> Word32 -> Ptr Word32 -> IO Word32
-- TraceId : ULONGLONG -> Word64
-- InformationClass : TRACE_QUERY_INFO_CLASS -> Int32
-- TraceInformation : void* out -> Ptr ()
-- InformationLength : DWORD -> Word32
-- ReturnLength : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let tracequeryinformation =
  foreign "TraceQueryInformation"
    (uint64_t @-> int32_t @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning uint32_t)
(* TraceId : ULONGLONG -> uint64_t *)
(* InformationClass : TRACE_QUERY_INFO_CLASS -> int32_t *)
(* TraceInformation : void* out -> (ptr void) *)
(* InformationLength : DWORD -> uint32_t *)
(* ReturnLength : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("TraceQueryInformation" trace-query-information :convention :stdcall) :uint32
  (trace-id :uint64)   ; ULONGLONG
  (information-class :int32)   ; TRACE_QUERY_INFO_CLASS
  (trace-information :pointer)   ; void* out
  (information-length :uint32)   ; DWORD
  (return-length :pointer))   ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $TraceQueryInformation = Win32::API::More->new('ADVAPI32',
    'DWORD TraceQueryInformation(UINT64 TraceId, int InformationClass, LPVOID TraceInformation, DWORD InformationLength, LPVOID ReturnLength)');
# my $ret = $TraceQueryInformation->Call($TraceId, $InformationClass, $TraceInformation, $InformationLength, $ReturnLength);
# TraceId : ULONGLONG -> UINT64
# InformationClass : TRACE_QUERY_INFO_CLASS -> int
# TraceInformation : void* out -> LPVOID
# InformationLength : DWORD -> DWORD
# ReturnLength : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型