CoWaitForMultipleHandles function (combaseapi.h)

Waits for specified handles to be signaled or for a specified timeout period to elapse.

Syntax

HRESULT CoWaitForMultipleHandles(
  [in]  DWORD    dwFlags,
  [in]  DWORD    dwTimeout,
  [in]  ULONG    cHandles,
  [in]  LPHANDLE pHandles,
  [out] LPDWORD  lpdwindex
);

Parameters

[in] dwFlags

The wait options. Possible values are taken from the COWAIT_FLAGS enumeration.

[in] dwTimeout

The timeout period, in milliseconds.

[in] cHandles

The number of elements in the pHandles array.

[in] pHandles

An array of handles.

[out] lpdwindex

A pointer to a variable that, when the returned status is S_OK, receives a value indicating the event that caused the function to return. This value is usually the index into pHandles for the handle that was signaled.

If pHandles includes one or more handles to mutex objects, a value between WAIT_ABANDONED_0 and (WAIT_ABANDONED_0 + nCount - 1) indicates the index into pHandles for the mutex that was abandoned.

If the COWAIT_ALERTABLE flag is set in dwFlags, a value of WAIT_IO_COMPLETION indicates the wait was ended by one or more user-mode asynchronous procedure calls (APC) queued to the thread.

See WaitForMultipleObjectsEx for more information.

Return value

This function can return the following values.

Note  The return value of CoWaitForMultipleHandles can be nondeterministic if the COWAIT_ALERTABLE flag is set in dwFlags, or if pHandles includes one or more handles to mutex objects. The recommended workaround is to call SetLastError(ERROR_SUCCESS) before CoWaitForMultipleHandles.
 
Return code Description
S_OK
The required handle or handles were signaled.
E_INVALIDARG
pHandles was NULL, lpdwindex was NULL, or dwFlags was not a value from the COWAIT_FLAGS enumeration.
RPC_E_NO_SYNC
The value of pHandles was 0.
RPC_S_CALLPENDING
The timeout period elapsed before the required handle or handles were signaled.

Remarks

Depending on which flags are set in the dwFlags parameter, CoWaitForMultipleHandles blocks the calling thread until one of the following events occurs:

  • One or all of the handles is signaled. In the case of mutex objects, this condition is also satisfied by a mutex being abandoned.
  • An asynchronous procedure call (APC) has been queued to the calling thread with a call to the QueueUserAPC function.
  • The timeout period expires.
If the caller resides in a single-thread apartment, CoWaitForMultipleHandles enters the COM modal loop, and the thread's message loop will continue to dispatch messages using the thread's message filter. If no message filter is registered for the thread, the default COM message processing is used.

If the calling thread resides in a multithread apartment (MTA), CoWaitForMultipleHandles calls the WaitForMultipleObjectsEx function.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header combaseapi.h (include Objbase.h)
Library Ole32.lib
DLL Ole32.dll

See also

COWAIT_FLAGS