I have a COM object developed in C++. This class uses another (third-party) COM object, which throws an event EvtThirdParty. This third-party object is just a method of my class.
Now I'm using my COM object from a .NET (Visual Basic for what it's worth) application, and I would like to catch EvtThirdParty from the Visual Basic application.
I'm guessing there is no trivial way to do this, but let this information here just in case someone points one. So, I have added one event (EvtThirdPartyDummy) to my COM object, and whenever it captures EvtThirdParty, raises an EvtThirdPartyDummy to VB.NET.
So far, so good.
Now, when the application receives this event, it must make a couple of calls to my object, to get some information.
Here's where my problems begin. I get a weird message about a disconnected context:
Disconnected Context was detected
Message: Context 0x1b9351e0' is disconnected. Releasing the interfaces from the current context (context 0x1b934f90). This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/apartments stay alive until the application is completely done with the RuntimeCallableWrappers that represent COM components that live inside them.
I'm not ABSOLUTELY sure this is the EXACT message I get, as my Visual Studio 2005 is in Spanish, and I found this in Google, but it seems close enough. There are some differences (e.g., the title of my message says "Visual Studio 2005", IIRC, but this could be due to a different IDE version).
For what I have found in Google, it seems like the thread in which the object was created has been destroyed, but I'm pretty sure this is not the case. It is created in the main application thread.
If I remove all the code from the event handler, everything works as a charm.
My best guess is that my event is being handled in a brand new thread, but AFAIK this shouldn't be the case.
What's going on?