Re: COM apartments
From: Ivan Brugiolo [MSFT] (ivanbrug_at_online.microsoft.com)
Date: 08/01/04
- Previous message: benben: "COM apartments"
- In reply to: benben: "COM apartments"
- Next in thread: Igor Tandetnik: "Re: COM apartments"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 31 Jul 2004 20:28:44 -0700
Let's start from the beginning:
"You have a COM server that resides in MTA of a different process."
This is already confused. If the COM component is in proc, it can declares
it's Apartment Model. If it's implemented in a COM Server,
then it's always implicitely in the MTA, and, calls to the exported
interface pointers
can be called in any thread, and in particualr, they can be NOT called in
the thread
where the interface implementation was first Co-Created.
There is no need for the COM server to have a message pump.
All a COM server has to do is to CoRegister the class factory.
>From that point on, the RPC thread pool will do the work.
Every time OLE32 needs to contact the object resolver,
in order to export an IPID, for example, it creates an RPC endpoint.
You can notice this by calling RpcMgmtEpEltInqXXXX.
For example, one of such RPC endpoint created by OLE32 looks like
-------------- ------------------------------------------ 19
UUID: {1FF70682-0A51-30E8-076D-740BE8CEE98B}
version: 1.0
StringBinding: ncalrpc:[OLE515C0747B0954305B4E2FD3FC5E3]
UUID: {00000000-0000-0000-0000-000000000000}
AnnoTation:
Through this endpoint, all the DCOM calls are dispatched.
For example, once your interface pointer has been exported
from the DCOM server, when a client invokes a method,
the ole32!ThreadInvoke RPC call will be invoked, and
from that place, the correct IPID will be resolved to an interface
pointer implementation, and the correct method will be called.
The complication of a process hosting a COM component
that lives in an STA is only marginally more complex.
Let's assume Process A calls CoCreateInstace for a
component that can live in an STA. If the current thread
has initialized com in the STA, then the CoCreation will happen in the
current thread.
If the current thread is MTA or neutral, then OLE32 will create
a suitable thread to host the component.
So far so good, either there is an STA thread,
or a an STA thread will be created.
Now, let's say you marshal away to a different process
the interface pointer to the STA component.
When the remote process makes a method call,
the call will be picked-up by the RPC thread pool,
and from there, it will be dispatched to the STA.
-- This posting is provided "AS IS" with no warranties, and confers no rights. Use of any included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm "benben" <benhongh@yahoo.com.au> wrote in message news:u4IzSm2dEHA.4048@TK2MSFTNGP12.phx.gbl... > I am quite confused with the COM apartment concepts. If a COM server resides > in a MultiThreaded Apartment in another process, would it require one of the > threads in the apartment implement a message pump? If so, and if more than > one threads implement message pumps in the apartment, which thread's message > queue is to receive the ORPC message? If none of the threads implements a > message pump in the appartment, will the invocation fail? > > ben > > > >
- Previous message: benben: "COM apartments"
- In reply to: benben: "COM apartments"
- Next in thread: Igor Tandetnik: "Re: COM apartments"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|