473,396 Members | 1,933 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,396 software developers and data experts.

access a com object from different threads

Hi,

I have an STA COM object and I need to access it from different
threads. I get the obligatory "QueryInterface for interface xyz
failed." exception.
Is there any possibility apart from using Invoke on a hidden form
thread? Can I perhaps somehow create a class with a message loop?

Thanx for your help,

Fabian
Nov 15 '05 #1
4 2837
Fabian,

If the COM object is a STA threaded object, then you can not just pass
it between threads. What you need to do is marshal the interface from the
thread it was created on, to the thread that you want to call it on. In
order to do this, you will need to use the global interface table
(accessible through the P/Invoke layer and COM interop). Check out the
section of the Platform SDK titled "Accessing Interfaces Across Apartments",
located at (watch for line wrap):

http://msdn.microsoft.com/library/de...nthrd_2eer.asp

This will give you the interfaces and functions you need to call to
marshal the interface between threads. You will have to use interop, but
everything you need is there.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fabian H?rle" <ha****@sls-software.de> wrote in message
news:e7************************@posting.google.com ...
Hi,

I have an STA COM object and I need to access it from different
threads. I get the obligatory "QueryInterface for interface xyz
failed." exception.
Is there any possibility apart from using Invoke on a hidden form
thread? Can I perhaps somehow create a class with a message loop?

Thanx for your help,

Fabian

Nov 15 '05 #2
The CLR is handling the necessary marshalling of interfaces when COM object
references are used from other threads than the creating thread, this should
work.
One possible cause is that the tlb is not registered.

Willy.
"Fabian H?rle" <ha****@sls-software.de> wrote in message
news:e7************************@posting.google.com ...
Hi,

I have an STA COM object and I need to access it from different
threads. I get the obligatory "QueryInterface for interface xyz
failed." exception.
Is there any possibility apart from using Invoke on a hidden form
thread? Can I perhaps somehow create a class with a message loop?

Thanx for your help,

Fabian

Nov 15 '05 #3
Hi Nicholas,

thanks a lot for the link to the MS Doc. I just read about how to create a
global interface
(http://msdn.microsoft.com/library/de...-us/com/htm/ap
tnthrd_4ew5.asp). This means, that I have to modify the COM Object's code,
doesn'it? Now, the problem is, that the object belongs to a third party
library - and I can' change it. Is there another possibility?

best regards,

Fabian

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP11.phx.gbl...
Fabian,

If the COM object is a STA threaded object, then you can not just pass
it between threads. What you need to do is marshal the interface from the
thread it was created on, to the thread that you want to call it on. In
order to do this, you will need to use the global interface table
(accessible through the P/Invoke layer and COM interop). Check out the
section of the Platform SDK titled "Accessing Interfaces Across Apartments", located at (watch for line wrap):

http://msdn.microsoft.com/library/de...nthrd_2eer.asp
This will give you the interfaces and functions you need to call to
marshal the interface between threads. You will have to use interop, but
everything you need is there.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fabian H?rle" <ha****@sls-software.de> wrote in message
news:e7************************@posting.google.com ...
Hi,

I have an STA COM object and I need to access it from different
threads. I get the obligatory "QueryInterface for interface xyz
failed." exception.
Is there any possibility apart from using Invoke on a hidden form
thread? Can I perhaps somehow create a class with a message loop?

Thanx for your help,

Fabian


Nov 15 '05 #4
Hi Willy,
One possible cause is that the tlb is not registered.
I can import the library via

Add Reference --> COM

without tlbimp.

Doesn't this mean, that the library is registered correctly?

Regards,

Fabian

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:ef**************@TK2MSFTNGP09.phx.gbl... The CLR is handling the necessary marshalling of interfaces when COM object references are used from other threads than the creating thread, this should work.
One possible cause is that the tlb is not registered.

Willy.
"Fabian H?rle" <ha****@sls-software.de> wrote in message
news:e7************************@posting.google.com ...
Hi,

I have an STA COM object and I need to access it from different
threads. I get the obligatory "QueryInterface for interface xyz
failed." exception.
Is there any possibility apart from using Invoke on a hidden form
thread? Can I perhaps somehow create a class with a message loop?

Thanx for your help,

Fabian


Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Zurer | last post by:
My architecture is, (ala Fowler PoEAA) Presentation Layer | Service Layer | Problem Domain (My Business Objects are held in memory) | Persistence Layer
1
by: edo | last post by:
Following is a summary of articles spanning a 7 day period, beginning at 12 Dec 2003 05:22:35 GMT and ending at 19 Dec 2003 04:09:06 GMT. Notes ===== - A line in the body of a post is...
9
by: Roger Down | last post by:
Lets say I have a method UpdateCache() called from a single thread. I also have a method GetCache() called from multiple threads. When UpdateCache() is called, the cache updating is being...
5
by: Sunny | last post by:
Hi, I have to implement client/server application. The client have to instaniate an remoting object via http and pass some auth info. If the auth is OK, the client should invoke a method (or...
6
by: Clark Sann | last post by:
Can someone help me understand what object should be used as the lock object? I've seen some programs that use Monitor.Enter(Me). Then, in those same programs, they sometimes use another object. ...
3
by: Kevin | last post by:
Using this: http://msdn2.microsoft.com/en-us/library/3dasc8as(VS.80).aspx as an example I have a question concerning the reuse of objects. In the example 10 instances of the Fibonacci class...
10
by: Chris Bordeman | last post by:
Hi all. I created a custom ServiceHost object and did a bunch of initialization there. Now I need to access an object in it from the actual WCF service class. How can this be done? Thanks!!!
9
by: thiago777 | last post by:
Question details: VB .NET / threads / events / GUI Imagine the following situation: A method from object "A" creates "n" threads. Variables from these threads contains values that should...
9
by: koschwitz | last post by:
Hi, I hope you guys can help me make this simple application work. I'm trying to create a form displaying 3 circles, which independently change colors 3 times after a random time period has...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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...
0
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...
0
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...

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.