ホーム › System.Threading › SetThreadPriority
SetThreadPriority
関数スレッドの優先度レベルを設定する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL SetThreadPriority(
HANDLE hThread,
THREAD_PRIORITY nPriority
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hThread | HANDLE | in |
| nPriority | THREAD_PRIORITY | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL SetThreadPriority(
HANDLE hThread,
THREAD_PRIORITY nPriority
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetThreadPriority(
IntPtr hThread, // HANDLE
int nPriority // THREAD_PRIORITY
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetThreadPriority(
hThread As IntPtr, ' HANDLE
nPriority As Integer ' THREAD_PRIORITY
) As Boolean
End Function' hThread : HANDLE
' nPriority : THREAD_PRIORITY
Declare PtrSafe Function SetThreadPriority Lib "kernel32" ( _
ByVal hThread As LongPtr, _
ByVal nPriority As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetThreadPriority = ctypes.windll.kernel32.SetThreadPriority
SetThreadPriority.restype = wintypes.BOOL
SetThreadPriority.argtypes = [
wintypes.HANDLE, # hThread : HANDLE
ctypes.c_int, # nPriority : THREAD_PRIORITY
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
SetThreadPriority = Fiddle::Function.new(
lib['SetThreadPriority'],
[
Fiddle::TYPE_VOIDP, # hThread : HANDLE
Fiddle::TYPE_INT, # nPriority : THREAD_PRIORITY
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn SetThreadPriority(
hThread: *mut core::ffi::c_void, // HANDLE
nPriority: i32 // THREAD_PRIORITY
) -> 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 SetThreadPriority(IntPtr hThread, int nPriority);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetThreadPriority' -Namespace Win32 -PassThru
# $api::SetThreadPriority(hThread, nPriority)#uselib "KERNEL32.dll"
#func global SetThreadPriority "SetThreadPriority" sptr, sptr
; SetThreadPriority hThread, nPriority ; 戻り値は stat
; hThread : HANDLE -> "sptr"
; nPriority : THREAD_PRIORITY -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global SetThreadPriority "SetThreadPriority" sptr, int
; res = SetThreadPriority(hThread, nPriority)
; hThread : HANDLE -> "sptr"
; nPriority : THREAD_PRIORITY -> "int"; BOOL SetThreadPriority(HANDLE hThread, THREAD_PRIORITY nPriority)
#uselib "KERNEL32.dll"
#cfunc global SetThreadPriority "SetThreadPriority" intptr, int
; res = SetThreadPriority(hThread, nPriority)
; hThread : HANDLE -> "intptr"
; nPriority : THREAD_PRIORITY -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetThreadPriority = kernel32.NewProc("SetThreadPriority")
)
// hThread (HANDLE), nPriority (THREAD_PRIORITY)
r1, _, err := procSetThreadPriority.Call(
uintptr(hThread),
uintptr(nPriority),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetThreadPriority(
hThread: THandle; // HANDLE
nPriority: Integer // THREAD_PRIORITY
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetThreadPriority';result := DllCall("KERNEL32\SetThreadPriority"
, "Ptr", hThread ; HANDLE
, "Int", nPriority ; THREAD_PRIORITY
, "Int") ; return: BOOL●SetThreadPriority(hThread, nPriority) = DLL("KERNEL32.dll", "bool SetThreadPriority(void*, int)")
# 呼び出し: SetThreadPriority(hThread, nPriority)
# hThread : HANDLE -> "void*"
# nPriority : THREAD_PRIORITY -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。