Win32 API 日本語リファレンス
ホームUI.WindowsAndMessaging › MsgWaitForMultipleObjectsEx

MsgWaitForMultipleObjectsEx

関数
拡張フラグ付きで待機とメッセージ到着を待つ。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

WAIT_EVENT MsgWaitForMultipleObjectsEx(
    DWORD nCount,
    const HANDLE* pHandles,   // optional
    DWORD dwMilliseconds,
    QUEUE_STATUS_FLAGS dwWakeMask,
    MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS dwFlags
);

パラメーター

名前方向
nCountDWORDin
pHandlesHANDLE*inoptional
dwMillisecondsDWORDin
dwWakeMaskQUEUE_STATUS_FLAGSin
dwFlagsMSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGSin

戻り値の型: WAIT_EVENT

各言語での呼び出し定義

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

WAIT_EVENT MsgWaitForMultipleObjectsEx(
    DWORD nCount,
    const HANDLE* pHandles,   // optional
    DWORD dwMilliseconds,
    QUEUE_STATUS_FLAGS dwWakeMask,
    MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS dwFlags
);
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern uint MsgWaitForMultipleObjectsEx(
    uint nCount,   // DWORD
    IntPtr pHandles,   // HANDLE* optional
    uint dwMilliseconds,   // DWORD
    uint dwWakeMask,   // QUEUE_STATUS_FLAGS
    uint dwFlags   // MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function MsgWaitForMultipleObjectsEx(
    nCount As UInteger,   ' DWORD
    pHandles As IntPtr,   ' HANDLE* optional
    dwMilliseconds As UInteger,   ' DWORD
    dwWakeMask As UInteger,   ' QUEUE_STATUS_FLAGS
    dwFlags As UInteger   ' MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS
) As UInteger
End Function
' nCount : DWORD
' pHandles : HANDLE* optional
' dwMilliseconds : DWORD
' dwWakeMask : QUEUE_STATUS_FLAGS
' dwFlags : MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS
Declare PtrSafe Function MsgWaitForMultipleObjectsEx Lib "user32" ( _
    ByVal nCount As Long, _
    ByVal pHandles As LongPtr, _
    ByVal dwMilliseconds As Long, _
    ByVal dwWakeMask As Long, _
    ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MsgWaitForMultipleObjectsEx = ctypes.windll.user32.MsgWaitForMultipleObjectsEx
MsgWaitForMultipleObjectsEx.restype = wintypes.DWORD
MsgWaitForMultipleObjectsEx.argtypes = [
    wintypes.DWORD,  # nCount : DWORD
    ctypes.c_void_p,  # pHandles : HANDLE* optional
    wintypes.DWORD,  # dwMilliseconds : DWORD
    wintypes.DWORD,  # dwWakeMask : QUEUE_STATUS_FLAGS
    wintypes.DWORD,  # dwFlags : MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
MsgWaitForMultipleObjectsEx = Fiddle::Function.new(
  lib['MsgWaitForMultipleObjectsEx'],
  [
    -Fiddle::TYPE_INT,  # nCount : DWORD
    Fiddle::TYPE_VOIDP,  # pHandles : HANDLE* optional
    -Fiddle::TYPE_INT,  # dwMilliseconds : DWORD
    -Fiddle::TYPE_INT,  # dwWakeMask : QUEUE_STATUS_FLAGS
    -Fiddle::TYPE_INT,  # dwFlags : MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS
  ],
  -Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn MsgWaitForMultipleObjectsEx(
        nCount: u32,  // DWORD
        pHandles: *mut *mut core::ffi::c_void,  // HANDLE* optional
        dwMilliseconds: u32,  // DWORD
        dwWakeMask: u32,  // QUEUE_STATUS_FLAGS
        dwFlags: u32  // MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", SetLastError = true)]
public static extern uint MsgWaitForMultipleObjectsEx(uint nCount, IntPtr pHandles, uint dwMilliseconds, uint dwWakeMask, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_MsgWaitForMultipleObjectsEx' -Namespace Win32 -PassThru
# $api::MsgWaitForMultipleObjectsEx(nCount, pHandles, dwMilliseconds, dwWakeMask, dwFlags)
#uselib "USER32.dll"
#func global MsgWaitForMultipleObjectsEx "MsgWaitForMultipleObjectsEx" sptr, sptr, sptr, sptr, sptr
; MsgWaitForMultipleObjectsEx nCount, pHandles, dwMilliseconds, dwWakeMask, dwFlags   ; 戻り値は stat
; nCount : DWORD -> "sptr"
; pHandles : HANDLE* optional -> "sptr"
; dwMilliseconds : DWORD -> "sptr"
; dwWakeMask : QUEUE_STATUS_FLAGS -> "sptr"
; dwFlags : MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global MsgWaitForMultipleObjectsEx "MsgWaitForMultipleObjectsEx" int, sptr, int, int, int
; res = MsgWaitForMultipleObjectsEx(nCount, pHandles, dwMilliseconds, dwWakeMask, dwFlags)
; nCount : DWORD -> "int"
; pHandles : HANDLE* optional -> "sptr"
; dwMilliseconds : DWORD -> "int"
; dwWakeMask : QUEUE_STATUS_FLAGS -> "int"
; dwFlags : MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS -> "int"
; WAIT_EVENT MsgWaitForMultipleObjectsEx(DWORD nCount, HANDLE* pHandles, DWORD dwMilliseconds, QUEUE_STATUS_FLAGS dwWakeMask, MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS dwFlags)
#uselib "USER32.dll"
#cfunc global MsgWaitForMultipleObjectsEx "MsgWaitForMultipleObjectsEx" int, intptr, int, int, int
; res = MsgWaitForMultipleObjectsEx(nCount, pHandles, dwMilliseconds, dwWakeMask, dwFlags)
; nCount : DWORD -> "int"
; pHandles : HANDLE* optional -> "intptr"
; dwMilliseconds : DWORD -> "int"
; dwWakeMask : QUEUE_STATUS_FLAGS -> "int"
; dwFlags : MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procMsgWaitForMultipleObjectsEx = user32.NewProc("MsgWaitForMultipleObjectsEx")
)

// nCount (DWORD), pHandles (HANDLE* optional), dwMilliseconds (DWORD), dwWakeMask (QUEUE_STATUS_FLAGS), dwFlags (MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS)
r1, _, err := procMsgWaitForMultipleObjectsEx.Call(
	uintptr(nCount),
	uintptr(pHandles),
	uintptr(dwMilliseconds),
	uintptr(dwWakeMask),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WAIT_EVENT
function MsgWaitForMultipleObjectsEx(
  nCount: DWORD;   // DWORD
  pHandles: Pointer;   // HANDLE* optional
  dwMilliseconds: DWORD;   // DWORD
  dwWakeMask: DWORD;   // QUEUE_STATUS_FLAGS
  dwFlags: DWORD   // MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS
): DWORD; stdcall;
  external 'USER32.dll' name 'MsgWaitForMultipleObjectsEx';
result := DllCall("USER32\MsgWaitForMultipleObjectsEx"
    , "UInt", nCount   ; DWORD
    , "Ptr", pHandles   ; HANDLE* optional
    , "UInt", dwMilliseconds   ; DWORD
    , "UInt", dwWakeMask   ; QUEUE_STATUS_FLAGS
    , "UInt", dwFlags   ; MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS
    , "UInt")   ; return: WAIT_EVENT
●MsgWaitForMultipleObjectsEx(nCount, pHandles, dwMilliseconds, dwWakeMask, dwFlags) = DLL("USER32.dll", "dword MsgWaitForMultipleObjectsEx(dword, void*, dword, dword, dword)")
# 呼び出し: MsgWaitForMultipleObjectsEx(nCount, pHandles, dwMilliseconds, dwWakeMask, dwFlags)
# nCount : DWORD -> "dword"
# pHandles : HANDLE* optional -> "void*"
# dwMilliseconds : DWORD -> "dword"
# dwWakeMask : QUEUE_STATUS_FLAGS -> "dword"
# dwFlags : MSG_WAIT_FOR_MULTIPLE_OBJECTS_EX_FLAGS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。