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

WaitForMultipleObjects

関数
複数オブジェクトのいずれかまたは全部のシグナルを待機する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

WAIT_EVENT WaitForMultipleObjects(
    DWORD nCount,
    const HANDLE* lpHandles,
    BOOL bWaitAll,
    DWORD dwMilliseconds
);

パラメーター

名前方向
nCountDWORDin
lpHandlesHANDLE*in
bWaitAllBOOLin
dwMillisecondsDWORDin

戻り値の型: WAIT_EVENT

各言語での呼び出し定義

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

WAIT_EVENT WaitForMultipleObjects(
    DWORD nCount,
    const HANDLE* lpHandles,
    BOOL bWaitAll,
    DWORD dwMilliseconds
);
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern uint WaitForMultipleObjects(
    uint nCount,   // DWORD
    IntPtr lpHandles,   // HANDLE*
    bool bWaitAll,   // BOOL
    uint dwMilliseconds   // DWORD
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WaitForMultipleObjects(
    nCount As UInteger,   ' DWORD
    lpHandles As IntPtr,   ' HANDLE*
    bWaitAll As Boolean,   ' BOOL
    dwMilliseconds As UInteger   ' DWORD
) As UInteger
End Function
' nCount : DWORD
' lpHandles : HANDLE*
' bWaitAll : BOOL
' dwMilliseconds : DWORD
Declare PtrSafe Function WaitForMultipleObjects Lib "kernel32" ( _
    ByVal nCount As Long, _
    ByVal lpHandles As LongPtr, _
    ByVal bWaitAll As Long, _
    ByVal dwMilliseconds As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WaitForMultipleObjects = ctypes.windll.kernel32.WaitForMultipleObjects
WaitForMultipleObjects.restype = wintypes.DWORD
WaitForMultipleObjects.argtypes = [
    wintypes.DWORD,  # nCount : DWORD
    ctypes.c_void_p,  # lpHandles : HANDLE*
    wintypes.BOOL,  # bWaitAll : BOOL
    wintypes.DWORD,  # dwMilliseconds : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procWaitForMultipleObjects = kernel32.NewProc("WaitForMultipleObjects")
)

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