473,698 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CoCreateInstanc e()
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 3137
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******** *************** ***********@mic rosoft.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
CoCreateInstanc e()
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 AfxOleInitModul e() 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******** *************** ***********@mic rosoft.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
CoCreateInstanc e()
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.Ole Required 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******** *************** ***********@mic rosoft.com...
No,
I'm using AfxOleInitModul e() 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******** *************** ***********@mic rosoft.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
> CoCreateInstanc e()
> 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
1463
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 perform actions on the remote server using the connection initiated by the main thread. At first sight, the only way I could achieve that in a proper manner (ie without having to open a connection to the remote server in every single thread and...
1
2051
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 to kick off the process and continue to work in the appliaction while getting progress updates and the ability to cancel. The method that seems easiest to me is this: The class exposes certain events for progress. Start, ProgressUpdate, and...
11
4260
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 threads of a multithreaded program using embedded SQL. Since the threads do not need to share transaction scopes, the sqleAttachToCtx family of APIs do not seem to be necessary. <quote> In the default implementation of threaded applications against...
1
1942
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. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp The question is In function void ShowProgress(string pi, int totalDigits, int digitsSoFar); if I use Invoke(showProgress, new object { pi, totalDigits, digitsSoFar});the UI performs better(it responses to my...
2
1206
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 Code ? 2. Is memory leakage possible in .Net Unmanaged Code ? 3. How can I find the what % of memory is being used by DLL at run time ? 4. What is difference between Sunchronous processing and Async
5
2135
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 when I got two threads going at the same time. What I have is two text boxes (textBox1 and textBox2) and four buttons(cmdStartThread1, cmdStartThread2, cmdStopThread1, cmdStopThread2)
2
1663
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 showing all filetypes and icons. I have an object that has extension, desc (like Word Document) and then icon, which is nothing to start with. I have a collection object of these and when it is initialized it goes to
2
2310
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 I just wanted to ask if I am missing anything based on the following scenario. My test app pulls data from a large external data source which has a table-like structure (but not rdbms - more
5
2485
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 multithreading online using C# .
7
16307
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 Exceptional C++, for example). Platform-specific (e.g.: Win32, POSIX) is OK, as long as it's good :) Thank you, Ray
0
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.