GetThreadInformation
関数シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL GetThreadInformation(
HANDLE hThread,
THREAD_INFORMATION_CLASS ThreadInformationClass,
void* ThreadInformation,
DWORD ThreadInformationSize
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hThread | HANDLE | in | スレッドのハンドル。このハンドルには THREAD_QUERY_INFORMATION アクセス権が必要です。詳細については、スレッドのセキュリティとアクセス権を参照してください。 |
| ThreadInformationClass | THREAD_INFORMATION_CLASS | in | 取得する情報のクラス。この値には ThreadMemoryPriority、ThreadAbsoluteCpuPriority、または ThreadDynamicCodePolicy を指定できます。 メモ
ThreadDynamicCodePolicy は、Windows Server 2016 以降、Windows 10 LTSB 2016 以降、および Windows 10 バージョン 1607 以降でサポートされています。 |
| ThreadInformation | void* | out | ThreadInformationClass パラメーターで指定した種類の情報を受け取る構造体へのポインター。 ThreadInformationClass パラメーターが ThreadMemoryPriority の場合、このパラメーターは MEMORY_PRIORITY_INFORMATION 構造体を指している必要があります。 ThreadInformationClass パラメーターが ThreadAbsoluteCpuPriority の場合、このパラメーターは LONG を指している必要があります。 ThreadInformationClass パラメーターが ThreadDynamicCodePolicy の場合、このパラメーターは DWORD を指している必要があります。 |
| ThreadInformationSize | DWORD | in | ThreadInformation パラメーターで指定した構造体のサイズ(バイト単位)。 ThreadInformationClass パラメーターが ThreadMemoryPriority の場合、このパラメーターは ThreadInformationClass パラメーターが ThreadAbsoluteCpuPriority の場合、このパラメーターは ThreadInformationClass パラメーターが ThreadDynamicCodePolicy の場合、このパラメーターは |
戻り値の型: BOOL
公式ドキュメント
指定したスレッドに関する情報を取得します。(GetThreadInformation)
戻り値
関数が成功した場合、戻り値は 0 以外の値になります。
関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、GetLastError を呼び出してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL GetThreadInformation(
HANDLE hThread,
THREAD_INFORMATION_CLASS ThreadInformationClass,
void* ThreadInformation,
DWORD ThreadInformationSize
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetThreadInformation(
IntPtr hThread, // HANDLE
int ThreadInformationClass, // THREAD_INFORMATION_CLASS
IntPtr ThreadInformation, // void* out
uint ThreadInformationSize // DWORD
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetThreadInformation(
hThread As IntPtr, ' HANDLE
ThreadInformationClass As Integer, ' THREAD_INFORMATION_CLASS
ThreadInformation As IntPtr, ' void* out
ThreadInformationSize As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hThread : HANDLE
' ThreadInformationClass : THREAD_INFORMATION_CLASS
' ThreadInformation : void* out
' ThreadInformationSize : DWORD
Declare PtrSafe Function GetThreadInformation Lib "kernel32" ( _
ByVal hThread As LongPtr, _
ByVal ThreadInformationClass As Long, _
ByVal ThreadInformation As LongPtr, _
ByVal ThreadInformationSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetThreadInformation = ctypes.windll.kernel32.GetThreadInformation
GetThreadInformation.restype = wintypes.BOOL
GetThreadInformation.argtypes = [
wintypes.HANDLE, # hThread : HANDLE
ctypes.c_int, # ThreadInformationClass : THREAD_INFORMATION_CLASS
ctypes.POINTER(None), # ThreadInformation : void* out
wintypes.DWORD, # ThreadInformationSize : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetThreadInformation = Fiddle::Function.new(
lib['GetThreadInformation'],
[
Fiddle::TYPE_VOIDP, # hThread : HANDLE
Fiddle::TYPE_INT, # ThreadInformationClass : THREAD_INFORMATION_CLASS
Fiddle::TYPE_VOIDP, # ThreadInformation : void* out
-Fiddle::TYPE_INT, # ThreadInformationSize : DWORD
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn GetThreadInformation(
hThread: *mut core::ffi::c_void, // HANDLE
ThreadInformationClass: i32, // THREAD_INFORMATION_CLASS
ThreadInformation: *mut (), // void* out
ThreadInformationSize: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool GetThreadInformation(IntPtr hThread, int ThreadInformationClass, IntPtr ThreadInformation, uint ThreadInformationSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetThreadInformation' -Namespace Win32 -PassThru
# $api::GetThreadInformation(hThread, ThreadInformationClass, ThreadInformation, ThreadInformationSize)#uselib "KERNEL32.dll"
#func global GetThreadInformation "GetThreadInformation" sptr, sptr, sptr, sptr
; GetThreadInformation hThread, ThreadInformationClass, ThreadInformation, ThreadInformationSize ; 戻り値は stat
; hThread : HANDLE -> "sptr"
; ThreadInformationClass : THREAD_INFORMATION_CLASS -> "sptr"
; ThreadInformation : void* out -> "sptr"
; ThreadInformationSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global GetThreadInformation "GetThreadInformation" sptr, int, sptr, int
; res = GetThreadInformation(hThread, ThreadInformationClass, ThreadInformation, ThreadInformationSize)
; hThread : HANDLE -> "sptr"
; ThreadInformationClass : THREAD_INFORMATION_CLASS -> "int"
; ThreadInformation : void* out -> "sptr"
; ThreadInformationSize : DWORD -> "int"; BOOL GetThreadInformation(HANDLE hThread, THREAD_INFORMATION_CLASS ThreadInformationClass, void* ThreadInformation, DWORD ThreadInformationSize)
#uselib "KERNEL32.dll"
#cfunc global GetThreadInformation "GetThreadInformation" intptr, int, intptr, int
; res = GetThreadInformation(hThread, ThreadInformationClass, ThreadInformation, ThreadInformationSize)
; hThread : HANDLE -> "intptr"
; ThreadInformationClass : THREAD_INFORMATION_CLASS -> "int"
; ThreadInformation : void* out -> "intptr"
; ThreadInformationSize : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetThreadInformation = kernel32.NewProc("GetThreadInformation")
)
// hThread (HANDLE), ThreadInformationClass (THREAD_INFORMATION_CLASS), ThreadInformation (void* out), ThreadInformationSize (DWORD)
r1, _, err := procGetThreadInformation.Call(
uintptr(hThread),
uintptr(ThreadInformationClass),
uintptr(ThreadInformation),
uintptr(ThreadInformationSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetThreadInformation(
hThread: THandle; // HANDLE
ThreadInformationClass: Integer; // THREAD_INFORMATION_CLASS
ThreadInformation: Pointer; // void* out
ThreadInformationSize: DWORD // DWORD
): BOOL; stdcall;
external 'KERNEL32.dll' name 'GetThreadInformation';result := DllCall("KERNEL32\GetThreadInformation"
, "Ptr", hThread ; HANDLE
, "Int", ThreadInformationClass ; THREAD_INFORMATION_CLASS
, "Ptr", ThreadInformation ; void* out
, "UInt", ThreadInformationSize ; DWORD
, "Int") ; return: BOOL●GetThreadInformation(hThread, ThreadInformationClass, ThreadInformation, ThreadInformationSize) = DLL("KERNEL32.dll", "bool GetThreadInformation(void*, int, void*, dword)")
# 呼び出し: GetThreadInformation(hThread, ThreadInformationClass, ThreadInformation, ThreadInformationSize)
# hThread : HANDLE -> "void*"
# ThreadInformationClass : THREAD_INFORMATION_CLASS -> "int"
# ThreadInformation : void* out -> "void*"
# ThreadInformationSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn GetThreadInformation(
hThread: ?*anyopaque, // HANDLE
ThreadInformationClass: i32, // THREAD_INFORMATION_CLASS
ThreadInformation: ?*anyopaque, // void* out
ThreadInformationSize: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc GetThreadInformation(
hThread: pointer, # HANDLE
ThreadInformationClass: int32, # THREAD_INFORMATION_CLASS
ThreadInformation: pointer, # void* out
ThreadInformationSize: uint32 # DWORD
): int32 {.importc: "GetThreadInformation", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int GetThreadInformation(
void* hThread, // HANDLE
int ThreadInformationClass, // THREAD_INFORMATION_CLASS
void* ThreadInformation, // void* out
uint ThreadInformationSize // DWORD
);ccall((:GetThreadInformation, "KERNEL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Ptr{Cvoid}, UInt32),
hThread, ThreadInformationClass, ThreadInformation, ThreadInformationSize)
# hThread : HANDLE -> Ptr{Cvoid}
# ThreadInformationClass : THREAD_INFORMATION_CLASS -> Int32
# ThreadInformation : void* out -> Ptr{Cvoid}
# ThreadInformationSize : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetThreadInformation(
void* hThread,
int32_t ThreadInformationClass,
void* ThreadInformation,
uint32_t ThreadInformationSize);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetThreadInformation(hThread, ThreadInformationClass, ThreadInformation, ThreadInformationSize)
-- hThread : HANDLE
-- ThreadInformationClass : THREAD_INFORMATION_CLASS
-- ThreadInformation : void* out
-- ThreadInformationSize : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetThreadInformation = lib.func('__stdcall', 'GetThreadInformation', 'int32_t', ['void *', 'int32_t', 'void *', 'uint32_t']);
// GetThreadInformation(hThread, ThreadInformationClass, ThreadInformation, ThreadInformationSize)
// hThread : HANDLE -> 'void *'
// ThreadInformationClass : THREAD_INFORMATION_CLASS -> 'int32_t'
// ThreadInformation : void* out -> 'void *'
// ThreadInformationSize : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
GetThreadInformation: { parameters: ["pointer", "i32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.GetThreadInformation(hThread, ThreadInformationClass, ThreadInformation, ThreadInformationSize)
// hThread : HANDLE -> "pointer"
// ThreadInformationClass : THREAD_INFORMATION_CLASS -> "i32"
// ThreadInformation : void* out -> "pointer"
// ThreadInformationSize : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetThreadInformation(
void* hThread,
int32_t ThreadInformationClass,
void* ThreadInformation,
uint32_t ThreadInformationSize);
C, "KERNEL32.dll");
// $ffi->GetThreadInformation(hThread, ThreadInformationClass, ThreadInformation, ThreadInformationSize);
// hThread : HANDLE
// ThreadInformationClass : THREAD_INFORMATION_CLASS
// ThreadInformation : void* out
// ThreadInformationSize : DWORD
// 構造体/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);
boolean GetThreadInformation(
Pointer hThread, // HANDLE
int ThreadInformationClass, // THREAD_INFORMATION_CLASS
Pointer ThreadInformation, // void* out
int ThreadInformationSize // DWORD
);
}@[Link("kernel32")]
lib LibKERNEL32
fun GetThreadInformation = GetThreadInformation(
hThread : Void*, # HANDLE
ThreadInformationClass : Int32, # THREAD_INFORMATION_CLASS
ThreadInformation : Void*, # void* out
ThreadInformationSize : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetThreadInformationNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Uint32);
typedef GetThreadInformationDart = int Function(Pointer<Void>, int, Pointer<Void>, int);
final GetThreadInformation = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<GetThreadInformationNative, GetThreadInformationDart>('GetThreadInformation');
// hThread : HANDLE -> Pointer<Void>
// ThreadInformationClass : THREAD_INFORMATION_CLASS -> Int32
// ThreadInformation : void* out -> Pointer<Void>
// ThreadInformationSize : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetThreadInformation(
hThread: THandle; // HANDLE
ThreadInformationClass: Integer; // THREAD_INFORMATION_CLASS
ThreadInformation: Pointer; // void* out
ThreadInformationSize: DWORD // DWORD
): BOOL; stdcall;
external 'KERNEL32.dll' name 'GetThreadInformation';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetThreadInformation"
c_GetThreadInformation :: Ptr () -> Int32 -> Ptr () -> Word32 -> IO CInt
-- hThread : HANDLE -> Ptr ()
-- ThreadInformationClass : THREAD_INFORMATION_CLASS -> Int32
-- ThreadInformation : void* out -> Ptr ()
-- ThreadInformationSize : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getthreadinformation =
foreign "GetThreadInformation"
((ptr void) @-> int32_t @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* hThread : HANDLE -> (ptr void) *)
(* ThreadInformationClass : THREAD_INFORMATION_CLASS -> int32_t *)
(* ThreadInformation : void* out -> (ptr void) *)
(* ThreadInformationSize : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("GetThreadInformation" get-thread-information :convention :stdcall) :int32
(h-thread :pointer) ; HANDLE
(thread-information-class :int32) ; THREAD_INFORMATION_CLASS
(thread-information :pointer) ; void* out
(thread-information-size :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetThreadInformation = Win32::API::More->new('KERNEL32',
'BOOL GetThreadInformation(HANDLE hThread, int ThreadInformationClass, LPVOID ThreadInformation, DWORD ThreadInformationSize)');
# my $ret = $GetThreadInformation->Call($hThread, $ThreadInformationClass, $ThreadInformation, $ThreadInformationSize);
# hThread : HANDLE -> HANDLE
# ThreadInformationClass : THREAD_INFORMATION_CLASS -> int
# ThreadInformation : void* out -> LPVOID
# ThreadInformationSize : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。