public:
CComDebugObject(void * = NULL)
{
+#if DEBUG_CCOMOBJECT_CREATION
+ DbgPrint("%S, this=%08p\n", __FUNCTION__, static_cast<Base*>(this));
+#endif
_pAtlModule->Lock();
}
STDMETHOD_(ULONG, AddRef)()
{
int rc = this->InternalAddRef();
- DbgPrint("RefCount is now %d(++)! %s\n", rc, __FUNCTION__);
+#if DEBUG_CCOMOBJECT_REFCOUNTING
+ DbgPrint("%s, RefCount is now %d(--)! \n", __FUNCTION__, rc);
+#endif
return rc;
}
STDMETHOD_(ULONG, Release)()
{
- ULONG newRefCount;
+ int rc = this->InternalRelease();
+
+#if DEBUG_CCOMOBJECT_REFCOUNTING
+ DbgPrint("%s, RefCount is now %d(--)! \n", __FUNCTION__, rc);
+#endif
- newRefCount = this->InternalRelease();
- if (newRefCount == 0)
+ if (rc == 0)
{
- DbgPrint("RefCount is now 0! Deleting! %s\n", newRefCount, __FUNCTION__);
+#if DEBUG_CCOMOBJECT_DESTRUCTION
+ DbgPrint("%s, RefCount reached 0 Deleting!\n", __FUNCTION__);
+#endif
delete this;
}
- else
- {
- DbgPrint("RefCount is now %d(--)! %s\n", newRefCount, __FUNCTION__);
- }
- return newRefCount;
+ return rc;
}
STDMETHOD(QueryInterface)(REFIID iid, void **ppvObject)
hResult = E_OUTOFMEMORY;
newInstance = NULL;
- ATLTRY(newInstance = new CComDebugObject<Base>())
- if (newInstance != NULL)
- {
+ ATLTRY(newInstance = new CComDebugObject<Base>());
+ if (newInstance != NULL)
+ {
newInstance->SetVoid(NULL);
newInstance->InternalFinalConstructAddRef();
hResult = newInstance->_AtlInitialConstruct();
delete newInstance;
newInstance = NULL;
}
- }
+ }
*pp = newInstance;
return hResult;
}
}
}
+template<class T, class R>
+HRESULT inline ShellDebugObjectCreator(REFIID riid, R ** ppv)
+{
+ CComPtr<T> obj;
+ HRESULT hResult;
+
+ if (ppv == NULL)
+ return E_POINTER;
+ *ppv = NULL;
+ ATLTRY(obj = new CComDebugObject<T>);
+ if (obj.p == NULL)
+ return E_OUTOFMEMORY;
+ hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
+ if (FAILED(hResult))
+ return hResult;
+ return S_OK;
+}
+
template<class T, class R>
HRESULT inline ShellObjectCreator(REFIID riid, R ** ppv)
{