是否可能有一个进程外的COM服务器,其中每个对象实例都使用一个单独的O/S进程?

时间:2022-10-15 21:59:27

I have a legacy C++ "solution engine" that I have already wrapped as an in-process COM object for use by client applications that only require a single "solution engine".

我有一个遗留的c++“解决方案引擎”,我已经将它包装为一个进程内的COM对象,供只需要一个“解决方案引擎”的客户机应用程序使用。

However I now have a client application that requires multiple "solution engines". Unfortunately the underlying legacy code has enough global data, singletons and threading horrors that given available resources it isn't possible to have multiple instances of it in-process simultaneously.

但是,我现在有一个需要多个“解决方案引擎”的客户机应用程序。不幸的是,底层遗留代码有足够的全局数据、单例和线程恐怖,如果给定可用资源,就不可能同时拥有多个it实例。

What I am hoping is that some kind soul can tell me of some COM magic where with the flip of a couple of registry settings it is possible to have a separate out-of-process COM server (separate operating system process) for each instance of the COM object requested.

我所希望的是,某个善良的灵魂能够告诉我一些COM魔法,通过翻转两个注册表设置,就可以为请求的COM对象的每个实例拥有一个单独的进程外COM服务器(单独的操作系统进程)。

Am I in luck?

我幸运吗?

3 个解决方案

#1


8  

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

是的,这是可能的。关键是通过调用CoRegisterClassObject来注册您的coclass,或者在flags参数中调用REGCLS_SINGLEUSE值。

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, thusly:

如果您的项目是ATL 7.0+项目,您可以通过重写CAtlExeModuleT::PreMessageLoop()来实现这一点,它负责注册类对象,thusly:

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;
}

#2


1  

You would need a "master" coclass to lock in the EXE instance, similar to an "Application" interface. Locate the CoRegisterClassObject() call for its factory. And change the REGCLS argument to REGCLS_SINGLEUSE.

您将需要一个“master”coclass来锁定EXE实例,类似于“Application”接口。为其工厂定位CoRegisterClassObject()调用。并将REGCLS参数更改为REGCLS_SINGLEUSE。

This will automatically unregister the class factory as soon as the first client connects to it. Calling CoCreateInstance() for that factory again starts a new instance of the server. I think.

这将在第一个客户端连接到类工厂时自动取消注册。为该工厂调用CoCreateInstance()将再次启动服务器的新实例。我认为。

#3


-2  

I'm pretty sure this is not possible. A COM out-of-proc server has to globally register the class objects it provides (via CoRegisterClassObject); part of this registration is the class GUID. Obviously you cannot register the same GUID twice.

我很确定这是不可能的。COM out- proc服务器必须全局注册它提供的类对象(通过CoRegisterClassObject);这个注册的一部分是GUID类。显然,不能两次注册相同的GUID。

#1


8  

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

是的,这是可能的。关键是通过调用CoRegisterClassObject来注册您的coclass,或者在flags参数中调用REGCLS_SINGLEUSE值。

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, thusly:

如果您的项目是ATL 7.0+项目,您可以通过重写CAtlExeModuleT::PreMessageLoop()来实现这一点,它负责注册类对象,thusly:

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;
}

#2


1  

You would need a "master" coclass to lock in the EXE instance, similar to an "Application" interface. Locate the CoRegisterClassObject() call for its factory. And change the REGCLS argument to REGCLS_SINGLEUSE.

您将需要一个“master”coclass来锁定EXE实例,类似于“Application”接口。为其工厂定位CoRegisterClassObject()调用。并将REGCLS参数更改为REGCLS_SINGLEUSE。

This will automatically unregister the class factory as soon as the first client connects to it. Calling CoCreateInstance() for that factory again starts a new instance of the server. I think.

这将在第一个客户端连接到类工厂时自动取消注册。为该工厂调用CoCreateInstance()将再次启动服务器的新实例。我认为。

#3


-2  

I'm pretty sure this is not possible. A COM out-of-proc server has to globally register the class objects it provides (via CoRegisterClassObject); part of this registration is the class GUID. Obviously you cannot register the same GUID twice.

我很确定这是不可能的。COM out- proc服务器必须全局注册它提供的类对象(通过CoRegisterClassObject);这个注册的一部分是GUID类。显然,不能两次注册相同的GUID。