Here's yet another ATL classfactory variation you may find useful. If they want to disable COM's default Garbage collection/pinging (and all the associated goodies - ref counting & timely shutdown etc.) than they can use this classfactory.
MS KB Q171414 describes one way to do this. But it has several problems. I like this one. The object using this classfactory is responsible for its own shutdown by calling CoDisconnectObject() at the place appropriate to his code logic.
Don Box gave the idea to write this one. Thanks Don...
class CComClassFactoryNoPing: public CComClassFactory
STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter, REFIID riid, void** ppvObj)
HRESULT hr = CComClassFactory::CreateInstance(pUnkOuter, riid, ppvObj);
if(SUCCEEDED(hr)) //NoPing CF
hr = ::CreateStreamOnHGlobal(0,FALSE,&spStream);
hr = ::CoMarshalInterface(spStream,
#define DECLARE_CLASSFACTORY_NOPING() DECLARE_CLASSFACTORY_EX(CComClassFactoryNoPing)
class ATL_NO_VTABLE CFoo: public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CFoo, &CLSID_Foo>,
public IFoo ...
DECLARE_CLASSFACTORY_NOPING() // Disable Pinging
This page and the source contained in(or
referred to) by this page are Copyright (c) 1998, Dharma Shukla.
All rights reserved. No warrenties extended. Use at your own risk.
Do send Comments/Bugs to me :-)