Win32 API 日本語リファレンス
ホームSystem.Threading › SetThreadPriorityBoost

SetThreadPriorityBoost

関数
スレッドの動的な優先度ブーストを有効または無効にする。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetThreadPriorityBoost(
    HANDLE hThread,
    BOOL bDisablePriorityBoost
);

パラメーター

名前方向
hThreadHANDLEin
bDisablePriorityBoostBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetThreadPriorityBoost(
    HANDLE hThread,
    BOOL bDisablePriorityBoost
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetThreadPriorityBoost(
    IntPtr hThread,   // HANDLE
    bool bDisablePriorityBoost   // BOOL
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetThreadPriorityBoost(
    hThread As IntPtr,   ' HANDLE
    bDisablePriorityBoost As Boolean   ' BOOL
) As Boolean
End Function
' hThread : HANDLE
' bDisablePriorityBoost : BOOL
Declare PtrSafe Function SetThreadPriorityBoost Lib "kernel32" ( _
    ByVal hThread As LongPtr, _
    ByVal bDisablePriorityBoost As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetThreadPriorityBoost = ctypes.windll.kernel32.SetThreadPriorityBoost
SetThreadPriorityBoost.restype = wintypes.BOOL
SetThreadPriorityBoost.argtypes = [
    wintypes.HANDLE,  # hThread : HANDLE
    wintypes.BOOL,  # bDisablePriorityBoost : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetThreadPriorityBoost = Fiddle::Function.new(
  lib['SetThreadPriorityBoost'],
  [
    Fiddle::TYPE_VOIDP,  # hThread : HANDLE
    Fiddle::TYPE_INT,  # bDisablePriorityBoost : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SetThreadPriorityBoost(
        hThread: *mut core::ffi::c_void,  // HANDLE
        bDisablePriorityBoost: i32  // BOOL
    ) -> 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 SetThreadPriorityBoost(IntPtr hThread, bool bDisablePriorityBoost);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetThreadPriorityBoost' -Namespace Win32 -PassThru
# $api::SetThreadPriorityBoost(hThread, bDisablePriorityBoost)
#uselib "KERNEL32.dll"
#func global SetThreadPriorityBoost "SetThreadPriorityBoost" sptr, sptr
; SetThreadPriorityBoost hThread, bDisablePriorityBoost   ; 戻り値は stat
; hThread : HANDLE -> "sptr"
; bDisablePriorityBoost : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetThreadPriorityBoost "SetThreadPriorityBoost" sptr, int
; res = SetThreadPriorityBoost(hThread, bDisablePriorityBoost)
; hThread : HANDLE -> "sptr"
; bDisablePriorityBoost : BOOL -> "int"
; BOOL SetThreadPriorityBoost(HANDLE hThread, BOOL bDisablePriorityBoost)
#uselib "KERNEL32.dll"
#cfunc global SetThreadPriorityBoost "SetThreadPriorityBoost" intptr, int
; res = SetThreadPriorityBoost(hThread, bDisablePriorityBoost)
; hThread : HANDLE -> "intptr"
; bDisablePriorityBoost : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetThreadPriorityBoost = kernel32.NewProc("SetThreadPriorityBoost")
)

// hThread (HANDLE), bDisablePriorityBoost (BOOL)
r1, _, err := procSetThreadPriorityBoost.Call(
	uintptr(hThread),
	uintptr(bDisablePriorityBoost),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetThreadPriorityBoost(
  hThread: THandle;   // HANDLE
  bDisablePriorityBoost: BOOL   // BOOL
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetThreadPriorityBoost';
result := DllCall("KERNEL32\SetThreadPriorityBoost"
    , "Ptr", hThread   ; HANDLE
    , "Int", bDisablePriorityBoost   ; BOOL
    , "Int")   ; return: BOOL
●SetThreadPriorityBoost(hThread, bDisablePriorityBoost) = DLL("KERNEL32.dll", "bool SetThreadPriorityBoost(void*, bool)")
# 呼び出し: SetThreadPriorityBoost(hThread, bDisablePriorityBoost)
# hThread : HANDLE -> "void*"
# bDisablePriorityBoost : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。