ホーム › Media.MediaFoundation › MFAllocateSerialWorkQueue
MFAllocateSerialWorkQueue
関数既存キューに連動する直列処理作業キューを割り当てる。
シグネチャ
// MFPlat.dll
#include <windows.h>
HRESULT MFAllocateSerialWorkQueue(
DWORD dwWorkQueue,
DWORD* pdwWorkQueue
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| dwWorkQueue | DWORD | in | 既存のワークキューの識別子です。これはマルチスレッドキュー、または別のシリアルワークキューのいずれかである必要があります。次のいずれかを使用できます。
|
| pdwWorkQueue | DWORD* | out | 新しいシリアルワークキューの識別子を受け取ります。作業項目をキューに登録する際に、この識別子を使用します。 |
戻り値の型: HRESULT
公式ドキュメント
作業項目の直列化を保証するワークキューを作成します。
戻り値
この関数は次のいずれかの値を返します。
| 戻り値 | 説明 |
|---|---|
| 関数は成功しました。 | |
| アプリケーションがワークキューの最大数を超えました。 | |
| アプリケーションが MFStartup を呼び出していないか、または既に MFShutdown を呼び出しています。 |
解説(Remarks)
ワークキューの使用が終わったら、MFUnlockWorkQueue を呼び出してください。
マルチスレッドキューはスレッドプールを使用するため、パイプライン内のスレッドの総数を削減できます。ただし、作業項目を直列化することはありません。シリアルワークキューを使用すると、アプリケーションは自身の作業項目を手動で直列化する必要なく、スレッドプールの利点を得ることができます。
応答モード
シリアライザーキューは「応答」モードで動作することもできます。呼び出し元の IMFAsyncCallback::GetParameters メソッドが MFASYNC_REPLY_CALLBACK フラグを返す場合、シリアライザーキューは次の作業項目へ自動的に進みません。代わりに、キューは呼び出し元からの応答を待ちます。呼び出し元は、ワークキューが Invoke メソッドに渡す非同期結果オブジェクトを呼び出すことで、応答を通知します。次のコードは、呼び出し元がワークキューに通知する方法を示しています。HRESULT CCallback::Invoke(IMFAsyncResult *pResult)
{
DoSomeWork();
// Reply to the work queue that you are done.
MFInvokeCallback(pResult);
// Note: This call to MFInvokeCallback does not have to occur inside the
// Invoke method. You could call MFInvokeCallback at a later time.
return S_OK;
}
HRESULT CCallback::GetParameters(DWORD *pdwFlags, DWORD *pdwQueue)
{
*pdwFlags = MFASYNC_REPLY_CALLBACK;
*pdwQueue = m_QueueId;
return S_OK;
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// MFPlat.dll
#include <windows.h>
HRESULT MFAllocateSerialWorkQueue(
DWORD dwWorkQueue,
DWORD* pdwWorkQueue
);[DllImport("MFPlat.dll", ExactSpelling = true)]
static extern int MFAllocateSerialWorkQueue(
uint dwWorkQueue, // DWORD
out uint pdwWorkQueue // DWORD* out
);<DllImport("MFPlat.dll", ExactSpelling:=True)>
Public Shared Function MFAllocateSerialWorkQueue(
dwWorkQueue As UInteger, ' DWORD
<Out> ByRef pdwWorkQueue As UInteger ' DWORD* out
) As Integer
End Function' dwWorkQueue : DWORD
' pdwWorkQueue : DWORD* out
Declare PtrSafe Function MFAllocateSerialWorkQueue Lib "mfplat" ( _
ByVal dwWorkQueue As Long, _
ByRef pdwWorkQueue As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MFAllocateSerialWorkQueue = ctypes.windll.mfplat.MFAllocateSerialWorkQueue
MFAllocateSerialWorkQueue.restype = ctypes.c_int
MFAllocateSerialWorkQueue.argtypes = [
wintypes.DWORD, # dwWorkQueue : DWORD
ctypes.POINTER(wintypes.DWORD), # pdwWorkQueue : DWORD* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('MFPlat.dll')
MFAllocateSerialWorkQueue = Fiddle::Function.new(
lib['MFAllocateSerialWorkQueue'],
[
-Fiddle::TYPE_INT, # dwWorkQueue : DWORD
Fiddle::TYPE_VOIDP, # pdwWorkQueue : DWORD* out
],
Fiddle::TYPE_INT)#[link(name = "mfplat")]
extern "system" {
fn MFAllocateSerialWorkQueue(
dwWorkQueue: u32, // DWORD
pdwWorkQueue: *mut u32 // DWORD* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("MFPlat.dll")]
public static extern int MFAllocateSerialWorkQueue(uint dwWorkQueue, out uint pdwWorkQueue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MFPlat_MFAllocateSerialWorkQueue' -Namespace Win32 -PassThru
# $api::MFAllocateSerialWorkQueue(dwWorkQueue, pdwWorkQueue)#uselib "MFPlat.dll"
#func global MFAllocateSerialWorkQueue "MFAllocateSerialWorkQueue" sptr, sptr
; MFAllocateSerialWorkQueue dwWorkQueue, varptr(pdwWorkQueue) ; 戻り値は stat
; dwWorkQueue : DWORD -> "sptr"
; pdwWorkQueue : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "MFPlat.dll" #cfunc global MFAllocateSerialWorkQueue "MFAllocateSerialWorkQueue" int, var ; res = MFAllocateSerialWorkQueue(dwWorkQueue, pdwWorkQueue) ; dwWorkQueue : DWORD -> "int" ; pdwWorkQueue : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "MFPlat.dll" #cfunc global MFAllocateSerialWorkQueue "MFAllocateSerialWorkQueue" int, sptr ; res = MFAllocateSerialWorkQueue(dwWorkQueue, varptr(pdwWorkQueue)) ; dwWorkQueue : DWORD -> "int" ; pdwWorkQueue : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT MFAllocateSerialWorkQueue(DWORD dwWorkQueue, DWORD* pdwWorkQueue) #uselib "MFPlat.dll" #cfunc global MFAllocateSerialWorkQueue "MFAllocateSerialWorkQueue" int, var ; res = MFAllocateSerialWorkQueue(dwWorkQueue, pdwWorkQueue) ; dwWorkQueue : DWORD -> "int" ; pdwWorkQueue : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT MFAllocateSerialWorkQueue(DWORD dwWorkQueue, DWORD* pdwWorkQueue) #uselib "MFPlat.dll" #cfunc global MFAllocateSerialWorkQueue "MFAllocateSerialWorkQueue" int, intptr ; res = MFAllocateSerialWorkQueue(dwWorkQueue, varptr(pdwWorkQueue)) ; dwWorkQueue : DWORD -> "int" ; pdwWorkQueue : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mfplat = windows.NewLazySystemDLL("MFPlat.dll")
procMFAllocateSerialWorkQueue = mfplat.NewProc("MFAllocateSerialWorkQueue")
)
// dwWorkQueue (DWORD), pdwWorkQueue (DWORD* out)
r1, _, err := procMFAllocateSerialWorkQueue.Call(
uintptr(dwWorkQueue),
uintptr(pdwWorkQueue),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction MFAllocateSerialWorkQueue(
dwWorkQueue: DWORD; // DWORD
pdwWorkQueue: Pointer // DWORD* out
): Integer; stdcall;
external 'MFPlat.dll' name 'MFAllocateSerialWorkQueue';result := DllCall("MFPlat\MFAllocateSerialWorkQueue"
, "UInt", dwWorkQueue ; DWORD
, "Ptr", pdwWorkQueue ; DWORD* out
, "Int") ; return: HRESULT●MFAllocateSerialWorkQueue(dwWorkQueue, pdwWorkQueue) = DLL("MFPlat.dll", "int MFAllocateSerialWorkQueue(dword, void*)")
# 呼び出し: MFAllocateSerialWorkQueue(dwWorkQueue, pdwWorkQueue)
# dwWorkQueue : DWORD -> "dword"
# pdwWorkQueue : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mfplat" fn MFAllocateSerialWorkQueue(
dwWorkQueue: u32, // DWORD
pdwWorkQueue: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) i32;proc MFAllocateSerialWorkQueue(
dwWorkQueue: uint32, # DWORD
pdwWorkQueue: ptr uint32 # DWORD* out
): int32 {.importc: "MFAllocateSerialWorkQueue", stdcall, dynlib: "MFPlat.dll".}pragma(lib, "mfplat");
extern(Windows)
int MFAllocateSerialWorkQueue(
uint dwWorkQueue, // DWORD
uint* pdwWorkQueue // DWORD* out
);ccall((:MFAllocateSerialWorkQueue, "MFPlat.dll"), stdcall, Int32,
(UInt32, Ptr{UInt32}),
dwWorkQueue, pdwWorkQueue)
# dwWorkQueue : DWORD -> UInt32
# pdwWorkQueue : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t MFAllocateSerialWorkQueue(
uint32_t dwWorkQueue,
uint32_t* pdwWorkQueue);
]]
local mfplat = ffi.load("mfplat")
-- mfplat.MFAllocateSerialWorkQueue(dwWorkQueue, pdwWorkQueue)
-- dwWorkQueue : DWORD
-- pdwWorkQueue : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('MFPlat.dll');
const MFAllocateSerialWorkQueue = lib.func('__stdcall', 'MFAllocateSerialWorkQueue', 'int32_t', ['uint32_t', 'uint32_t *']);
// MFAllocateSerialWorkQueue(dwWorkQueue, pdwWorkQueue)
// dwWorkQueue : DWORD -> 'uint32_t'
// pdwWorkQueue : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("MFPlat.dll", {
MFAllocateSerialWorkQueue: { parameters: ["u32", "pointer"], result: "i32" },
});
// lib.symbols.MFAllocateSerialWorkQueue(dwWorkQueue, pdwWorkQueue)
// dwWorkQueue : DWORD -> "u32"
// pdwWorkQueue : DWORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t MFAllocateSerialWorkQueue(
uint32_t dwWorkQueue,
uint32_t* pdwWorkQueue);
C, "MFPlat.dll");
// $ffi->MFAllocateSerialWorkQueue(dwWorkQueue, pdwWorkQueue);
// dwWorkQueue : DWORD
// pdwWorkQueue : DWORD* 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 Mfplat extends StdCallLibrary {
Mfplat INSTANCE = Native.load("mfplat", Mfplat.class);
int MFAllocateSerialWorkQueue(
int dwWorkQueue, // DWORD
IntByReference pdwWorkQueue // DWORD* out
);
}@[Link("mfplat")]
lib LibMFPlat
fun MFAllocateSerialWorkQueue = MFAllocateSerialWorkQueue(
dwWorkQueue : UInt32, # DWORD
pdwWorkQueue : UInt32* # DWORD* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MFAllocateSerialWorkQueueNative = Int32 Function(Uint32, Pointer<Uint32>);
typedef MFAllocateSerialWorkQueueDart = int Function(int, Pointer<Uint32>);
final MFAllocateSerialWorkQueue = DynamicLibrary.open('MFPlat.dll')
.lookupFunction<MFAllocateSerialWorkQueueNative, MFAllocateSerialWorkQueueDart>('MFAllocateSerialWorkQueue');
// dwWorkQueue : DWORD -> Uint32
// pdwWorkQueue : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MFAllocateSerialWorkQueue(
dwWorkQueue: DWORD; // DWORD
pdwWorkQueue: Pointer // DWORD* out
): Integer; stdcall;
external 'MFPlat.dll' name 'MFAllocateSerialWorkQueue';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MFAllocateSerialWorkQueue"
c_MFAllocateSerialWorkQueue :: Word32 -> Ptr Word32 -> IO Int32
-- dwWorkQueue : DWORD -> Word32
-- pdwWorkQueue : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let mfallocateserialworkqueue =
foreign "MFAllocateSerialWorkQueue"
(uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* dwWorkQueue : DWORD -> uint32_t *)
(* pdwWorkQueue : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mfplat (t "MFPlat.dll"))
(cffi:use-foreign-library mfplat)
(cffi:defcfun ("MFAllocateSerialWorkQueue" mfallocate-serial-work-queue :convention :stdcall) :int32
(dw-work-queue :uint32) ; DWORD
(pdw-work-queue :pointer)) ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MFAllocateSerialWorkQueue = Win32::API::More->new('MFPlat',
'int MFAllocateSerialWorkQueue(DWORD dwWorkQueue, LPVOID pdwWorkQueue)');
# my $ret = $MFAllocateSerialWorkQueue->Call($dwWorkQueue, $pdwWorkQueue);
# dwWorkQueue : DWORD -> DWORD
# pdwWorkQueue : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。