Export (0) Print
Expand All
COM
Expand Minimize

CoWaitForMultipleHandles function

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

dwFlags [in]

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

dwTimeout [in]

The timeout period, in milliseconds.

cHandles [in]

The number of elements in the pHandles array.

pHandles [in]

An array of handles.

lpdwindex [out]

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 codeDescription
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.

The following flags are required when you call CoWaitForMultipleHandles within a Windows Store app: COWAIT_DISPATCH_CALLS | COWAIT_DISPATCH_WINDOW_MESSAGES. Without these flags, deadlocks may occur.

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

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Objbase.h

Library

Ole32.lib

DLL

Ole32.dll

See also

COWAIT_FLAGS

 

 

Community Additions

ADD
Show:
© 2014 Microsoft