MsgWaitForMultipleObjectsEx  2JE4P4X 

[New - Windows NT]

The MsgWaitForMultipleObjectsEx function returns when one of the following occurs:

    Either any one or all of the specified objects are in the signaled state. The array of objects can include input event objects, which you specify using the dwWakeMask parameter.

    An I/O completion routine or asynchronous procedure call (APC) is queued to the thread.

    The time-out interval elapses.

 

The MsgWaitForMultipleObjectsEx function does not return if there is unread input of the specified type in the queue. It returns only when new input arrives.

DWORD MsgWaitForMultipleObjectsEx(

    DWORD nCount,

// number of handles in handle array

    LPHANDLE pHandles,

// pointer to an object-handle array

    DWORD dwMilliseconds,

// time-out interval in milliseconds

    DWORD dwWakeMask,

// type of input events to wait for

    DWORD dwFlags

// wait flags

   );

 

 

Parameters

nCount

Specifies the number of object handles in the array pointed to by pHandles. The maximum number of object handles is MAXIMUM_WAIT_OBJECTS minus one.

pHandles

Points to an array of object handles. For a list of the object types whose handles you can specify, see the Remarks section later in this topic. The array can contain handles to multiple types of objects.

Windows NT: The handles must have SYNCHRONIZE access.

dwMilliseconds

Specifies the time-out interval, in milliseconds. The function returns if the interval elapses, even if the conditions specified by the dwWakeMask and dwFlags parameters are not met. If dwMilliseconds is zero, the function tests the states of the specified objects and returns immediately. If dwMilliseconds is INFINITE, the function's time-out interval never elapses.

dwWakeMask

Specifies input types for which an input event object handle will be added to the array of object handles. This parameter can be any combination of the following values:

Value

Meaning

QS_ALLINPUT

Any message is in the queue.

QS_HOTKEY

A WM_HOTKEYUQH9UB message is in the queue.

QS_INPUT

An input message is in the queue.

QS_KEY

A WM_KEYUP1UBR_9N, WM_KEYDOWNCXJO_P, WM_SYSKEYUP7A010RJ, or WM_SYSKEYDOWN7.WA3P message is in the queue.

QS_MOUSE

A WM_MOUSEMOVE1MQ_IQ2 message or mouse-button message (WM_LBUTTONUPYL9YEK, WM_RBUTTONDOWN0T6FUI, and so on) is in the queue.

QS_MOUSEBUTTON

A mouse-button message (WM_LBUTTONUPYL9YEK, WM_RBUTTONDOWN0T6FUI, and so on) is in the queue.

QS_MOUSEMOVE

A WM_MOUSEMOVE1MQ_IQ2 message is in the queue.

QS_PAINT

A WM_PAINTF55XZ2 message is in the queue.

QS_POSTMESSAGE

A posted message (other than those just listed) is in the queue.

QS_SENDMESSAGE

A message sent by another thread or application is in the queue.

QS_TIMER

A WM_TIMER303BZXE message is in the queue.

 

dwFlags

Specifies the wait type. This parameter can be any combination of the following values:

Value

Meaning

0

The function returns when any one of the objects is signaled. The return value indicates the object whose state caused the function to return.

MWMO_WAITALL

The function returns when all objects in the pHandles array are signaled at the same time.

MWMO_ALERTABLE

The function also returns if an APC has been queued to the thread with QueueUserAPCKJA6PW.

 

Return Values

If the function succeeds, the return value indicates the event that caused the function to return. The successful return value is one of the following:

Value

Meaning

WAIT_OBJECT_0 to
 (WAIT_OBJECT_0 + nCount - 1)

If the MWMO_WAITALL flag is used, the return value indicates that the state of all specified objects is signaled. Otherwise, the return value minus WAIT_OBJECT_0 indicates the pHandles array index of the object that caused the function to return.

WAIT_OBJECT_0 + nCount

Input of the type specified in the dwWakeMask parameter is available in the thread's input queue.

WAIT_ABANDONED_0 to
(WAIT_ABANDONED_0 + nCount - 1)

If the MWMO_WAITALL flag is used, the return value indicates that the state of all specified objects is signaled and at least one of the objects is an abandoned mutex object. Otherwise, the return value minus WAIT_ABANDONED_0 indicates the pHandles array index of an abandoned mutex object that caused the function to return.

WAIT_IO_COMPLETION

The wait was ended by a user-mode asynchronous procedure call (APC) queued to the thread.

WAIT_TIMEOUT

The time-out interval elapsed, but the conditions specified by the dwFlags and dwWakeMask parameters were not met.

 

If the function fails, the return value is 0xFFFFFFFF. To get extended error information, call GetLastError11C2VS7.

Remarks

The MsgWaitForMultipleObjectsEx function determines whether the conditions specified by dwWakeMask and dwFlags have been met. If the conditions have not been met, the calling thread enters an efficient wait state. The thread uses very little processor time while waiting for one of the conditions to be met or for the time-out interval to elapse.

Before returning, a wait function modifies the state of some types of synchronization objects. Modification occurs only for the object or objects whose signaled state caused the function to return. For example, the system decreases the count of a semaphore object by one.

The MsgWaitForMultipleObjectsEx function can specify handles of any of the following object types in the pHandles array:

Object

Description

Change notification

The FindFirstChangeNotificationPU4_HM function returns the handle. The state of a change notification object is set to signaled when a specified change occurs within a specified directory or directory tree.

Console input

The CreateFileXN35YD function returns the handle when the CONIN$ value is specified, or the GetStdHandle1B8L_FR function returns the handle. The state of the object is set to signaled when there is unread input in the console's input buffer and nonsignaled when the input buffer is empty.

Event

The CreateEventJ_ZBJV or OpenEventQTG5JZ function returns the handle. The state of an event object is set explicitly to signaled by the SetEventAT02D. or PulseEvent7D.L0ZU function. The state of a manual-reset event object must be reset explicitly to nonsignaled by the ResetEvent1.IH1GV function. For an auto-reset event object, the wait function resets the object state to nonsignaled before returning. Event objects are also used in overlapped operations, in which the state is set by the system.

Mutex

The CreateMutexJEYQAZ or OpenMutex4S0DUN function returns the handle. The state of a mutex object is signaled when it is not owned by any thread. The wait function requests ownership of the mutex for the calling thread, changing the mutex state to nonsignaled when ownership is granted.

Process

The CreateProcess5FBJ_XX or OpenProcess9MLGUT function returns the handle. The state of a process object is set to signaled when the process terminates.

Semaphore

The CreateSemaphore41RE8TU or OpenSemaphoreB3N75Z function returns the handle. A semaphore object maintains a count between zero and the maximum count specified during its creation. Its state is set to signaled when its count is greater than zero and nonsignaled when its count is zero. If the current state of the semaphore is signaled, the wait function decreases the count by one.

Thread

The CreateProcess5FBJ_XX, CreateThread70TS0Y, or CreateRemoteThread19IU6KT function returns the handle. The state of a thread object is set to signaled when the thread terminates.

Timer

The CreateWaitableTimer12BP5E6 or OpenWaitableTimer2Z5SBU function returns the handle. Activate the timer by calling the SetWaitableTimerC26JBN function. The state of an active timer is set to signaled when it reaches its due time. You can deactivate the timer by calling the CancelWaitableTimerW6GYXD function.

 

In some circumstances, you can specify a handle of a file, named pipe, or communications device as a synchronization object in lpHandles. However, their use for this purpose is discouraged.

See Also

CancelWaitableTimer, CreateEvent, CreateFile, CreateMutex, CreateProcess, CreateRemoteThread, CreateSemaphore, CreateThread, CreateWaitableTimer, FindFirstChangeNotification, GetStdHandle, MsgWaitForMultipleObjects, OpenEvent, OpenMutex, OpenProcess, OpenSemaphore, OpenWaitableTimer, PulseEvent, QueueUserAPC, ResetEvent, SetEvent, SetWaitableTimer