Re: ATL threading problem using client COM interface

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Igor Tandetnik wrote:
"Edward Diener" <eddielee_no_spam_here@xxxxxxxxxxxxxx> wrote in message
news:Oo%232SvZBJHA.4108@xxxxxxxxxxxxxxxxxxxx
Igor Tandetnik wrote:
"Edward Diener" <eddielee_no_spam_here@xxxxxxxxxxxxxx> wrote in
message news:O90YIBZBJHA.5468@xxxxxxxxxxxxxxxxxxxx
So what you are saying is that in my COM server, when I want to
pass a client interface pointer from the main thread in my STA to
my worker thread, I need to use one of the techniques above ?
Yes. You would also need to initialize COM on your worker thread - it
looks like CWorkerThread doesn't itself do that.
My COM Server is a DLL. It does not appear that initializing COM in a
DLL is correct. But perhaps I am wrong about this.

You are wrong about this. Every thread that wants to do COM work needs to initialize COM first. It doesn't matter whether or not the CreateThread call that created this thread is part of a DLL.

Now, if you have an in-proc (DLL) COM server, then the thread your objects are created on must necessarily have already initialized COM - otherwise, the client wouldn't be able to call CoCreateInstance and create your object in the first place. So you shouldn't initialize COM on client-created threads.

But if you create your own threads, there's no magic fairy that would somehow initialize COM on them. It's your responsibility.

OK, understood. I can CoInitializeEx in the constructor of my IWorkerThreadClient thread class and CoUninitialize in its destructor. A nice use of RAII in C++.


Which part of "CComGITPtr" did you find unclear?
That class deals with the global interface table.

"Global" here really means "global within a process".

Understood.


If the interface is
created by the client and passed to me on the server is it valid to
add that interface to the GIT so that my different server threads can
use it in place of the marshalling functions you also mentioned ?

Yes. Note that the act of retrieving a pointer from GIT _is_ marshalling. It's not like you eliminate it somehow.

Understood. The GIT is just a process global area in memory from which to retrieve my marshalled pointer from any thread once I stash it there.


I also realized, if I am not mistaken, that I could use free threading
rather than apartment threading

You could. It essentially achieves the same effect: right at the time when the client calls CoCreateInstance to get an instance of your component, COM spins a worker thread that enters MTA, and creates your component there. Your interface pointer is marshalled to the client, and any calls the client makes on your object are marshalled back to MTA threads. If the client passes its own interfrace pointers as parameters to those methods, they are also automatically marshalled at that time.

Note that, when you created UI from your STA component, you could rely on the client's message pump to deliver messages to your windows. Once you have an MTA component, you are running in a different threads from your client. If you want to display UI, you would have to spawn a dedicated thread for it and have it run a message pump.

Thanks for the info on MTA and the message pump. I will stick to STA right now to get it working, then consider switching to MTA if I feel the need for it. MTA will be more responsive to my server doing its processing but raises synchronization issues which I can ignore for now.

Thanks for all your help !
.



Relevant Pages

  • Re: COM concurrency???
    ... > call the object concurrently through this single interface pointer. ... > the client does not have to be explicitly multithreaded. ... >> one message queue will be responsible for multiple stubs of different ... >> words dose MS RPC support concurrency for one interface? ...
    (microsoft.public.win32.programmer.ole)
  • Re: Marshalling SafeArray of VARIANTS and IDispatch
    ... A client would then get an interface pointer from ... safearray and query for IRecord - at this point IRecord would be ... Does this mean that if I have a safearray on the client, ...
    (microsoft.public.win32.programmer.ole)
  • Re: ATL threading problem using client COM interface
    ... pass a client interface pointer from the main thread in my STA to ... You would also need to initialize COM on your worker thread - it ... use it in place of the marshalling functions you also mentioned? ...
    (microsoft.public.vc.atl)
  • Re: 1910 The object exporter specified was not found. OR_INVALID_OXID
    ... The most common reason for this error in Win2K onwards is that the marshaled ... interface pointer from the server is unreachable from the for some reason. ... A quick check would be to reach the server from the client using FQDN *and* ... Configure COM Internet Services on the Client Side ...
    (microsoft.public.win32.programmer.ole)
  • Re: ATL and object aggregation (more)
    ... I will look at in-depth to IMarshal, but from what I know of marshalling, I ... >>> Why don't you simply marshal InObj3's interface pointer into the client ... >> obtain an InObj3 running in the same process than OutObj). ...
    (microsoft.public.vc.atl)