COM activation models

From: Headache (rquirk_at_tandbergtv.com)
Date: 12/20/04


Date: 20 Dec 2004 01:36:53 -0800

I have a freee threaded out-of-process (.exe) server which exposes one
COM object that is CComMultiThread model. When a client accesses the
server's COM object using CoCreateInstance I see no evidence of the
server's main thread running. I've read 'Essential COM' by Don Box and
the section 'Activation and the SCM' says the following:

When calling CoRegisterClassObject, the COM library holds a reference
to the class object provided as the second parameter and associates
the class object with its CLSID in an internally maintained table.
Depending on the activation flags used in the call, the COM library
may also notify the local SCM that the CALLER'S PROCESS IS NOW THE
SERVER PROCESS FOR THE DESIGNATED CLASS.

I'm guessing this is why I don't see the server's main thread
ATLTRACE?

Apparently at odds with this statement (IMHO) is a satement later
which says:

Server processes can register class objects for more than one class.
If the class objects are registered to run in the MTA of the process,
this means that incoming activation requests may be serviced as soon
as the first call to CoRegisterClassObject completes. In any MTA-based
servers this can cause problems .. so REG_CLS_SUSPENDED was introduced
with a call to CoResumeClassObjects.

Now, the server code has the following ON THE PRIMARY THREAD

#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
            REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
        _ASSERTE(SUCCEEDED(hRes));
        hRes = CoResumeClassObjects();
        ATLTRACE("Main thread CoResumeClassObjects");
#else

Would I expect to have to see this code execute (ie. the main thread)
for each activation request or is it only necessary to do it once
using /regserver for the SCM?

The whole reason for this is I need to create a particular
multi-threaded COM singleton on the main thread. To do this I have
overriden CComClassFactorySingleton (created
CComClassFactorySingletonOnMainThread) and have used
DECLARE_COM_CLASSFACTORY_EX. Running the server standalone the class
factory's overridden CreateInstance is entered. However, running it
from a CoCreateInstance in a client does not even seem to get the
server's main thread up and running let alone enter my ClassFactory's
CoCreateInstance!

For reason's best kept secret I can't use CComSingleThreadedModel for
the singleton.

Questions are:

Can I cause the server's main thread to run by effectively changing
the activation flags used in CoRegisterClassObject or ...

Is there any way I can force COM MTA object activation onto the main
thread given the observation that the server's main thread does not
appear to run?

Hope that's clear!

TIA



Relevant Pages

  • Re: Launch a process for each COM object?
    ... "Once an application is connected to a class object with CoGetClassObject, ... COM server instance. ... If COM can't be configured to launch separate processes, ... consider a COM connection to a single process which then iteself launces ...
    (microsoft.public.win32.programmer.ole)
  • Re: Getting class object for specific COM local server process
    ... If I use CoCreateInstance COM always attaches the object ... could I get the class object for that specific process? ... Well the server is windows app with UI and user may be using it. ... So I would need mimic the CoCreateInstance for server. ...
    (microsoft.public.vc.atl)
  • Re: Launch a process for each COM object?
    ... I tried creating a basic ATL project with the 'add new project' wizard, ... I also have a desire that all COM calls into the COM server ... threading models. ... the class object is removed from public view so ...
    (microsoft.public.win32.programmer.ole)
  • Re: Question of CoGetClassObject
    ... Brian, OP wasn't asking about singletons, the whole dicussion ... clients have no say in the way DllGetClassObject is ... implemented by an in-proc server, ... will give them the same instance of the class object. ...
    (microsoft.public.vc.atl)
  • Re: Question of CoGetClassObject
    ... to use the same class object, Client can cache the class object and ... > Brian, OP wasn't asking about singletons, the whole dicussion ... > implemented by an in-proc server, ... > a client can do is cache an instance of the class object ...
    (microsoft.public.vc.atl)