This sequence of patches fixes numerous corner cases in CoMsgWaitForMultipleHandles, particularly around the exact sequence in which signaled handles, windows messages, and APCs are considered and which "win" if more than one thing has happened at a time.
This was previously submitted quite some time ago, and rejected as "Needs splitting": https://www.winehq.org/pipermail/wine-devel/2020-November/177529.html Sorry it has taken me so long to get back to this one, but here's an attempt to tease it apart into a number of smaller commits that each make smaller changes and add some of the new tests. Hopefully that makes it easier to follow which change fixes what. Apologies if the splitting is still a little tortured in places, since it re-thought all at once and then split apart, not developed in this order and then squashed. But hopefully this is more readable.
Major fixes are: - closes a race condition with short/zero timeouts, in which it could reports RPC_S_PENDING without ever even checking the handles - cancellation via IMessageFilter::PendingMesage -> `PENDINGMSG_CANCELCALL` now actually exits the wait - makes sure not to pump additional messages after the handles have been signaled - don't use a MsgWait until after seeing that handles were not already signaled. This is mostly important to COWAIT_WAITALL. It's still not advisable to use COWAIT_WAITALL in an STA (for reasons all our favorite Microsoft Gurus have discussed: https://learn.microsoft.com/en-us/archive/blogs/larryosterman/things-you-sho... https://devblogs.microsoft.com/oldnewthing/20060127-17/?p=32493). But it gets fixed in passing as a consequence of the previous changes, and so there are some new conformance tests to show that the new behavior matches windows.
There's also a some new `todo_wine` tests for spurious calls to IMessageFilter_MessagePending. This behavior has *not* changed, but I expanded the test coverage (unsuccessfully) hoping it would give me a hint about what should change. Since I still don't know what the rules should be, I left the new tests `todo_wine`. But maybe they'll be a useful hint someday.