472,986 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 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 3111
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jean-Yves Nief | last post by:
hello, I have written a script which is performing some tasks in multithreading mode: the main thread is opening a connection to a distant server and all the threads that I start will have to...
1
by: dixp | last post by:
I'm new to writing multithreaded apps and I have a design question. I have a winforms app and a class which has a method that does processing which is time intensive. I want the user to be able...
11
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate...
1
by: Jeff Yang | last post by:
These days,I have read the artile "Safe, Simple Multithreading in Windows Forms, Part 1" on MSDN,and I also runed the example of it....
2
by: Silent Ocean | last post by:
Hi All I have following questions regarding C# Assembly and Threading. Let me know the precise answer or lead me to the proper materials. 1. Is memory leakeage possible in .Net Manager...
5
by: sarge | last post by:
I would like to know how to perform simple multithreading. I had created a simple form to test out if I was multithreading properly, but got buggy results. Sometime the whole thig would lock up...
2
by: SStory | last post by:
Here is the situation. I want to display Icons, Type of file etc from a file extension. Upon initial program load I may only need icons for certain files. But other operations will require...
2
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and...
5
by: sandy82 | last post by:
Whats actuallly multithreading is ... and how threading and multithreading differ . Can any1 guide how multithreading is used on the Web .. i mean a practical scenario in which u use...
7
by: Ray | last post by:
Hello, Greetings! I'm looking for a solid C++ multithreading book. Can you recommend one? I don't think I've seen a multithreading C++ book that everybody thinks is good (like Effective C++ or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.