是否可以有一个进程外 COM 服务器,其中每个对象实例使用一个单独的 O/S 进程? [英] Is it possible to have an out-of-process COM server where a separate O/S process is used for each object instance?

查看:18
本文介绍了是否可以有一个进程外 COM 服务器,其中每个对象实例使用一个单独的 O/S 进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个遗留的 C++解决方案引擎",我已经将它包装为一个进程内 COM 对象,供只需要一个单个解决方案引擎"的客户端应用程序使用.

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".

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

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.

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

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.

我运气好吗?

推荐答案

是的,这是可能的.关键是通过调用 CoRegisterClassObject 来注册你的 coclass, 并在值 REGCLS_SINGLEUSEflags 参数中.

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.

如果您的项目是 ATL 7.0+ 项目,您可以通过覆盖 CAtlExeModuleT::PreMessageLoop(),负责注册类对象,因此:

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:

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

这篇关于是否可以有一个进程外 COM 服务器,其中每个对象实例使用一个单独的 O/S 进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆