Is it possible to have an out-of-process COM server where a separate O / S process is used for each instance of the object?

I have an outdated "solution mechanism" in C ++, which I have already wrapped as a COM object in the process for use by client applications that require only a single solution mechanism . "

However, I now have a client application that requires several "solutions." Unfortunately, the base legacy code has sufficient global data, singletones, and the horrors of threads, which, given available resources, cannot have multiple instances in the process at the same time.

I hope that some soul can tell me about some COM manner, where, with the flip of several registry parameters, you can have a separate COM server outside the processing process (a separate operating system process) for each instance of the COM object is requested.

Am i lucky?

+5
source share
3 answers

Yes it is possible. The key is to register your coclass by calling CoRegisterClassObject , and OR by setting REGCLS_SINGLEUSE in the parameter flags.

If your project is an ATL 7.0+ project, you can do this by overriding CAtlExeModuleT :: PreMessageLoop () , which is responsible for registering the class object, this way:

HRESULT CATLHacksModule::PreMessageLoop(int nShow)
{
    HRESULT hr = RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_SINGLEUSE);
    if (hr == S_OK)
    {
        if (m_bDelayShutdown && !StartMonitor())
        {
            hr = E_FAIL;
        }
    }
    else
    {
        m_bDelayShutdown = false;
    }
    return hr;
}
+8

"-" EXE-, "Application". CoRegisterClassObject() factory. REGCLS REGCLS_SINGLEUSE.

factory, . CoCreateInstance() factory . .

+1

, . COM out-of-proc , ( CoRegisterClassObject); GUID . , GUID.

-2
source

All Articles