是否可能有一个进程外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?

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

问题描述

我有一个旧的C ++解决方案引擎,我已经封装为一个进程中的COM对象,供只需要一个单个解决方案引擎的客户端应用程序使用。



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



我希望是某种灵魂可以告诉我一些COM魔术,其中翻转的几个注册表设置,可以有一个单独的进程外COM服务器(单独的操作系统进程)的每个实例的COM对象请求。



我是运气吗?

解决方案

, 这个有可能。关键是要注册您的coclass,方法是调用 CoRegisterClassObject 和OR中的值 REGCLS_SINGLEUSE 如果您的项目是ATL 7.0+项目,您可以通过在标志覆盖 CAtlExeModuleT :: PreMessageLoop(),其中负责注册类对象,因此:

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


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.

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.

Am I in luck?

解决方案

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.

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天全站免登陆