[RSHELL]
authorDavid Quintana <gigaherz@gmail.com>
Mon, 20 Oct 2014 21:09:55 +0000 (21:09 +0000)
committerDavid Quintana <gigaherz@gmail.com>
Mon, 20 Oct 2014 21:09:55 +0000 (21:09 +0000)
[SHELL32]
[BROWSEUI]
* Move undocshell.h to a shared location, and move some shared utility functions into it.
* Replace all the COM object constructor functions with generic equivalents.
* Fixes a big bunch of "problems" found by Coverity Scan, but I don't have the list of CID at the moment.

svn path=/branches/shell-experiments/; revision=64854

33 files changed:
base/shell/rshell/CMenuBand.cpp
base/shell/rshell/CMenuDeskBar.cpp
base/shell/rshell/CMenuSite.cpp
base/shell/rshell/CMergedFolder.cpp
base/shell/rshell/precomp.h
dll/win32/browseui/addressband.cpp
dll/win32/browseui/addresseditbox.cpp
dll/win32/browseui/bandproxy.cpp
dll/win32/browseui/basebar.cpp
dll/win32/browseui/basebarsite.cpp
dll/win32/browseui/brandband.cpp
dll/win32/browseui/internettoolbar.cpp
dll/win32/browseui/precomp.h
dll/win32/browseui/shellbrowser.cpp
dll/win32/browseui/toolsband.cpp
dll/win32/browseui/travellog.cpp
dll/win32/shell32/dataobject.cpp
dll/win32/shell32/enumidlist.cpp
dll/win32/shell32/extracticon.cpp
dll/win32/shell32/folders/admintools.cpp
dll/win32/shell32/folders/cpanel.cpp
dll/win32/shell32/folders/desktop.cpp
dll/win32/shell32/folders/fonts.cpp
dll/win32/shell32/folders/fs.cpp
dll/win32/shell32/folders/mycomp.cpp
dll/win32/shell32/folders/mydocuments.cpp
dll/win32/shell32/folders/printers.cpp
dll/win32/shell32/folders/recyclebin.cpp
dll/win32/shell32/openwithmenu.cpp
dll/win32/shell32/precomp.h
dll/win32/shell32/shellole.cpp
dll/win32/shell32/shlview.cpp
include/reactos/undocshell.h [moved from dll/win32/shell32/undocshell.h with 62% similarity]

index 932f161..4ea59fd 100644 (file)
@@ -35,27 +35,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(CMenuBand);
 extern "C"
 HRESULT WINAPI CMenuBand_Constructor(REFIID riid, LPVOID *ppv)
 {
-    HRESULT hr;
-#if USE_SYSTEM_MENUBAND
-    hr = CoCreateInstance(CLSID_MenuBand,
-        NULL,
-        CLSCTX_INPROC_SERVER,
-        riid, ppv);
-#else
-    *ppv = NULL;
-
-    CMenuBand * site = new CComObject<CMenuBand>();
-
-    if (!site)
-        return E_OUTOFMEMORY;
-
-    hr = site->QueryInterface(riid, ppv);
-
-    if (FAILED_UNEXPECTEDLY(hr))
-        delete site;
-#endif
-
-    return hr;
+    return ShellObjectCreator<CMenuBand>(riid, ppv);
 }
 
 CMenuBand::CMenuBand() :
index 91088f5..cef88c5 100644 (file)
@@ -30,27 +30,7 @@ const static GUID CGID_MenuDeskBar = { 0x5C9F0A12, 0x959E, 0x11D0, { 0xA3, 0xA4,
 extern "C"
 HRESULT WINAPI CMenuDeskBar_Constructor(REFIID riid, LPVOID *ppv)
 {
-    HRESULT hr;
-#if USE_SYSTEM_MENUDESKBAR
-    hr = CoCreateInstance(CLSID_MenuDeskBar,
-        NULL,
-        CLSCTX_INPROC_SERVER,
-        riid, ppv);
-#else
-    *ppv = NULL;
-
-    CMenuDeskBar * deskbar = new CComObject<CMenuDeskBar>();
-
-    if (!deskbar)
-        return E_OUTOFMEMORY;
-
-    hr = deskbar->QueryInterface(riid, ppv);
-
-    if (FAILED_UNEXPECTEDLY(hr))
-        delete deskbar;
-
-#endif
-    return hr;
+    return ShellObjectCreator<CMenuDeskBar>(riid, ppv);
 }
 
 CMenuDeskBar::CMenuDeskBar() :
index 384b37a..fe0a52d 100644 (file)
@@ -28,27 +28,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(menusite);
 extern "C"
 HRESULT WINAPI CMenuSite_Constructor(REFIID riid, LPVOID *ppv)
 {
-    HRESULT hr;
-#if USE_SYSTEM_MENUSITE
-    hr = CoCreateInstance(CLSID_MenuBandSite,
-        NULL,
-        CLSCTX_INPROC_SERVER,
-        riid, ppv);
-#else
-    *ppv = NULL;
-
-    CMenuSite * site = new CComObject<CMenuSite>();
-
-    if (!site)
-        return E_OUTOFMEMORY;
-
-    hr = site->QueryInterface(riid, ppv);
-
-    if (FAILED_UNEXPECTEDLY(hr))
-        delete site;
-#endif
-
-    return hr;
+    return ShellObjectCreator<CMenuSite>(riid, ppv);
 }
 
 CMenuSite::CMenuSite() :
index 32ca1cc..f39bac2 100644 (file)
@@ -356,20 +356,7 @@ HRESULT STDMETHODCALLTYPE CEnumMergedFolder::Clone(
 extern "C"
 HRESULT WINAPI CMergedFolder_Constructor(REFIID riid, LPVOID *ppv)
 {
-    *ppv = NULL;
-
-    CMergedFolder * fld = new CComObject<CMergedFolder>();
-
-    if (!fld)
-        return E_OUTOFMEMORY;
-
-    HRESULT hr;
-
-    hr = fld->QueryInterface(riid, ppv);
-    if (FAILED_UNEXPECTEDLY(hr))
-        delete fld;
-
-    return hr;
+    return ShellObjectCreator<CMergedFolder>(riid, ppv);
 }
 
 CMergedFolder::CMergedFolder() :
index ce2f0a4..d5fb9d6 100644 (file)
@@ -53,6 +53,8 @@
 
 #include <atlbase.h>
 #include <atlcom.h>
+#include <undocshell.h>
+
 #include <wine/debug.h>
 
 #if _MSC_VER
@@ -73,115 +75,3 @@ extern "C" HRESULT WINAPI CMenuSite_Wrapper(IBandSite * bs, REFIID riid, LPVOID
 extern "C" HRESULT WINAPI CMenuBand_Wrapper(IShellMenu * sm, REFIID riid, LPVOID *ppv);
 extern "C" HRESULT WINAPI CMergedFolder_Constructor(REFIID riid, LPVOID *ppv);
 extern "C" HRESULT WINAPI CStartMenuSite_Wrapper(ITrayPriv * trayPriv, REFIID riid, LPVOID *ppv);
-
-static __inline ULONG
-Win32DbgPrint(const char *filename, int line, const char *lpFormat, ...)
-{
-    char szMsg[512];
-    char *szMsgStart;
-    const char *fname;
-    va_list vl;
-    ULONG uRet;
-
-    fname = strrchr(filename, '\\');
-    if (fname == NULL)
-    {
-        fname = strrchr(filename, '/');
-    }
-
-    if (fname == NULL)
-        fname = filename;
-    else
-        fname++;
-
-    szMsgStart = szMsg + sprintf(szMsg, "[%10lu] %s:%d: ", GetTickCount(), fname, line);
-
-    va_start(vl, lpFormat);
-    uRet = (ULONG) vsprintf(szMsgStart, lpFormat, vl);
-    va_end(vl);
-
-    OutputDebugStringA(szMsg);
-
-    return uRet;
-}
-
-#define DbgPrint(fmt, ...) \
-    Win32DbgPrint(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
-
-#if 1
-#define FAILED_UNEXPECTEDLY(hr) (FAILED(hr) && (DbgPrint("Unexpected failure %08x.\n", hr), TRUE))
-#else
-#define FAILED_UNEXPECTEDLY(hr) FAILED(hr)
-#endif
-
-
-template <class Base>
-class CComDebugObject : public Base
-{
-public:
-    CComDebugObject(void * = NULL)
-    {
-        _pAtlModule->Lock();
-    }
-
-    virtual ~CComDebugObject()
-    {
-        this->FinalRelease();
-        _pAtlModule->Unlock();
-    }
-
-    STDMETHOD_(ULONG, AddRef)()
-    {
-        int rc = this->InternalAddRef();
-        DbgPrint("RefCount is now %d(++)!\n", rc);
-        return rc;
-    }
-
-    STDMETHOD_(ULONG, Release)()
-    {
-        ULONG                                                          newRefCount;
-
-        newRefCount = this->InternalRelease();
-        DbgPrint("RefCount is now %d(--)!\n", newRefCount);
-        if (newRefCount == 0)
-            delete this;
-        return newRefCount;
-    }
-
-    STDMETHOD(QueryInterface)(REFIID iid, void **ppvObject)
-    {
-        return this->_InternalQueryInterface(iid, ppvObject);
-    }
-
-    static HRESULT WINAPI CreateInstance(CComDebugObject<Base> **pp)
-    {
-        CComDebugObject<Base>                          *newInstance;
-        HRESULT                                                                hResult;
-
-        ATLASSERT(pp != NULL);
-        if (pp == NULL)
-            return E_POINTER;
-
-        hResult = E_OUTOFMEMORY;
-        newInstance = NULL;
-        ATLTRY(newInstance = new CComDebugObject<Base>())
-            if (newInstance != NULL)
-            {
-            newInstance->SetVoid(NULL);
-            newInstance->InternalFinalConstructAddRef();
-            hResult = newInstance->_AtlInitialConstruct();
-            if (SUCCEEDED(hResult))
-                hResult = newInstance->FinalConstruct();
-            if (SUCCEEDED(hResult))
-                hResult = newInstance->_AtlFinalConstruct();
-            newInstance->InternalFinalConstructRelease();
-            if (hResult != S_OK)
-            {
-                delete newInstance;
-                newInstance = NULL;
-            }
-            }
-        *pp = newInstance;
-        return hResult;
-    }
-};
index 8e1f92e..2db3f4a 100644 (file)
@@ -668,20 +668,5 @@ LRESULT CAddressBand::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lPara
 
 HRESULT CreateAddressBand(REFIID riid, void **ppv)
 {
-    CAddressBand                *theMenuBar;
-    HRESULT                     hResult;
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY (theMenuBar = new CComObject<CAddressBand>);
-    if (theMenuBar == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theMenuBar->QueryInterface(riid, reinterpret_cast<void **>(ppv));
-    if (FAILED_UNEXPECTEDLY(hResult))
-    {
-        delete theMenuBar;
-        return hResult;
-    }
-    return S_OK;
+    return ShellObjectCreator<CAddressBand>(riid, ppv);
 }
index 78ff858..12b9d52 100644 (file)
@@ -283,20 +283,5 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::GetSizeMax(ULARGE_INTEGER *pcbSize)
 
 HRESULT CreateAddressEditBox(REFIID riid, void **ppv)
 {
-    CComObject<CAddressEditBox>             *theMenuBar;
-    HRESULT                                 hResult;
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY (theMenuBar = new CComObject<CAddressEditBox>);
-    if (theMenuBar == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theMenuBar->QueryInterface(riid, reinterpret_cast<void **>(ppv));
-    if (FAILED_UNEXPECTEDLY(hResult))
-    {
-        delete theMenuBar;
-        return hResult;
-    }
-    return S_OK;
+    return ShellObjectCreator<CAddressEditBox>(riid, ppv);
 }
index 060add9..4da31b2 100644 (file)
@@ -133,20 +133,5 @@ HRESULT STDMETHODCALLTYPE CBandProxy::NavigateToURL(long paramC, long param10)
 
 HRESULT CreateBandProxy(REFIID riid, void **ppv)
 {
-    CComObject<CBandProxy>                  *theBandProxy;
-    HRESULT                                 hResult;
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY (theBandProxy = new CComObject<CBandProxy>);
-    if (theBandProxy == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theBandProxy->QueryInterface(riid, reinterpret_cast<void **>(ppv));
-    if (FAILED_UNEXPECTEDLY(hResult))
-    {
-        delete theBandProxy;
-        return hResult;
-    }
-    return S_OK;
+    return ShellObjectCreator<CBandProxy>(riid, ppv);
 }
index e745f05..a178c4b 100644 (file)
@@ -514,20 +514,5 @@ LRESULT CBaseBar::OnCaptureChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
 
 HRESULT CreateBaseBar(REFIID riid, void **ppv)
 {
-    CComObject<CBaseBar>                    *theBaseBar;
-    HRESULT                                 hResult;
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY (theBaseBar = new CComObject<CBaseBar>);
-    if (theBaseBar == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theBaseBar->QueryInterface (riid, reinterpret_cast<void **>(ppv));
-    if (FAILED_UNEXPECTEDLY(hResult))
-    {
-        delete theBaseBar;
-        return hResult;
-    }
-    return S_OK;
+    return ShellObjectCreator<CBaseBar>(riid, ppv);
 }
index 60fc47f..2912ca1 100644 (file)
@@ -477,20 +477,5 @@ LRESULT CBaseBarSite::OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bH
 
 HRESULT CreateBaseBarSite(REFIID riid, void **ppv)
 {
-    CComObject<CBaseBarSite>                *theBaseBarSite;
-    HRESULT                                 hResult;
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY (theBaseBarSite = new CComObject<CBaseBarSite>);
-    if (theBaseBarSite == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theBaseBarSite->QueryInterface(riid, reinterpret_cast<void **>(ppv));
-    if (FAILED_UNEXPECTEDLY(hResult))
-    {
-        delete theBaseBarSite;
-        return hResult;
-    }
-    return S_OK;
+    return ShellObjectCreator<CBaseBarSite>(riid, ppv);
 }
index 4008493..223d558 100644 (file)
@@ -470,20 +470,5 @@ LRESULT CBrandBand::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHand
 
 HRESULT CreateBrandBand(REFIID riid, void **ppv)
 {
-    CComObject<CBrandBand>                  *theMenuBar;
-    HRESULT                                 hResult;
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY (theMenuBar = new CComObject<CBrandBand>);
-    if (theMenuBar == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theMenuBar->QueryInterface(riid, reinterpret_cast<void **>(ppv));
-    if (FAILED_UNEXPECTEDLY(hResult))
-    {
-        delete theMenuBar;
-        return hResult;
-    }
-    return S_OK;
+    return ShellObjectCreator<CBrandBand>(riid, ppv);
 }
index 053690e..bcfcb06 100644 (file)
@@ -437,7 +437,11 @@ static HRESULT GetFavoritesFolder(IShellFolder ** ppsfFavorites, LPITEMIDLIST *
     CComPtr<IShellFolder> psfCommonFavorites;
     CComPtr<IAugmentedShellFolder> pasf;
 
-    *ppsfFavorites = NULL;
+    if (ppsfFavorites)
+        *ppsfFavorites = NULL;
+    
+    if (ppidl)
+        *ppidl = NULL;
 
     hr = SHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidlUserFavorites);
     if (FAILED(hr))
@@ -499,6 +503,8 @@ static HRESULT GetFavoritesFolder(IShellFolder ** ppsfFavorites, LPITEMIDLIST *
     hr = pasf->QueryInterface(IID_PPV_ARG(IShellFolder, ppsfFavorites));
     pasf.Release();
 
+    // TODO: obtain the folder's PIDL
+
     ILFree(pidlCommonFavorites);
     ILFree(pidlUserFavorites);
 
@@ -578,7 +584,8 @@ HRESULT STDMETHODCALLTYPE CMenuCallback::GetObject(LPSMDATA psmd, REFIID riid, v
             return hResult;
 
         hResult = newMenu->SetShellFolder(favoritesFolder, favoritesPIDL, orderRegKey, SMSET_BOTTOM | SMINIT_CACHED | SMINV_ID);
-        ILFree(favoritesPIDL);
+        if (favoritesPIDL)
+            ILFree(favoritesPIDL);
         if (SUCCEEDED(hResult))
             fFavoritesMenu.Attach(newMenu.Detach());
     }
@@ -1989,20 +1996,5 @@ LRESULT CInternetToolbar::OnLUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &b
 
 HRESULT CreateInternetToolbar(REFIID riid, void **ppv)
 {
-    CInternetToolbar            *theToolbar;
-    HRESULT                     hResult;
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY (theToolbar = new CComObject<CInternetToolbar>);
-    if (theToolbar == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theToolbar->QueryInterface (riid, reinterpret_cast<void **>(ppv));
-    if (FAILED_UNEXPECTEDLY(hResult))
-    {
-        delete theToolbar;
-        return hResult;
-    }
-    return S_OK;
+    return ShellObjectCreator<CInternetToolbar>(riid, ppv);
 }
index 21ce5e3..49ce44c 100644 (file)
@@ -23,6 +23,7 @@
 #include <exdispid.h>
 #include <shlwapi.h>
 #include <shlwapi_undoc.h>
+#include <undocshell.h>
 #include <wine/debug.h>
 
 #include "resource.h"
 #include "regtreeoptions.h"
 #include <stdio.h>
 
-static __inline ULONG
-Win32DbgPrint(const char *filename, int line, const char *lpFormat, ...)
-{
-    char szMsg[512];
-    char *szMsgStart;
-    const char *fname;
-    va_list vl;
-    ULONG uRet;
-
-    fname = strrchr(filename, '\\');
-    if (fname == NULL)
-    {
-        fname = strrchr(filename, '/');
-        if (fname != NULL)
-            fname++;
-    }
-    else
-        fname++;
-
-    if (fname == NULL)
-        fname = filename;
-
-    szMsgStart = szMsg + sprintf(szMsg, "%s:%d: ", fname, line);
-
-    va_start(vl, lpFormat);
-    uRet = (ULONG) vsprintf(szMsgStart, lpFormat, vl);
-    va_end(vl);
-
-    OutputDebugStringA(szMsg);
-
-    return uRet;
-}
-
-#define DbgPrint(fmt, ...) \
-    Win32DbgPrint(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
-
-static void DbgDumpMenuInternal(HMENU hmenu, char* padding, int padlevel)
-{
-    WCHAR label[128];
-
-    padding[padlevel] = '.';
-    padding[padlevel + 1] = '.';
-    padding[padlevel + 2] = 0;
-
-    int count = GetMenuItemCount(hmenu);
-    for (int i = 0; i < count; i++)
-    {
-        MENUITEMINFOW mii = { 0 };
-
-        mii.cbSize = sizeof(mii);
-        mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU | MIIM_STATE | MIIM_ID;
-        mii.dwTypeData = label;
-        mii.cch = _countof(label);
-
-        GetMenuItemInfo(hmenu, i, TRUE, &mii);
-
-        if (mii.fType & MFT_BITMAP)
-            DbgPrint("%s%2d - %08x: BITMAP %08p (state=%d, has submenu=%s)\n", padding, i, mii.wID, mii.hbmpItem, mii.fState, mii.hSubMenu ? "TRUE" : "FALSE");
-        else if (mii.fType & MFT_SEPARATOR)
-            DbgPrint("%s%2d - %08x ---SEPARATOR---\n", padding, i, mii.wID);
-        else
-            DbgPrint("%s%2d - %08x: %S (state=%d, has submenu=%s)\n", padding, i, mii.wID, mii.dwTypeData, mii.fState, mii.hSubMenu ? "TRUE" : "FALSE");
-
-        if (mii.hSubMenu)
-            DbgDumpMenuInternal(mii.hSubMenu, padding, padlevel + 2);
-
-    }
-
-    padding[padlevel] = 0;
-}
-
-static __inline void DbgDumpMenu(HMENU hmenu)
-{
-    char padding[128];
-    DbgDumpMenuInternal(hmenu, padding, 0);
-}
-
-#if 1
-#define FAILED_UNEXPECTEDLY(hr) (FAILED(hr) && (DbgPrint("Unexpected failure %08x.\n", hr), TRUE))
-#else
-#define FAILED_UNEXPECTEDLY(hr) FAILED(hr)
-#endif
-
-
-template <class Base>
-class CComDebugObject : public Base
-{
-public:
-    CComDebugObject(void * = NULL)
-    {
-        _pAtlModule->Lock();
-    }
-
-    virtual ~CComDebugObject()
-    {
-        this->FinalRelease();
-        _pAtlModule->Unlock();
-    }
-
-    STDMETHOD_(ULONG, AddRef)()
-    {
-        int rc = this->InternalAddRef();
-        DbgPrint("RefCount is now %d(++)!\n", rc);
-        return rc;
-    }
-
-    STDMETHOD_(ULONG, Release)()
-    {
-        ULONG                                                          newRefCount;
-
-        newRefCount = this->InternalRelease();
-        DbgPrint("RefCount is now %d(--)!\n", newRefCount);
-        if (newRefCount == 0)
-            delete this;
-        return newRefCount;
-    }
-
-    STDMETHOD(QueryInterface)(REFIID iid, void **ppvObject)
-    {
-        return this->_InternalQueryInterface(iid, ppvObject);
-    }
-
-    static HRESULT WINAPI CreateInstance(CComDebugObject<Base> **pp)
-    {
-        CComDebugObject<Base>                          *newInstance;
-        HRESULT                                                                hResult;
-
-        ATLASSERT(pp != NULL);
-        if (pp == NULL)
-            return E_POINTER;
-
-        hResult = E_OUTOFMEMORY;
-        newInstance = NULL;
-        ATLTRY(newInstance = new CComDebugObject<Base>())
-            if (newInstance != NULL)
-            {
-            newInstance->SetVoid(NULL);
-            newInstance->InternalFinalConstructAddRef();
-            hResult = newInstance->_AtlInitialConstruct();
-            if (SUCCEEDED(hResult))
-                hResult = newInstance->FinalConstruct();
-            if (SUCCEEDED(hResult))
-                hResult = newInstance->_AtlFinalConstruct();
-            newInstance->InternalFinalConstructRelease();
-            if (hResult != S_OK)
-            {
-                delete newInstance;
-                newInstance = NULL;
-            }
-            }
-        *pp = newInstance;
-        return hResult;
-    }
-};
-
 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
 
 #endif /* _BROWSEUI_PCH_ */
index c738f24..ea02d0c 100644 (file)
@@ -3431,15 +3431,11 @@ static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters)
             DispatchMessage(&Msg);
         }
     }
-    
-    //TerminateProcess(GetCurrentProcess(), hResult);
 
     int nrc = theCabinet->Release();
     if (nrc > 0)
     {
-        DbgPrint("WARNING: There are %d references to the CShellBrowser active or leaked, process will never terminate. Terminating forcefully.\n", nrc);
-
-        //TerminateProcess(GetCurrentProcess(), 1);
+        DbgPrint("WARNING: There are %d references to the CShellBrowser active or leaked.\n", nrc);
     }
 
     theCabinet.Detach();
index abad2d6..0410109 100644 (file)
@@ -313,15 +313,11 @@ HRESULT STDMETHODCALLTYPE CToolsBand::SetSite(IUnknown* pUnkSite){
         BITMAP bitmapInfo;
         GetObjectW(imgNormal, sizeof(bitmapInfo), &bitmapInfo);
         HIMAGELIST himlNormal = ImageList_Create(bitmapInfo.bmHeight, bitmapInfo.bmHeight, ILC_COLOR32, 4, 4);
-
         ImageList_Add(himlNormal, imgNormal, NULL);
-        DeleteObject(imgNormal);
 
         GetObjectW(imgHot, sizeof(bitmapInfo), &bitmapInfo);
         HIMAGELIST himlHot = ImageList_Create(bitmapInfo.bmHeight, bitmapInfo.bmHeight, ILC_COLOR32, 4, 4);
-
         ImageList_Add(himlHot, imgHot, NULL);
-        DeleteObject(imgHot);
 
         SendMessage(TB_SETIMAGELIST, 0, (LPARAM) himlNormal);
         SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM) himlHot);
@@ -329,6 +325,11 @@ HRESULT STDMETHODCALLTYPE CToolsBand::SetSite(IUnknown* pUnkSite){
 
     SendMessage(TB_ADDBUTTONSW, numShownButtons, (LPARAM)&tbButtonsAdd);
 
+    if (imgNormal)
+        DeleteObject(imgNormal);
+    if (imgHot)
+        DeleteObject(imgHot);
+    
     return hResult;
 }
 
@@ -440,21 +441,6 @@ LRESULT CToolsBand::OnGetButtonInfo(UINT idControl, NMHDR *pNMHDR, BOOL &bHandle
 
 HRESULT CreateToolsBar(REFIID riid, void **ppv)
 {
-    CToolsBand                  *theToolbar;
-    HRESULT                     hResult;
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY(theToolbar = new CComObject<CToolsBand>);
-    if (theToolbar == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theToolbar->QueryInterface(riid, reinterpret_cast<void **>(ppv));
-    if (FAILED_UNEXPECTEDLY(hResult))
-    {
-        delete theToolbar;
-        return hResult;
-    }
-    return S_OK;
+    return ShellObjectCreator<CToolsBand>(riid, ppv);
 }
 
index 9fc6276..45bbaf2 100644 (file)
@@ -621,23 +621,5 @@ HRESULT STDMETHODCALLTYPE CTravelLog::Revert()
 
 HRESULT CreateTravelLog(REFIID riid, void **ppv)
 {
-    CComObject<CTravelLog>                  *theTravelLog;
-    HRESULT                                 hResult;
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY (theTravelLog = new CComObject<CTravelLog>);
-    if (theTravelLog == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theTravelLog->QueryInterface(riid, reinterpret_cast<void **>(ppv));
-    if (FAILED_UNEXPECTEDLY(hResult))
-    {
-        delete theTravelLog;
-        return hResult;
-    }
-    hResult = theTravelLog->Initialize();
-    if (FAILED_UNEXPECTEDLY(hResult))
-        return hResult;
-    return S_OK;
+    return ShellObjectCreatorInit<CTravelLog>(riid, ppv);
 }
index 88f10fb..f0bab7f 100644 (file)
@@ -127,30 +127,9 @@ HRESULT WINAPI IEnumFORMATETCImpl::Clone(LPENUMFORMATETC* ppenum)
     return (*ppenum)->Skip(posFmt);
 }
 
-HRESULT IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[], IEnumFORMATETC **enumerator)
+HRESULT IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[], IEnumFORMATETC **ppFormat)
 {
-    CComObject<IEnumFORMATETCImpl>            *theEnumerator;
-    CComPtr<IEnumFORMATETC>                    result;
-    HRESULT                                    hResult;
-
-    if (enumerator == NULL)
-        return E_POINTER;
-    *enumerator = NULL;
-    ATLTRY (theEnumerator = new CComObject<IEnumFORMATETCImpl>);
-    if (theEnumerator == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theEnumerator->QueryInterface (IID_PPV_ARG(IEnumFORMATETC, &result));
-    if (FAILED (hResult))
-    {
-        delete theEnumerator;
-        return hResult;
-    }
-    hResult = theEnumerator->Initialize (cfmt, afmt);
-    if (FAILED (hResult))
-        return hResult;
-    *enumerator = result.Detach ();
-    TRACE("(%p)->(%u,%p)\n", *enumerator, cfmt, afmt);
-    return S_OK;
+    return ShellObjectCreatorInit<IEnumFORMATETCImpl>(cfmt, afmt, IID_IEnumFORMATETC, ppFormat);
 }
 
 
@@ -416,28 +395,7 @@ HRESULT WINAPI IDataObjectImpl::EndOperation(HRESULT hResult, IBindCtx *pbcReser
 */
 HRESULT IDataObject_Constructor(HWND hwndOwner, LPCITEMIDLIST pMyPidl, LPCITEMIDLIST * apidl, UINT cidl, IDataObject **dataObject)
 {
-    CComObject<IDataObjectImpl>                *theDataObject;
-    CComPtr<IDataObject>                    result;
-    HRESULT                                    hResult;
-
-    if (dataObject == NULL)
-        return E_POINTER;
-    *dataObject = NULL;
-    ATLTRY (theDataObject = new CComObject<IDataObjectImpl>);
-    if (theDataObject == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theDataObject->QueryInterface(IID_PPV_ARG(IDataObject, &result));
-    if (FAILED (hResult))
-    {
-        delete theDataObject;
-        return hResult;
-    }
-    hResult = theDataObject->Initialize (hwndOwner, pMyPidl, apidl, cidl);
-    if (FAILED (hResult))
-        return hResult;
-    *dataObject = result.Detach ();
-    TRACE("(%p)->(apidl=%p cidl=%u)\n", *dataObject,  apidl, cidl);
-    return S_OK;
+    return ShellObjectCreatorInit<IDataObjectImpl>(hwndOwner, pMyPidl, apidl, cidl, IID_IDataObject, dataObject);
 }
 
 /*************************************************************************
index ee7394e..3086928 100644 (file)
@@ -281,22 +281,5 @@ HRESULT WINAPI IEnumIDListImpl::Clone(LPENUMIDLIST *ppenum)
  */
 HRESULT IEnumIDList_Constructor(IEnumIDList **enumerator)
 {
-    CComObject<IEnumIDListImpl>                *theEnumerator;
-    CComPtr<IEnumIDList>                    result;
-    HRESULT                                    hResult;
-
-    if (enumerator == NULL)
-        return E_POINTER;
-    *enumerator = NULL;
-    ATLTRY (theEnumerator = new CComObject<IEnumIDListImpl>);
-    if (theEnumerator == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theEnumerator->QueryInterface(IID_PPV_ARG(IEnumIDList, &result));
-    if (FAILED (hResult))
-    {
-        delete theEnumerator;
-        return hResult;
-    }
-    *enumerator = result.Detach ();
-    return S_OK;
+    return ShellObjectCreator<IEnumIDListImpl>(IID_IEnumIDList, enumerator);
 }
index 80c65d5..26a0600 100644 (file)
@@ -337,22 +337,5 @@ HRESULT STDMETHODCALLTYPE IconExtraction::GetCurFile(
 
 HRESULT WINAPI SHCreateDefaultExtractIcon(REFIID riid, void **ppv)
 {
-    CComObject<IconExtraction>                *theExtractor;
-    CComPtr<IUnknown>                        result;
-    HRESULT                                    hResult;
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY (theExtractor = new CComObject<IconExtraction>);
-    if (theExtractor == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theExtractor->QueryInterface (riid, (void **)&result);
-    if (FAILED (hResult))
-    {
-        delete theExtractor;
-        return hResult;
-    }
-    *ppv = result.Detach ();
-    return S_OK;
+    return ShellObjectCreator<IconExtraction>(riid, ppv);
 }
index b742d99..cac2f58 100644 (file)
@@ -136,32 +136,7 @@ HRESULT WINAPI CAdminToolsFolder::ParseDisplayName(HWND hwndOwner, LPBC pbc, LPO
  */
 HRESULT WINAPI CAdminToolsFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
 {
-    CComObject<CDesktopFolderEnumY>        *theEnumerator;
-    CComPtr<IEnumIDList>                    result;
-    HRESULT                                 hResult;
-
-    TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", this, hwndOwner, dwFlags, ppEnumIDList);
-
-    if (ppEnumIDList == NULL)
-        return E_POINTER;
-    *ppEnumIDList = NULL;
-    ATLTRY (theEnumerator = new CComObject<CDesktopFolderEnumY>);
-    if (theEnumerator == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theEnumerator->QueryInterface(IID_PPV_ARG(IEnumIDList, &result));
-    if (FAILED (hResult))
-    {
-        delete theEnumerator;
-        return hResult;
-    }
-    hResult = theEnumerator->Initialize (szTarget, dwFlags);
-    if (FAILED (hResult))
-        return hResult;
-    *ppEnumIDList = result.Detach ();
-
-    TRACE ("-- (%p)->(new ID List: %p)\n", this, *ppEnumIDList);
-
-    return S_OK;
+    return ShellObjectCreatorInit<CDesktopFolderEnumY>(szTarget, dwFlags, IID_IEnumIDList, ppEnumIDList);
 }
 
 /**************************************************************************
index 01aaf99..1033450 100644 (file)
@@ -371,37 +371,9 @@ HRESULT WINAPI CControlPanelFolder::ParseDisplayName(
 /**************************************************************************
 *        CControlPanelFolder::EnumObjects
 */
-HRESULT WINAPI CControlPanelFolder::EnumObjects(
-    HWND hwndOwner,
-    DWORD dwFlags,
-    LPENUMIDLIST *ppEnumIDList)
+HRESULT WINAPI CControlPanelFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
 {
-    CComObject<CControlPanelEnum>            *theEnumerator;
-    CComPtr<IEnumIDList>                    result;
-    HRESULT                                    hResult;
-
-    TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", this, hwndOwner, dwFlags, ppEnumIDList);
-
-    if (ppEnumIDList == NULL)
-        return E_POINTER;
-    *ppEnumIDList = NULL;
-    ATLTRY (theEnumerator = new CComObject<CControlPanelEnum>);
-    if (theEnumerator == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theEnumerator->QueryInterface(IID_PPV_ARG(IEnumIDList, &result));
-    if (FAILED (hResult))
-    {
-        delete theEnumerator;
-        return hResult;
-    }
-    hResult = theEnumerator->Initialize (dwFlags);
-    if (FAILED (hResult))
-        return hResult;
-    *ppEnumIDList = result.Detach ();
-
-    TRACE ("-- (%p)->(new ID List: %p)\n", this, *ppEnumIDList);
-
-    return S_OK;
+    return ShellObjectCreatorInit<CControlPanelEnum>(dwFlags, IID_IEnumIDList, ppEnumIDList);
 }
 
 /**************************************************************************
index 5ed78a2..119df7a 100644 (file)
@@ -421,41 +421,9 @@ HRESULT WINAPI CDesktopFolder::ParseDisplayName(
 /**************************************************************************
  *        CDesktopFolder::EnumObjects
  */
-HRESULT WINAPI CDesktopFolder::EnumObjects(
-    HWND hwndOwner,
-    DWORD dwFlags,
-    LPENUMIDLIST *ppEnumIDList)
+HRESULT WINAPI CDesktopFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
 {
-    CComObject<CDesktopFolderEnum>            *theEnumerator;
-    CComPtr<IEnumIDList>                    result;
-    HRESULT                                    hResult;
-
-    TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", this, hwndOwner, dwFlags, ppEnumIDList);
-
-    if (ppEnumIDList == NULL)
-        return E_POINTER;
-    *ppEnumIDList = NULL;
-
-    ATLTRY (theEnumerator = new CComObject<CDesktopFolderEnum>);
-
-    if (theEnumerator == NULL)
-        return E_OUTOFMEMORY;
-
-    hResult = theEnumerator->QueryInterface(IID_PPV_ARG(IEnumIDList, &result));
-    if (FAILED (hResult))
-    {
-        delete theEnumerator;
-        return hResult;
-    }
-
-    hResult = theEnumerator->Initialize (this, hwndOwner, dwFlags);
-    if (FAILED (hResult))
-        return hResult;
-    *ppEnumIDList = result.Detach ();
-
-    TRACE ("-- (%p)->(new ID List: %p)\n", this, *ppEnumIDList);
-
-    return S_OK;
+    return ShellObjectCreatorInit<CDesktopFolderEnum>(this, hwndOwner, dwFlags, IID_IEnumIDList, ppEnumIDList);
 }
 
 /**************************************************************************
index 236b84a..218d46e 100644 (file)
@@ -219,32 +219,7 @@ HRESULT WINAPI CFontsFolder::ParseDisplayName(
 */
 HRESULT WINAPI CFontsFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
 {
-    CComObject<CDesktopFolderEnumZ>            *theEnumerator;
-    CComPtr<IEnumIDList>                    result;
-    HRESULT                                    hResult;
-
-    TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", this, hwndOwner, dwFlags, ppEnumIDList);
-
-    if (ppEnumIDList == NULL)
-        return E_POINTER;
-    *ppEnumIDList = NULL;
-    ATLTRY (theEnumerator = new CComObject<CDesktopFolderEnumZ>);
-    if (theEnumerator == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theEnumerator->QueryInterface(IID_PPV_ARG(IEnumIDList, &result));
-    if (FAILED (hResult))
-    {
-        delete theEnumerator;
-        return hResult;
-    }
-    hResult = theEnumerator->Initialize (dwFlags);
-    if (FAILED (hResult))
-        return hResult;
-    *ppEnumIDList = result.Detach ();
-
-    TRACE ("-- (%p)->(new ID List: %p)\n", this, *ppEnumIDList);
-
-    return S_OK;
+    return ShellObjectCreatorInit<CDesktopFolderEnumZ>(dwFlags, IID_IEnumIDList, ppEnumIDList);
 }
 
 /**************************************************************************
index fd75611..e880021 100644 (file)
@@ -260,32 +260,7 @@ HRESULT WINAPI CFSFolder::EnumObjects(
     DWORD dwFlags,
     LPENUMIDLIST *ppEnumIDList)
 {
-    CComObject<CFileSysEnum> *theEnumerator;
-    CComPtr<IEnumIDList>      result;
-    HRESULT                   hResult;
-
-    TRACE("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", this, hwndOwner, dwFlags, ppEnumIDList);
-
-    if (ppEnumIDList == NULL)
-        return E_POINTER;
-    *ppEnumIDList = NULL;
-    ATLTRY (theEnumerator = new CComObject<CFileSysEnum>);
-    if (theEnumerator == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theEnumerator->QueryInterface(IID_PPV_ARG(IEnumIDList, &result));
-    if (FAILED(hResult))
-    {
-        delete theEnumerator;
-        return hResult;
-    }
-    hResult = theEnumerator->Initialize (sPathTarget, dwFlags);
-    if (FAILED (hResult))
-        return hResult;
-    *ppEnumIDList = result.Detach();
-
-    TRACE("-- (%p)->(new ID List: %p)\n", this, *ppEnumIDList);
-
-    return S_OK;
+    return ShellObjectCreatorInit<CFileSysEnum>(sPathTarget, dwFlags, IID_IEnumIDList, ppEnumIDList);
 }
 
 /**************************************************************************
index 9239977..828abac 100644 (file)
@@ -252,36 +252,7 @@ HRESULT WINAPI CDrivesFolder::ParseDisplayName(HWND hwndOwner, LPBC pbc, LPOLEST
 */
 HRESULT WINAPI CDrivesFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
 {
-    CComObject<CDrivesFolderEnum> *theEnumerator;
-    CComPtr<IEnumIDList>          result;
-    HRESULT                       hResult;
-
-    TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", this, hwndOwner, dwFlags, ppEnumIDList);
-
-    if (ppEnumIDList == NULL)
-        return E_POINTER;
-
-    *ppEnumIDList = NULL;
-    ATLTRY(theEnumerator = new CComObject<CDrivesFolderEnum>);
-
-    if (theEnumerator == NULL)
-        return E_OUTOFMEMORY;
-
-    hResult = theEnumerator->QueryInterface(IID_IEnumIDList, (void **)&result);
-    if (FAILED(hResult))
-    {
-        delete theEnumerator;
-        return hResult;
-    }
-
-    hResult = theEnumerator->Initialize(hwndOwner, dwFlags);
-    if (FAILED(hResult))
-        return hResult;
-    *ppEnumIDList = result.Detach();
-
-    TRACE("-- (%p)->(new ID List: %p)\n", this, *ppEnumIDList);
-
-    return S_OK;
+    return ShellObjectCreatorInit<CDrivesFolderEnum>(hwndOwner, dwFlags, IID_IEnumIDList, ppEnumIDList);
 }
 
 /**************************************************************************
index b610f4c..8d6eff9 100644 (file)
@@ -214,32 +214,7 @@ HRESULT WINAPI CMyDocsFolder::ParseDisplayName(HWND hwndOwner, LPBC pbc, LPOLEST
  */
 HRESULT WINAPI CMyDocsFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
 {
-    CComObject<CFileSysEnumX>                *theEnumerator;
-    CComPtr<IEnumIDList>                    result;
-    HRESULT                                    hResult;
-
-    TRACE("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", this, hwndOwner, dwFlags, ppEnumIDList);
-
-    if (ppEnumIDList == NULL)
-        return E_POINTER;
-    *ppEnumIDList = NULL;
-    ATLTRY (theEnumerator = new CComObject<CFileSysEnumX>);
-    if (theEnumerator == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theEnumerator->QueryInterface(IID_IEnumIDList, (void **)&result);
-    if (FAILED (hResult))
-    {
-        delete theEnumerator;
-        return hResult;
-    }
-    hResult = theEnumerator->Initialize(dwFlags);
-    if (FAILED (hResult))
-        return hResult;
-    *ppEnumIDList = result.Detach();
-
-    TRACE("-- (%p)->(new ID List: %p)\n", this, *ppEnumIDList);
-
-    return S_OK;
+    return ShellObjectCreatorInit<CFileSysEnumX>(dwFlags, IID_IEnumIDList, ppEnumIDList);
 }
 
 /**************************************************************************
index 2e794af..689434b 100644 (file)
@@ -185,27 +185,7 @@ HRESULT WINAPI CPrintersExtractIconW::Extract(LPCSTR pszFile,
  */
 static HRESULT WINAPI IEI_Printers_Constructor(LPCITEMIDLIST pidl, REFIID riid, IUnknown **ppv)
 {
-    CComObject<CPrintersExtractIconW> *theExtractor;
-    CComPtr<IUnknown>                 result;
-    HRESULT                           hResult;
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY (theExtractor = new CComObject<CPrintersExtractIconW>);
-    if (theExtractor == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theExtractor->QueryInterface(riid, (void **)&result);
-    if (FAILED (hResult))
-    {
-        delete theExtractor;
-        return hResult;
-    }
-    hResult = theExtractor->Initialize(pidl);
-    if (FAILED (hResult))
-        return hResult;
-    *ppv = result.Detach();
-    return S_OK;
+    return ShellObjectCreatorInit<CPrintersExtractIconW>(pidl, riid, ppv);
 }
 
 /***********************************************************************
@@ -379,32 +359,7 @@ static PIDLPrinterStruct * _ILGetPrinterStruct(LPCITEMIDLIST pidl)
  */
 HRESULT WINAPI CPrinterFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
 {
-    CComObject<CPrintersEnum> *theEnumerator;
-    CComPtr<IEnumIDList>      result;
-    HRESULT                   hResult;
-
-    TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", this, hwndOwner, dwFlags, ppEnumIDList);
-
-    if (ppEnumIDList == NULL)
-        return E_POINTER;
-    *ppEnumIDList = NULL;
-    ATLTRY (theEnumerator = new CComObject<CPrintersEnum>);
-    if (theEnumerator == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theEnumerator->QueryInterface(IID_PPV_ARG(IEnumIDList, &result));
-    if (FAILED (hResult))
-    {
-        delete theEnumerator;
-        return hResult;
-    }
-    hResult = theEnumerator->Initialize(hwndOwner, dwFlags);
-    if (FAILED (hResult))
-        return hResult;
-    *ppEnumIDList = result.Detach();
-
-    TRACE ("-- (%p)->(new ID List: %p)\n", this, *ppEnumIDList);
-
-    return S_OK;
+    return ShellObjectCreatorInit<CPrintersEnum>(hwndOwner, dwFlags, IID_IEnumIDList, ppEnumIDList);
 }
 
 /**************************************************************************
index 19f9bbd..5266fad 100644 (file)
@@ -403,34 +403,6 @@ HRESULT WINAPI CRecycleBinItemContextMenu::HandleMenuMsg(UINT uMsg, WPARAM wPara
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI CRecycleBinItemContextMenuConstructor(REFIID riid, LPCITEMIDLIST pidl, LPVOID *ppv)
-{
-    CComObject<CRecycleBinItemContextMenu>    *theMenu;
-    CComPtr<IUnknown>                        result;
-    HRESULT                                    hResult;
-
-    TRACE("%s\n", shdebugstr_guid(&riid));
-
-    if (ppv == NULL)
-        return E_POINTER;
-    *ppv = NULL;
-    ATLTRY(theMenu = new CComObject<CRecycleBinItemContextMenu>);
-    if (theMenu == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theMenu->QueryInterface(riid, (void **)&result);
-    if (FAILED(hResult))
-    {
-        delete theMenu;
-        return hResult;
-    }
-    hResult = theMenu->Initialize(pidl);
-    if (FAILED(hResult))
-        return hResult;
-    *ppv = result.Detach();
-    TRACE ("--(%p)\n", *ppv);
-    return S_OK;
-}
-
 /**************************************************************************
 * registers clipboardformat once
 */
@@ -509,32 +481,7 @@ UnpackDetailsFromPidl(LPCITEMIDLIST pidl)
 
 HRESULT WINAPI CRecycleBin::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
 {
-    CComObject<CRecycleBinEnum>                *theEnumerator;
-    CComPtr<IEnumIDList>                    result;
-    HRESULT                                    hResult;
-
-    TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", this, hwndOwner, dwFlags, ppEnumIDList);
-
-    if (ppEnumIDList == NULL)
-        return E_POINTER;
-    *ppEnumIDList = NULL;
-    ATLTRY (theEnumerator = new CComObject<CRecycleBinEnum>);
-    if (theEnumerator == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theEnumerator->QueryInterface(IID_PPV_ARG(IEnumIDList, &result));
-    if (FAILED (hResult))
-    {
-        delete theEnumerator;
-        return hResult;
-    }
-    hResult = theEnumerator->Initialize(dwFlags);
-    if (FAILED (hResult))
-        return hResult;
-    *ppEnumIDList = result.Detach();
-
-    TRACE ("-- (%p)->(new ID List: %p)\n", this, *ppEnumIDList);
-
-    return S_OK;
+    return ShellObjectCreatorInit<CRecycleBinEnum>(dwFlags, IID_IEnumIDList, ppEnumIDList);
 }
 
 HRESULT WINAPI CRecycleBin::BindToObject(PCUIDLIST_RELATIVE pidl, LPBC pbc, REFIID riid, void **ppv)
@@ -617,12 +564,12 @@ HRESULT WINAPI CRecycleBin::GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_C
 
     if ((IsEqualIID (riid, IID_IContextMenu) || IsEqualIID(riid, IID_IContextMenu2)) && (cidl >= 1))
     {
-        hr = CRecycleBinItemContextMenuConstructor(riid, apidl[0], (void **)&pObj);
+        hr = ShellObjectCreatorInit<CRecycleBinItemContextMenu>(apidl[0], riid, &pObj);
     }
     else if (IsEqualIID (riid, IID_IDropTarget) && (cidl == 1))
     {
         IDropTarget * pDt = NULL;
-        hr = this->QueryInterface(IID_PPV_ARG(IDropTarget, &pDt));
+        hr = QueryInterface(IID_PPV_ARG(IDropTarget, &pDt));
         pObj = pDt;
     }
     else
index a2033f8..70495d4 100644 (file)
@@ -1376,7 +1376,6 @@ SHOpenWithDialog(HWND hwndParent, const OPENASINFO *poainfo)
 {
     MSG msg;
     HWND hwnd;
-    COpenWithDialog *pDialog;
 
     TRACE("SHOpenWithDialog hwndParent %p poainfo %p\n", hwndParent, poainfo);
 
@@ -1385,11 +1384,9 @@ SHOpenWithDialog(HWND hwndParent, const OPENASINFO *poainfo)
     if (poainfo->pcszClass == NULL && poainfo->pcszFile == NULL)
         return E_FAIL;
 
-    pDialog = new COpenWithDialog(poainfo);
-    if (!pDialog)
-        return E_OUTOFMEMORY;
+    COpenWithDialog pDialog(poainfo);
 
-    hwnd = CreateDialogParam(shell32_hInstance, MAKEINTRESOURCE(IDD_OPEN_WITH), hwndParent, COpenWithDialog::DialogProc, (LPARAM)pDialog);
+    hwnd = CreateDialogParam(shell32_hInstance, MAKEINTRESOURCE(IDD_OPEN_WITH), hwndParent, COpenWithDialog::DialogProc, (LPARAM)&pDialog);
     if (hwnd == NULL)
     {
         ERR("Failed to create dialog\n");
@@ -1407,7 +1404,5 @@ SHOpenWithDialog(HWND hwndParent, const OPENASINFO *poainfo)
         }
     }
 
-    delete pDialog;
-
     return S_OK;
 }
index 285472d..60198c9 100644 (file)
@@ -30,6 +30,7 @@
 #include <atlbase.h>
 #include <atlcom.h>
 #include <powrprof.h>
+#include <undocshell.h>
 
 //#include "base/shell/explorer-new/todo.h"
 //#include "dlgs.h"
index 884ab67..6690996 100644 (file)
@@ -376,27 +376,7 @@ HRESULT WINAPI IDefClFImpl::LockServer(BOOL fLock)
 
 HRESULT IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, const IID *riidInst, IClassFactory **theFactory)
 {
-    CComObject<IDefClFImpl>                    *theClassObject;
-    CComPtr<IClassFactory>                    result;
-    HRESULT                                    hResult;
-
-    if (theFactory == NULL)
-        return E_POINTER;
-    *theFactory = NULL;
-    ATLTRY (theClassObject = new CComObject<IDefClFImpl>);
-    if (theClassObject == NULL)
-        return E_OUTOFMEMORY;
-    hResult = theClassObject->QueryInterface (IID_PPV_ARG(IClassFactory, &result));
-    if (FAILED (hResult))
-    {
-        delete theClassObject;
-        return hResult;
-    }
-    hResult = theClassObject->Initialize (lpfnCI, pcRefDll, riidInst);
-    if (FAILED (hResult))
-        return hResult;
-    *theFactory = result.Detach ();
-    return S_OK;
+    return ShellObjectCreatorInit<IDefClFImpl>(lpfnCI, pcRefDll, riidInst, IID_IClassFactory, theFactory);
 }
 
 /******************************************************************************
index 3633b28..333917f 100644 (file)
@@ -2974,30 +2974,5 @@ HRESULT CDefView::_MergeToolbar()
  */
 HRESULT WINAPI IShellView_Constructor(IShellFolder *pFolder, IShellView **newView)
 {
-    CComObject<CDefView>                    *theView;
-    CComPtr<IShellView>                        result;
-    HRESULT                                    hResult;
-
-    if (newView == NULL)
-        return E_POINTER;
-
-    *newView = NULL;
-    ATLTRY (theView = new CComObject<CDefView>);
-
-    if (theView == NULL)
-        return E_OUTOFMEMORY;
-
-    hResult = theView->QueryInterface(IID_PPV_ARG(IShellView, &result));
-    if (FAILED (hResult))
-    {
-        delete theView;
-        return hResult;
-    }
-
-    hResult = theView->Initialize (pFolder);
-    if (FAILED (hResult))
-        return hResult;
-    *newView = result.Detach ();
-
-    return S_OK;
+    return ShellObjectCreatorInit<CDefView>(pFolder, IID_IShellView, newView);
 }
similarity index 62%
rename from dll/win32/shell32/undocshell.h
rename to include/reactos/undocshell.h
index dad99e0..e220433 100644 (file)
@@ -529,8 +529,315 @@ BOOL WINAPI SHDesktopMessageLoop(HANDLE);
 
 #define CSIDL_FOLDER_MASK      0x00ff
 
+/* Utility functions */
+#include <stdio.h>
+
+static inline ULONG
+Win32DbgPrint(const char *filename, int line, const char *lpFormat, ...)
+{
+    char szMsg[512];
+    char *szMsgStart;
+    const char *fname;
+    va_list vl;
+    ULONG uRet;
+
+    fname = strrchr(filename, '\\');
+    if (fname == NULL)
+    {
+        fname = strrchr(filename, '/');
+        if (fname != NULL)
+            fname++;
+    }
+    else
+        fname++;
+
+    if (fname == NULL)
+        fname = filename;
+
+    szMsgStart = szMsg + sprintf(szMsg, "%s:%d: ", fname, line);
+
+    va_start(vl, lpFormat);
+    uRet = (ULONG) vsprintf(szMsgStart, lpFormat, vl);
+    va_end(vl);
+
+    OutputDebugStringA(szMsg);
+
+    return uRet;
+}
+
+#define DbgPrint(fmt, ...) \
+    Win32DbgPrint(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
+
+static inline void DbgDumpMenuInternal(HMENU hmenu, char* padding, int padlevel)
+{
+    WCHAR label[128];
+
+    padding[padlevel] = '.';
+    padding[padlevel + 1] = '.';
+    padding[padlevel + 2] = 0;
+
+    int count = GetMenuItemCount(hmenu);
+    for (int i = 0; i < count; i++)
+    {
+        MENUITEMINFOW mii = { 0 };
+
+        mii.cbSize = sizeof(mii);
+        mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU | MIIM_STATE | MIIM_ID;
+        mii.dwTypeData = label;
+        mii.cch = _countof(label);
+
+        GetMenuItemInfo(hmenu, i, TRUE, &mii);
+
+        if (mii.fType & MFT_BITMAP)
+            DbgPrint("%s%2d - %08x: BITMAP %08p (state=%d, has submenu=%s)\n", padding, i, mii.wID, mii.hbmpItem, mii.fState, mii.hSubMenu ? "TRUE" : "FALSE");
+        else if (mii.fType & MFT_SEPARATOR)
+            DbgPrint("%s%2d - %08x ---SEPARATOR---\n", padding, i, mii.wID);
+        else
+            DbgPrint("%s%2d - %08x: %S (state=%d, has submenu=%s)\n", padding, i, mii.wID, mii.dwTypeData, mii.fState, mii.hSubMenu ? "TRUE" : "FALSE");
+
+        if (mii.hSubMenu)
+            DbgDumpMenuInternal(mii.hSubMenu, padding, padlevel + 2);
+
+    }
+
+    padding[padlevel] = 0;
+}
+
+static __inline void DbgDumpMenu(HMENU hmenu)
+{
+    char padding[128];
+    DbgDumpMenuInternal(hmenu, padding, 0);
+}
+
+#if 1
+#define FAILED_UNEXPECTEDLY(hr) (FAILED(hr) && (DbgPrint("Unexpected failure %08x.\n", hr), TRUE))
+#else
+#define FAILED_UNEXPECTEDLY(hr) FAILED(hr)
+#endif
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif /* defined(__cplusplus) */
 
+#ifdef __cplusplus
+template <class Base>
+class CComDebugObject : public Base
+{
+public:
+    CComDebugObject(void * = NULL)
+    {
+        _pAtlModule->Lock();
+    }
+
+    virtual ~CComDebugObject()
+    {
+        this->FinalRelease();
+        _pAtlModule->Unlock();
+    }
+
+    STDMETHOD_(ULONG, AddRef)()
+    {
+        int rc = this->InternalAddRef();
+        DbgPrint("RefCount is now %d(++)!\n", rc);
+        return rc;
+    }
+
+    STDMETHOD_(ULONG, Release)()
+    {
+        ULONG                                                          newRefCount;
+
+        newRefCount = this->InternalRelease();
+        DbgPrint("RefCount is now %d(--)!\n", newRefCount);
+        if (newRefCount == 0)
+            delete this;
+        return newRefCount;
+    }
+
+    STDMETHOD(QueryInterface)(REFIID iid, void **ppvObject)
+    {
+        return this->_InternalQueryInterface(iid, ppvObject);
+    }
+
+    static HRESULT WINAPI CreateInstance(CComDebugObject<Base> **pp)
+    {
+        CComDebugObject<Base>                          *newInstance;
+        HRESULT                                                                hResult;
+
+        ATLASSERT(pp != NULL);
+        if (pp == NULL)
+            return E_POINTER;
+
+        hResult = E_OUTOFMEMORY;
+        newInstance = NULL;
+        ATLTRY(newInstance = new CComDebugObject<Base>())
+            if (newInstance != NULL)
+            {
+            newInstance->SetVoid(NULL);
+            newInstance->InternalFinalConstructAddRef();
+            hResult = newInstance->_AtlInitialConstruct();
+            if (SUCCEEDED(hResult))
+                hResult = newInstance->FinalConstruct();
+            if (SUCCEEDED(hResult))
+                hResult = newInstance->_AtlFinalConstruct();
+            newInstance->InternalFinalConstructRelease();
+            if (hResult != S_OK)
+            {
+                delete newInstance;
+                newInstance = NULL;
+            }
+            }
+        *pp = newInstance;
+        return hResult;
+    }
+};
+
+template<class T, class R>
+HRESULT inline ShellObjectCreator(REFIID riid, R ** ppv)
+{
+    CComPtr<T>       obj;
+    HRESULT          hResult;
+
+    if (ppv == NULL)
+        return E_POINTER;
+    *ppv = NULL;
+    ATLTRY(obj = new CComObject<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 ShellObjectCreatorInit(REFIID riid, R ** ppv)
+{
+    CComPtr<T>  obj;
+    CComPtr<R>  result;
+    HRESULT     hResult;
+
+    if (ppv == NULL)
+        return E_POINTER;
+    *ppv = NULL;
+    ATLTRY(obj = new CComObject<T>);
+    if (obj.p == NULL)
+        return E_OUTOFMEMORY;
+    hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
+    if (FAILED(hResult))
+        return hResult;
+
+    hResult = obj->Initialize();
+    if (FAILED(hResult))
+        return hResult;
+
+    *ppv = result.Detach();
+
+    return S_OK;
+}
+
+template<class T, class T1, class R>
+HRESULT inline ShellObjectCreatorInit(T1 initArg1, REFIID riid, R ** ppv)
+{
+    CComPtr<T>  obj;
+    CComPtr<R>  result;
+    HRESULT     hResult;
+
+    if (ppv == NULL)
+        return E_POINTER;
+    *ppv = NULL;
+    ATLTRY(obj = new CComObject<T>);
+    if (obj.p == NULL)
+        return E_OUTOFMEMORY;
+    hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
+    if (FAILED(hResult))
+        return hResult;
+
+    hResult = obj->Initialize(initArg1);
+    if (FAILED(hResult))
+        return hResult;
+
+    *ppv = result.Detach();
+
+    return S_OK;
+}
+
+template<class T, class T1, class T2, class R>
+HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, REFIID riid, R ** ppv)
+{
+    CComPtr<T>  obj;
+    CComPtr<R>  result;
+    HRESULT     hResult;
+
+    if (ppv == NULL)
+        return E_POINTER;
+    *ppv = NULL;
+    ATLTRY(obj = new CComObject<T>);
+    if (obj.p == NULL)
+        return E_OUTOFMEMORY;
+    hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
+    if (FAILED(hResult))
+        return hResult;
+
+    hResult = obj->Initialize(initArg1, initArg2);
+    if (FAILED(hResult))
+        return hResult;
+
+    *ppv = result.Detach();
+
+    return S_OK;
+}
+
+template<class T, class T1, class T2, class T3, class R>
+HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, REFIID riid, R ** ppv)
+{
+    CComPtr<T>  obj;
+    CComPtr<R>  result;
+    HRESULT     hResult;
+
+    if (ppv == NULL)
+        return E_POINTER;
+    *ppv = NULL;
+    ATLTRY(obj = new CComObject<T>);
+    if (obj.p == NULL)
+        return E_OUTOFMEMORY;
+    hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
+    if (FAILED(hResult))
+        return hResult;
+
+    hResult = obj->Initialize(initArg1, initArg2, initArg3);
+    if (FAILED(hResult))
+        return hResult;
+
+    *ppv = result.Detach();
+
+    return S_OK;
+}
+
+template<class T, class T1, class T2, class T3, class T4, class R>
+HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, T4 initArg4, REFIID riid, R ** ppv)
+{
+    CComPtr<T>  obj;
+    CComPtr<R>  result;
+    HRESULT     hResult;
+
+    if (ppv == NULL)
+        return E_POINTER;
+    *ppv = NULL;
+    ATLTRY(obj = new CComObject<T>);
+    if (obj.p == NULL)
+        return E_OUTOFMEMORY;
+    hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(&result));
+    if (FAILED(hResult))
+        return hResult;
+
+    hResult = obj->Initialize(initArg1, initArg2, initArg3, initArg4);
+    if (FAILED(hResult))
+        return hResult;
+
+    *ppv = result.Detach();
+
+    return S_OK;
+}
+#endif /* __cplusplus */
+
 #endif /* __WINE_UNDOCSHELL_H */