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

AvSetMmThreadPriority

関数
マルチメディアスレッドの優先度を設定する。
DLLAVRT.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL AvSetMmThreadPriority(
    AVRT_TASK_HANDLE AvrtHandle,
    AVRT_PRIORITY Priority
);

パラメーター

名前方向説明
AvrtHandleAVRT_TASK_HANDLEinタスクへのハンドル。このハンドルは AvSetMmThreadCharacteristics 関数または AvSetMmMaxThreadCharacteristics 関数によって返されます。
PriorityAVRT_PRIORITYin

類似のタスクを実行している他のスレッドに対する、このスレッドの相対的なスレッド優先度。このパラメーターには次のいずれかの値を指定できます。

AVRT_PRIORITY_CRITICAL (2)

AVRT_PRIORITY_HIGH (1)

AVRT_PRIORITY_LOW (-1)

AVRT_PRIORITY_NORMAL (0)

戻り値の型: BOOL

公式ドキュメント

呼び出し元スレッドのスレッド優先度を、同じタスクを実行している他のスレッドに対して相対的に調整します。

戻り値

関数が成功すると、戻り値は 0 以外の値になります。

関数が失敗すると、戻り値は 0 になります。詳細なエラー情報を取得するには、 GetLastError を呼び出します。

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

各言語での呼び出し定義

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

BOOL AvSetMmThreadPriority(
    AVRT_TASK_HANDLE AvrtHandle,
    AVRT_PRIORITY Priority
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("AVRT.dll", SetLastError = true, ExactSpelling = true)]
static extern bool AvSetMmThreadPriority(
    AVRT_TASK_HANDLE AvrtHandle,   // AVRT_TASK_HANDLE
    int Priority   // AVRT_PRIORITY
);
<DllImport("AVRT.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function AvSetMmThreadPriority(
    AvrtHandle As AVRT_TASK_HANDLE,   ' AVRT_TASK_HANDLE
    Priority As Integer   ' AVRT_PRIORITY
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' AvrtHandle : AVRT_TASK_HANDLE
' Priority : AVRT_PRIORITY
Declare PtrSafe Function AvSetMmThreadPriority Lib "avrt" ( _
    ByVal AvrtHandle As LongPtr, _
    ByVal Priority As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

AvSetMmThreadPriority = ctypes.windll.avrt.AvSetMmThreadPriority
AvSetMmThreadPriority.restype = wintypes.BOOL
AvSetMmThreadPriority.argtypes = [
    AVRT_TASK_HANDLE,  # AvrtHandle : AVRT_TASK_HANDLE
    ctypes.c_int,  # Priority : AVRT_PRIORITY
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('AVRT.dll')
AvSetMmThreadPriority = Fiddle::Function.new(
  lib['AvSetMmThreadPriority'],
  [
    Fiddle::TYPE_VOIDP,  # AvrtHandle : AVRT_TASK_HANDLE
    Fiddle::TYPE_INT,  # Priority : AVRT_PRIORITY
  ],
  Fiddle::TYPE_INT)
#[link(name = "avrt")]
extern "system" {
    fn AvSetMmThreadPriority(
        AvrtHandle: AVRT_TASK_HANDLE,  // AVRT_TASK_HANDLE
        Priority: i32  // AVRT_PRIORITY
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("AVRT.dll", SetLastError = true)]
public static extern bool AvSetMmThreadPriority(AVRT_TASK_HANDLE AvrtHandle, int Priority);
"@
$api = Add-Type -MemberDefinition $sig -Name 'AVRT_AvSetMmThreadPriority' -Namespace Win32 -PassThru
# $api::AvSetMmThreadPriority(AvrtHandle, Priority)
#uselib "AVRT.dll"
#func global AvSetMmThreadPriority "AvSetMmThreadPriority" sptr, sptr
; AvSetMmThreadPriority AvrtHandle, Priority   ; 戻り値は stat
; AvrtHandle : AVRT_TASK_HANDLE -> "sptr"
; Priority : AVRT_PRIORITY -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "AVRT.dll"
#cfunc global AvSetMmThreadPriority "AvSetMmThreadPriority" int, int
; res = AvSetMmThreadPriority(AvrtHandle, Priority)
; AvrtHandle : AVRT_TASK_HANDLE -> "int"
; Priority : AVRT_PRIORITY -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; BOOL AvSetMmThreadPriority(AVRT_TASK_HANDLE AvrtHandle, AVRT_PRIORITY Priority)
#uselib "AVRT.dll"
#cfunc global AvSetMmThreadPriority "AvSetMmThreadPriority" int, int
; res = AvSetMmThreadPriority(AvrtHandle, Priority)
; AvrtHandle : AVRT_TASK_HANDLE -> "int"
; Priority : AVRT_PRIORITY -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	avrt = windows.NewLazySystemDLL("AVRT.dll")
	procAvSetMmThreadPriority = avrt.NewProc("AvSetMmThreadPriority")
)

// AvrtHandle (AVRT_TASK_HANDLE), Priority (AVRT_PRIORITY)
r1, _, err := procAvSetMmThreadPriority.Call(
	uintptr(AvrtHandle),
	uintptr(Priority),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function AvSetMmThreadPriority(
  AvrtHandle: AVRT_TASK_HANDLE;   // AVRT_TASK_HANDLE
  Priority: Integer   // AVRT_PRIORITY
): BOOL; stdcall;
  external 'AVRT.dll' name 'AvSetMmThreadPriority';
result := DllCall("AVRT\AvSetMmThreadPriority"
    , "Ptr", AvrtHandle   ; AVRT_TASK_HANDLE
    , "Int", Priority   ; AVRT_PRIORITY
    , "Int")   ; return: BOOL
●AvSetMmThreadPriority(AvrtHandle, Priority) = DLL("AVRT.dll", "bool AvSetMmThreadPriority(void*, int)")
# 呼び出し: AvSetMmThreadPriority(AvrtHandle, Priority)
# AvrtHandle : AVRT_TASK_HANDLE -> "void*"
# Priority : AVRT_PRIORITY -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "avrt" fn AvSetMmThreadPriority(
    AvrtHandle: AVRT_TASK_HANDLE, // AVRT_TASK_HANDLE
    Priority: i32 // AVRT_PRIORITY
) callconv(std.os.windows.WINAPI) i32;
proc AvSetMmThreadPriority(
    AvrtHandle: AVRT_TASK_HANDLE,  # AVRT_TASK_HANDLE
    Priority: int32  # AVRT_PRIORITY
): int32 {.importc: "AvSetMmThreadPriority", stdcall, dynlib: "AVRT.dll".}
pragma(lib, "avrt");
extern(Windows)
int AvSetMmThreadPriority(
    AVRT_TASK_HANDLE AvrtHandle,   // AVRT_TASK_HANDLE
    int Priority   // AVRT_PRIORITY
);
ccall((:AvSetMmThreadPriority, "AVRT.dll"), stdcall, Int32,
      (AVRT_TASK_HANDLE, Int32),
      AvrtHandle, Priority)
# AvrtHandle : AVRT_TASK_HANDLE -> AVRT_TASK_HANDLE
# Priority : AVRT_PRIORITY -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t AvSetMmThreadPriority(
    AVRT_TASK_HANDLE AvrtHandle,
    int32_t Priority);
]]
local avrt = ffi.load("avrt")
-- avrt.AvSetMmThreadPriority(AvrtHandle, Priority)
-- AvrtHandle : AVRT_TASK_HANDLE
-- Priority : AVRT_PRIORITY
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('AVRT.dll');
const AvSetMmThreadPriority = lib.func('__stdcall', 'AvSetMmThreadPriority', 'int32_t', ['AVRT_TASK_HANDLE', 'int32_t']);
// AvSetMmThreadPriority(AvrtHandle, Priority)
// AvrtHandle : AVRT_TASK_HANDLE -> 'AVRT_TASK_HANDLE'
// Priority : AVRT_PRIORITY -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("AVRT.dll", {
  AvSetMmThreadPriority: { parameters: ["buffer", "i32"], result: "i32" },
});
// lib.symbols.AvSetMmThreadPriority(AvrtHandle, Priority)
// AvrtHandle : AVRT_TASK_HANDLE -> "buffer"
// Priority : AVRT_PRIORITY -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t AvSetMmThreadPriority(
    AVRT_TASK_HANDLE AvrtHandle,
    int32_t Priority);
C, "AVRT.dll");
// $ffi->AvSetMmThreadPriority(AvrtHandle, Priority);
// AvrtHandle : AVRT_TASK_HANDLE
// Priority : AVRT_PRIORITY
// 構造体/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 Avrt extends StdCallLibrary {
    Avrt INSTANCE = Native.load("avrt", Avrt.class);
    boolean AvSetMmThreadPriority(
        AVRT_TASK_HANDLE /* extends Structure (by value) */ AvrtHandle,   // AVRT_TASK_HANDLE
        int Priority   // AVRT_PRIORITY
    );
}
@[Link("avrt")]
lib LibAVRT
  fun AvSetMmThreadPriority = AvSetMmThreadPriority(
    AvrtHandle : AVRT_TASK_HANDLE,   # AVRT_TASK_HANDLE
    Priority : Int32   # AVRT_PRIORITY
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef AvSetMmThreadPriorityNative = Int32 Function(AVRT_TASK_HANDLE, Int32);
typedef AvSetMmThreadPriorityDart = int Function(int, int);
final AvSetMmThreadPriority = DynamicLibrary.open('AVRT.dll')
    .lookupFunction<AvSetMmThreadPriorityNative, AvSetMmThreadPriorityDart>('AvSetMmThreadPriority');
// AvrtHandle : AVRT_TASK_HANDLE -> AVRT_TASK_HANDLE
// Priority : AVRT_PRIORITY -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function AvSetMmThreadPriority(
  AvrtHandle: AVRT_TASK_HANDLE;   // AVRT_TASK_HANDLE
  Priority: Integer   // AVRT_PRIORITY
): BOOL; stdcall;
  external 'AVRT.dll' name 'AvSetMmThreadPriority';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "AvSetMmThreadPriority"
  c_AvSetMmThreadPriority :: AVRT_TASK_HANDLE -> Int32 -> IO CInt
-- AvrtHandle : AVRT_TASK_HANDLE -> AVRT_TASK_HANDLE
-- Priority : AVRT_PRIORITY -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。
open Ctypes
open Foreign

let avsetmmthreadpriority =
  foreign "AvSetMmThreadPriority"
    (AVRT_TASK_HANDLE @-> int32_t @-> returning int32_t)
(* AvrtHandle : AVRT_TASK_HANDLE -> AVRT_TASK_HANDLE *)
(* Priority : AVRT_PRIORITY -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library avrt (t "AVRT.dll"))
(cffi:use-foreign-library avrt)

(cffi:defcfun ("AvSetMmThreadPriority" av-set-mm-thread-priority :convention :stdcall) :int32
  (avrt-handle (:struct avrt-task-handle))   ; AVRT_TASK_HANDLE
  (priority :int32))   ; AVRT_PRIORITY
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $AvSetMmThreadPriority = Win32::API::More->new('AVRT',
    'BOOL AvSetMmThreadPriority(LPVOID AvrtHandle, int Priority)');
# my $ret = $AvSetMmThreadPriority->Call($AvrtHandle, $Priority);
# AvrtHandle : AVRT_TASK_HANDLE -> LPVOID
# Priority : AVRT_PRIORITY -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型