471,357 Members | 1,122 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 software developers and data experts.

Question about Multithreading and COM

Ed
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
Jul 22 '05 #1
3 3047
Do you call CoInitialize to init the COM library in your threads?

-Atul
http://www.ssware.com/
Shell MegaPack - Windows Explorer Shell Controls for ActiveX and .Net

"Ed" <Ed@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com...
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

Jul 22 '05 #2
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

"Atul" wrote:
Do you call CoInitialize to init the COM library in your threads?

-Atul
http://www.ssware.com/
Shell MegaPack - Windows Explorer Shell Controls for ActiveX and .Net

"Ed" <Ed@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com...
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


Jul 22 '05 #3
Why don't you try calling Application.OleRequired from your child thread?

-Atul
http://www.ssware.com/
Shell MegaPack - Windows Explorer Shell Controls for ActiveX and .Net

"Ed" <Ed@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
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

"Atul" wrote:
Do you call CoInitialize to init the COM library in your threads?

-Atul
http://www.ssware.com/
Shell MegaPack - Windows Explorer Shell Controls for ActiveX and .Net

"Ed" <Ed@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com...
> 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


Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jean-Yves Nief | last post: by
1 post views Thread by dixp | last post: by
2 posts views Thread by Silent Ocean | last post: by
5 posts views Thread by sarge | last post: by
2 posts views Thread by Rich | last post: by
5 posts views Thread by sandy82 | last post: by
7 posts views Thread by Ray | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.