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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With