473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 3121
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.