Question about Multithreading and COM

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Here's my situation, I am moving some of my apps over from native C++
(primarily Win32 and MFC).

One of these apps uses some COM objects in worker threads running in the
background where it doesn't bother the user.

I'm keeping the native code that interfaces with the COM objects in a DLL
since I know it works with no problem (I've used for a year and half with no
bugs).

I want my .Net app to use those exported functions (from the above mentioned
DLL) from within child threads.

The problem I'm getting is that when my native code calls CoCreateInstance()
to get the interface, it returns E_NOINTERFACE. But only if my native code
is being called from within a child thread. I've tried just simply calling
it from a button push on a form, and it works perfectly.

Is there some kind of setting I need to set in the Thread object? I've
tried changing the apartment to MTA (from the defaul unknown). Is there some
other setting I'm missing?

thank you so much in advance,
ed
 
No,
I'm using AfxOleInitModule() in the InitInstance() implementation since the
native dll is MFC based. According to the docs this is what I understood to
be the best practice.

I just tried switching to trying to using CoInitialize, and there was no
difference. I also tried getting just the IUnknown interface of the CLSID,
and that works ok. But when I try a QI on the IUnknown pointer for the
interface that I'm actually trying to get, it's the same thing all over again
(E_NOINTERFACE).

ed
 
Back
Top