using System;
using System.Runtime.InteropServices;
namespace ZB.MOM.WW.MxGateway.Worker.Sta;
///
/// The single declaration of the Win32 wait the worker's STA is built on.
/// Both waiters use it: for the runtime's outer
/// idle wait, and for the inner completion waits
/// a command performs while it already holds the apartment.
///
///
/// Deliberately one copy. This is the subtlest Win32 contract in the worker —
/// the wake mask decides which events can wake the STA, and
/// decides whether a message already seen by
/// a PeekMessage still counts as a wake. Two copies of it could drift
/// apart silently, and a divergence would show up only as COM events
/// arriving late on a live provider.
///
internal static class StaNativeMethods
{
/// Return value of a failed wait (WAIT_FAILED).
internal const uint MsgWaitFailed = 0xFFFFFFFF;
///
/// Wake even when the pending input has already been seen (but not
/// removed) by an earlier PeekMessage. Both callers peek before
/// they wait, so without this flag a message that arrived during the peek
/// would not wake the wait that follows it.
///
internal const uint MwmoInputAvailable = 0x0004;
/// Wake on any queued input, including sent and posted messages.
internal const uint QsAllInput = 0x04FF;
///
/// Waits for the given handles, for queued input matching
/// , or for the timeout — whichever comes
/// first.
///
/// Number of handles in .
/// Handles to wait on; marshaled as a pointer to the array.
/// Timeout in milliseconds; 0xFFFFFFFF means INFINITE.
/// Input types that may wake the wait ().
/// Wait flags ().
///
/// WAIT_OBJECT_0 + i for a signaled handle, WAIT_OBJECT_0 + count
/// for available input, WAIT_TIMEOUT (258), or
/// .
///
[DllImport("user32.dll", SetLastError = true)]
internal static extern uint MsgWaitForMultipleObjectsEx(
uint count,
IntPtr[] handles,
uint milliseconds,
uint wakeMask,
uint flags);
}