Re: COM apartments

From: Ivan Brugiolo [MSFT] (ivanbrug_at_online.microsoft.com)
Date: 08/01/04

  • Next message: Daniel L Newhouse: "Re: newbie: RS232 and SDK"
    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
    >
    >
    >
    >
    

  • Next message: Daniel L Newhouse: "Re: newbie: RS232 and SDK"

    Relevant Pages

    • STA vs. MTA when calling out-of-process objects
      ... I have created an EXE server with VC 6.0 and ATL. ... My client is a GUI application which has a single thread that is initialized ... called from the STA that created it. ...
      (microsoft.public.vc.atl)
    • Re: COM calls reentering in STA
      ... Client and server use STA. ... initially passes in a callback pointer the server will use to call ...
      (microsoft.public.vc.atl)
    • STA behaves like MTA upon method call
      ... Part A) in-process COM server created in STA; ... Part A registers an event sink from the COM server in part B. ...
      (microsoft.public.vc.atl)
    • Re: Something like "ping" for windows messages.
      ... Is there any gaurentee that OnIdle ... kernel network buffers available, or the amount of network bandwidth available. ... at all how fast the http server is. ... Poking messages at the message pump only tells you how responsive the message pump is. ...
      (microsoft.public.vc.mfc)
    • Re: COM Server/Client mit Threads
      ... COM-Server bisher hab ich die Initialisierung und auch die gestarteten ... Wenn Du zum Beispiel Deine Server Funktionen in einen eigenen STA legst dürftest Du keine Probleme haben. ... Ich gehe davon aus, dass Du nur einen Thread hast und alles in einem STA lebt, der auch gleichzeitig der GUI ...
      (microsoft.public.de.vc)