Win32 API 日本語リファレンス
ホームSystem.Performance.HardwareCounterProfiling › QueryThreadProfiling

QueryThreadProfiling

関数
指定スレッドのプロファイリングが有効か照会する。
DLLKERNEL32.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

DWORD QueryThreadProfiling(
    HANDLE ThreadHandle,
    BOOLEAN* Enabled
);

パラメーター

名前方向説明
ThreadHandleHANDLEinプロファイリング状態を問い合わせる対象スレッドのハンドル。
EnabledBOOLEAN*outプロファイリングが有効かを受け取るBOOLEANへの出力ポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD QueryThreadProfiling(
    HANDLE ThreadHandle,
    BOOLEAN* Enabled
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern uint QueryThreadProfiling(
    IntPtr ThreadHandle,   // HANDLE
    [MarshalAs(UnmanagedType.U1)] out bool Enabled   // BOOLEAN* out
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function QueryThreadProfiling(
    ThreadHandle As IntPtr,   ' HANDLE
    <MarshalAs(UnmanagedType.U1)> <Out> ByRef Enabled As Boolean   ' BOOLEAN* out
) As UInteger
End Function
' ThreadHandle : HANDLE
' Enabled : BOOLEAN* out
Declare PtrSafe Function QueryThreadProfiling Lib "kernel32" ( _
    ByVal ThreadHandle As LongPtr, _
    ByRef Enabled As Byte) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

QueryThreadProfiling = ctypes.windll.kernel32.QueryThreadProfiling
QueryThreadProfiling.restype = wintypes.DWORD
QueryThreadProfiling.argtypes = [
    wintypes.HANDLE,  # ThreadHandle : HANDLE
    ctypes.c_void_p,  # Enabled : BOOLEAN* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
QueryThreadProfiling = Fiddle::Function.new(
  lib['QueryThreadProfiling'],
  [
    Fiddle::TYPE_VOIDP,  # ThreadHandle : HANDLE
    Fiddle::TYPE_VOIDP,  # Enabled : BOOLEAN* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn QueryThreadProfiling(
        ThreadHandle: *mut core::ffi::c_void,  // HANDLE
        Enabled: *mut u8  // BOOLEAN* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern uint QueryThreadProfiling(IntPtr ThreadHandle, [MarshalAs(UnmanagedType.U1)] out bool Enabled);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_QueryThreadProfiling' -Namespace Win32 -PassThru
# $api::QueryThreadProfiling(ThreadHandle, Enabled)
#uselib "KERNEL32.dll"
#func global QueryThreadProfiling "QueryThreadProfiling" sptr, sptr
; QueryThreadProfiling ThreadHandle, varptr(Enabled)   ; 戻り値は stat
; ThreadHandle : HANDLE -> "sptr"
; Enabled : BOOLEAN* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global QueryThreadProfiling "QueryThreadProfiling" sptr, var
; res = QueryThreadProfiling(ThreadHandle, Enabled)
; ThreadHandle : HANDLE -> "sptr"
; Enabled : BOOLEAN* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD QueryThreadProfiling(HANDLE ThreadHandle, BOOLEAN* Enabled)
#uselib "KERNEL32.dll"
#cfunc global QueryThreadProfiling "QueryThreadProfiling" intptr, var
; res = QueryThreadProfiling(ThreadHandle, Enabled)
; ThreadHandle : HANDLE -> "intptr"
; Enabled : BOOLEAN* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procQueryThreadProfiling = kernel32.NewProc("QueryThreadProfiling")
)

// ThreadHandle (HANDLE), Enabled (BOOLEAN* out)
r1, _, err := procQueryThreadProfiling.Call(
	uintptr(ThreadHandle),
	uintptr(Enabled),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function QueryThreadProfiling(
  ThreadHandle: THandle;   // HANDLE
  Enabled: Pointer   // BOOLEAN* out
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'QueryThreadProfiling';
result := DllCall("KERNEL32\QueryThreadProfiling"
    , "Ptr", ThreadHandle   ; HANDLE
    , "Ptr", Enabled   ; BOOLEAN* out
    , "UInt")   ; return: DWORD
●QueryThreadProfiling(ThreadHandle, Enabled) = DLL("KERNEL32.dll", "dword QueryThreadProfiling(void*, void*)")
# 呼び出し: QueryThreadProfiling(ThreadHandle, Enabled)
# ThreadHandle : HANDLE -> "void*"
# Enabled : BOOLEAN* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef QueryThreadProfilingNative = Uint32 Function(Pointer<Void>, Pointer<Uint8>);
typedef QueryThreadProfilingDart = int Function(Pointer<Void>, Pointer<Uint8>);
final QueryThreadProfiling = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<QueryThreadProfilingNative, QueryThreadProfilingDart>('QueryThreadProfiling');
// ThreadHandle : HANDLE -> Pointer<Void>
// Enabled : BOOLEAN* out -> Pointer<Uint8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function QueryThreadProfiling(
  ThreadHandle: THandle;   // HANDLE
  Enabled: Pointer   // BOOLEAN* out
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'QueryThreadProfiling';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "QueryThreadProfiling"
  c_QueryThreadProfiling :: Ptr () -> Ptr Word8 -> IO Word32
-- ThreadHandle : HANDLE -> Ptr ()
-- Enabled : BOOLEAN* out -> Ptr Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let querythreadprofiling =
  foreign "QueryThreadProfiling"
    ((ptr void) @-> (ptr uint8_t) @-> returning uint32_t)
(* ThreadHandle : HANDLE -> (ptr void) *)
(* Enabled : BOOLEAN* out -> (ptr uint8_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("QueryThreadProfiling" query-thread-profiling :convention :stdcall) :uint32
  (thread-handle :pointer)   ; HANDLE
  (enabled :pointer))   ; BOOLEAN* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $QueryThreadProfiling = Win32::API::More->new('KERNEL32',
    'DWORD QueryThreadProfiling(HANDLE ThreadHandle, LPVOID Enabled)');
# my $ret = $QueryThreadProfiling->Call($ThreadHandle, $Enabled);
# ThreadHandle : HANDLE -> HANDLE
# Enabled : BOOLEAN* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。