[RSHELL]
[reactos.git] / include / reactos / undocshell.h
index 517b00b..5b1e785 100644 (file)
@@ -626,6 +626,9 @@ class CComDebugObject : public Base
 public:
     CComDebugObject(void * = NULL)
     {
+#if DEBUG_CCOMOBJECT_CREATION
+        DbgPrint("%S, this=%08p\n", __FUNCTION__, static_cast<Base*>(this));
+#endif
         _pAtlModule->Lock();
     }
 
@@ -638,25 +641,28 @@ public:
     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)
@@ -675,9 +681,9 @@ public:
 
         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();
@@ -691,7 +697,7 @@ public:
                 delete newInstance;
                 newInstance = NULL;
             }
-            }
+        }
         *pp = newInstance;
         return hResult;
     }
@@ -724,6 +730,24 @@ void ReleaseCComPtrExpectZero(CComPtr<T>& cptr, BOOL forceRelease = FALSE)
     }
 }
 
+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)
 {