Okay, "COM apartments" are really kicking my butt today.
I wrote an MFC program which creates a COM object from a local server (EXE), creates a DirectShow filter from an in-process server, and then passes the COM object interface to the filter.
The problem is, the MFC program, COM object, and DirectShow filter are all in different COM apartments:
MFC program -- process A, single threaded apartment
COM object -- process B, multi threaded apartment
DirectShow filter -- process A, multi threaded apartment
When the DirectShow filter proceeds to call methods of the interface, sometimes they work, sometimes they don't. When they don't, either process A freezes, or I get exceptions thrown which mention "interface used was marshalled for a different apartment" or something like that.
I know that when an object in one apartment creates an object in another apartment and gets an interface to it, COM creates special proxy/stub modules to marshal the interface. So how can I take this interface and use it with a third apartment? Is there a way to "remarshal" the interface to work with another apartment?
I wrote an MFC program which creates a COM object from a local server (EXE), creates a DirectShow filter from an in-process server, and then passes the COM object interface to the filter.
The problem is, the MFC program, COM object, and DirectShow filter are all in different COM apartments:
MFC program -- process A, single threaded apartment
COM object -- process B, multi threaded apartment
DirectShow filter -- process A, multi threaded apartment
When the DirectShow filter proceeds to call methods of the interface, sometimes they work, sometimes they don't. When they don't, either process A freezes, or I get exceptions thrown which mention "interface used was marshalled for a different apartment" or something like that.
I know that when an object in one apartment creates an object in another apartment and gets an interface to it, COM creates special proxy/stub modules to marshal the interface. So how can I take this interface and use it with a third apartment? Is there a way to "remarshal" the interface to work with another apartment?