I would like to pass a COM object created in the main thread of my C++/MFC8 program to a different thread, and leave all synchronization to COM. Using CoMarshalInterThreadInterfaceInStream works -- until the user opens a modal dialog. While the dialog is open, apparently all marshalling messages are rejected, which I sort of understand because they could wreak havoc, e.g. by re-entering the modal dialog. The thing is, one of the operations involving the thread is supposed to be triggered from a modal dialog, so if the rejection is just a safety measure, I would like to turn it off.
One hack I've tried is to make the dialog non-modal and disable the main window while it is open. Turns out disabling the main window also makes marshalling fail. This particularly surprises me because the window receiving the messages is not the main window but a special hidden one (as documented by Microsoft). So some code must be checking the "enabled" status of the main window explicitly. In fact, I can see the messages (WM_USER sent to that special window) arrive in the program's message loop and march on via DispatchMessage, but then I lose track of them.
So I'm wondering where they go next (only to come back disappointed). I figured AfxOleGetMessageFilter might lead me somewhere, but breakpoints in the implementation of the object it returns are not even hit. So if someone knows where to look, I would be very grateful. Of course, ideas for a workaround are also welcome. (The best I could come up with was to make the dialog non-modal and then temporarily re-enable the main window underneath. Yuk!)
(If someone wants to test this on a minimal example, I can try to come up with one, but it will not be small. Thanks in advance!)