[RSHELL]
[reactos.git] / include / reactos / undocshell.h
index e5c2193..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,19 +641,28 @@ public:
     STDMETHOD_(ULONG, AddRef)()
     {
         int rc = this->InternalAddRef();
-        DbgPrint("RefCount is now %d(++)!\n", rc);
+#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();
-        DbgPrint("RefCount is now %d(--)!\n", newRefCount);
-        if (newRefCount == 0)
+        if (rc == 0)
+        {
+#if DEBUG_CCOMOBJECT_DESTRUCTION
+            DbgPrint("%s, RefCount reached 0 Deleting!\n", __FUNCTION__);
+#endif
             delete this;
-        return newRefCount;
+        }
+        return rc;
     }
 
     STDMETHOD(QueryInterface)(REFIID iid, void **ppvObject)
@@ -669,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();
@@ -685,12 +697,18 @@ public:
                 delete newInstance;
                 newInstance = NULL;
             }
-            }
+        }
         *pp = newInstance;
         return hResult;
     }
 };
 
+#ifdef DEBUG_CCOMOBJECT
+#   define _CComObject CComDebugObject
+#else
+#   define _CComObject CComObject
+#endif
+
 template<class T>
 void ReleaseCComPtrExpectZero(CComPtr<T>& cptr, BOOL forceRelease = FALSE)
 {
@@ -712,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)
 {
@@ -721,7 +757,7 @@ HRESULT inline ShellObjectCreator(REFIID riid, R ** ppv)
     if (ppv == NULL)
         return E_POINTER;
     *ppv = NULL;
-    ATLTRY(obj = new CComObject<T>);
+ATLTRY(obj = new _CComObject<T>);
     if (obj.p == NULL)
         return E_OUTOFMEMORY;
     hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
@@ -740,7 +776,7 @@ HRESULT inline ShellObjectCreatorInit(REFIID riid, R ** ppv)
     if (ppv == NULL)
         return E_POINTER;
     *ppv = NULL;
-    ATLTRY(obj = new CComObject<T>);
+    ATLTRY(obj = new _CComObject<T>);
     if (obj.p == NULL)
         return E_OUTOFMEMORY;
     hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
@@ -766,7 +802,7 @@ HRESULT inline ShellObjectCreatorInit(REFIID riid, void ** ppv)
     if (ppv == NULL)
         return E_POINTER;
     *ppv = NULL;
-    ATLTRY(obj = new CComObject<T>);
+    ATLTRY(obj = new _CComObject<T>);
     if (obj.p == NULL)
         return E_OUTOFMEMORY;
     hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
@@ -792,7 +828,7 @@ HRESULT inline ShellObjectCreatorInit(T1 initArg1, REFIID riid, R ** ppv)
     if (ppv == NULL)
         return E_POINTER;
     *ppv = NULL;
-    ATLTRY(obj = new CComObject<T>);
+    ATLTRY(obj = new _CComObject<T>);
     if (obj.p == NULL)
         return E_OUTOFMEMORY;
     hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
@@ -818,7 +854,7 @@ HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, REFIID riid, R *
     if (ppv == NULL)
         return E_POINTER;
     *ppv = NULL;
-    ATLTRY(obj = new CComObject<T>);
+    ATLTRY(obj = new _CComObject<T>);
     if (obj.p == NULL)
         return E_OUTOFMEMORY;
     hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
@@ -844,7 +880,7 @@ HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, REF
     if (ppv == NULL)
         return E_POINTER;
     *ppv = NULL;
-    ATLTRY(obj = new CComObject<T>);
+    ATLTRY(obj = new _CComObject<T>);
     if (obj.p == NULL)
         return E_OUTOFMEMORY;
     hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
@@ -870,7 +906,7 @@ HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, T4
     if (ppv == NULL)
         return E_POINTER;
     *ppv = NULL;
-    ATLTRY(obj = new CComObject<T>);
+    ATLTRY(obj = new _CComObject<T>);
     if (obj.p == NULL)
         return E_OUTOFMEMORY;
     hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));