[SHELL32]
authorDavid Quintana <gigaherz@gmail.com>
Wed, 4 Jun 2014 16:25:48 +0000 (16:25 +0000)
committerDavid Quintana <gigaherz@gmail.com>
Wed, 4 Jun 2014 16:25:48 +0000 (16:25 +0000)
* Fix gcc compilation.

[BROWSEUI/RSHELL]
* Use virtual destructors and cleanup with delete in the creator functions.
* Try to fix a bit the "close" flow, so that less circular references remain when the filebrowser windows are closed.

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

16 files changed:
base/shell/rshell/CMenuBand.cpp
base/shell/rshell/CMenuBand.h
base/shell/rshell/CMenuDeskBar.cpp
base/shell/rshell/CMenuDeskBar.h
base/shell/rshell/CMenuSite.cpp
base/shell/rshell/CMenuSite.h
base/shell/rshell/CMergedFolder.cpp
base/shell/rshell/CMergedFolder.h
dll/win32/browseui/addressband.cpp
dll/win32/browseui/addressband.h
dll/win32/browseui/internettoolbar.cpp
dll/win32/browseui/internettoolbar.h
dll/win32/browseui/precomp.h
dll/win32/browseui/shellbrowser.cpp
dll/win32/browseui/toolsband.cpp
dll/win32/shell32/shlview.cpp

index 6806175..229cb1e 100644 (file)
@@ -52,7 +52,7 @@ HRESULT WINAPI CMenuBand_Constructor(REFIID riid, LPVOID *ppv)
     hr = site->QueryInterface(riid, ppv);
 
     if (FAILED_UNEXPECTEDLY(hr))
-        site->Release();
+        delete site;
 #endif
 
     return hr;
@@ -255,8 +255,7 @@ HRESULT STDMETHODCALLTYPE  CMenuBand::GetSite(REFIID riid, PVOID *ppvSite)
     return m_site->QueryInterface(riid, ppvSite);
 }
 
-HRESULT STDMETHODCALLTYPE CMenuBand::GetWindow(
-    HWND *phwnd)
+HRESULT STDMETHODCALLTYPE CMenuBand::GetWindow(HWND *phwnd)
 {
     if (m_SFToolbar != NULL)
         return m_SFToolbar->GetWindow(phwnd);
@@ -264,6 +263,8 @@ HRESULT STDMETHODCALLTYPE CMenuBand::GetWindow(
     if (m_staticToolbar != NULL)
         return m_staticToolbar->GetWindow(phwnd);
 
+    if (phwnd) *phwnd = NULL;
+
     return E_FAIL;
 }
 
@@ -417,10 +418,25 @@ HRESULT STDMETHODCALLTYPE CMenuBand::CloseDW(DWORD dwReserved)
     ShowDW(FALSE);
 
     if (m_staticToolbar != NULL)
-        return m_staticToolbar->Close();
+    {
+        m_staticToolbar->Close();
+        delete m_staticToolbar;
+        m_staticToolbar = NULL;
+    }
 
     if (m_SFToolbar != NULL)
-        return m_SFToolbar->Close();
+    {
+        m_SFToolbar->Close();
+        delete m_staticToolbar;
+        m_staticToolbar = NULL;
+    }
+
+    if (m_site) m_site.Release();
+    if (m_psmc) m_psmc.Release();
+    if (m_subMenuChild) m_subMenuChild.Release();
+    if (m_subMenuParent) m_subMenuParent.Release();
+    if (m_childBand) m_childBand.Release();
+    if (m_parentBand) m_parentBand.Release();
 
     return S_OK;
 }
index a9f1972..d4cde91 100644 (file)
@@ -69,7 +69,7 @@ private:
 
 public:
     CMenuBand();
-    ~CMenuBand();
+    virtual ~CMenuBand();
 
     DECLARE_NOT_AGGREGATABLE(CMenuBand)
     DECLARE_PROTECT_FINAL_CONSTRUCT()
index ad07d2b..4c3cbad 100644 (file)
@@ -47,7 +47,7 @@ HRESULT WINAPI CMenuDeskBar_Constructor(REFIID riid, LPVOID *ppv)
     hr = deskbar->QueryInterface(riid, ppv);
 
     if (FAILED_UNEXPECTEDLY(hr))
-        deskbar->Release();
+        delete deskbar;
 
 #endif
     return hr;
index a0ccdf9..f8aba1d 100644 (file)
@@ -52,7 +52,7 @@ private:
 
 public:
     CMenuDeskBar();
-    ~CMenuDeskBar();
+    virtual ~CMenuDeskBar();
 
     DECLARE_NOT_AGGREGATABLE(CMenuDeskBar)
     DECLARE_PROTECT_FINAL_CONSTRUCT()
index 791377d..3ebc541 100644 (file)
@@ -45,7 +45,7 @@ HRESULT WINAPI CMenuSite_Constructor(REFIID riid, LPVOID *ppv)
     hr = site->QueryInterface(riid, ppv);
 
     if (FAILED_UNEXPECTEDLY(hr))
-        site->Release();
+        delete site;
 #endif
 
     return hr;
index 1539a15..7e02249 100644 (file)
@@ -39,7 +39,7 @@ private:
 
 public:
     CMenuSite();
-    ~CMenuSite() {}
+    virtual ~CMenuSite() {}
 
     DECLARE_WND_CLASS_EX(_T("MenuSite"), 0, COLOR_MENU)
 
index 6d1c35b..7af7389 100644 (file)
@@ -36,7 +36,7 @@ private:
 
 public:
     CEnumMergedFolder() : m_UserLocal(NULL), m_AllUSers(NULL), m_FirstDone(FALSE) {}
-    ~CEnumMergedFolder() {}
+    virtual ~CEnumMergedFolder() {}
 
     DECLARE_NOT_AGGREGATABLE(CEnumMergedFolder)
     DECLARE_PROTECT_FINAL_CONSTRUCT()
@@ -139,7 +139,7 @@ HRESULT WINAPI CMergedFolder_Constructor(IShellFolder* userLocal, IShellFolder*
 
     hr = fld->QueryInterface(riid, ppv);
     if (FAILED_UNEXPECTEDLY(hr))
-        fld->Release();
+        delete fld;
 
     return hr;
 }
index d60327f..d757d53 100644 (file)
@@ -29,7 +29,7 @@ private:
 
 public:
     CMergedFolder() {}
-    ~CMergedFolder() {}
+    virtual ~CMergedFolder() {}
 
     HRESULT _SetSources(IShellFolder* userLocal, IShellFolder* allUSers);
 
index 2b88ec2..d12b649 100644 (file)
@@ -111,15 +111,9 @@ HRESULT STDMETHODCALLTYPE CAddressBand::GetBandInfo(DWORD dwBandID, DWORD dwView
 HRESULT STDMETHODCALLTYPE CAddressBand::SetSite(IUnknown *pUnkSite)
 {
     CComPtr<IBrowserService>                browserService;
-    CComPtr<IOleWindow>                     oleWindow;
     CComPtr<IShellService>                  shellService;
-    CComPtr<IUnknown>                       offset34;
     HWND                                    parentWindow;
     HWND                                    combobox;
-    static const TBBUTTON                   buttonInfo[] = { {0, 1, TBSTATE_ENABLED, 0} };
-    HIMAGELIST                              normalImagelist;
-    HIMAGELIST                              hotImageList;
-    HINSTANCE                               shellInstance;
     HRESULT                                 hResult;
 
     if (pUnkSite == NULL)
@@ -137,7 +131,7 @@ HRESULT STDMETHODCALLTYPE CAddressBand::SetSite(IUnknown *pUnkSite)
 
     // get window handle of parent
     parentWindow = NULL;
-    hResult = IUnknown_GetWindow(pUnkSite, &parentWindow);
+    hResult = IUnknown_GetWindow(fSite, &parentWindow);
 
     if (!::IsWindow(parentWindow))
         return E_FAIL;
@@ -182,35 +176,43 @@ HRESULT STDMETHODCALLTYPE CAddressBand::SetSite(IUnknown *pUnkSite)
     // TODO: properly initialize this from registry
     fGoButtonShown = true;
 
-    shellInstance = GetModuleHandle(_T("shell32.dll"));
-    normalImagelist = ImageList_LoadImageW(shellInstance, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL),
-        20, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION);
-    hotImageList = ImageList_LoadImageW(shellInstance, MAKEINTRESOURCE(IDB_GOBUTTON_HOT),
-        20, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION);
-
-    fGoButton = CreateWindowEx(WS_EX_TOOLWINDOW, TOOLBARCLASSNAMEW, 0, WS_CHILD | WS_CLIPSIBLINGS |
-        WS_CLIPCHILDREN | TBSTYLE_LIST | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CCS_NODIVIDER |
-        CCS_NOPARENTALIGN | CCS_NORESIZE,
-        0, 0, 0, 0, m_hWnd, NULL, _AtlBaseModule.GetModuleInstance(), NULL);
-    SendMessage(fGoButton, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
-    SendMessage(fGoButton, TB_SETMAXTEXTROWS, 1, 0);
-    if (normalImagelist)
-        SendMessage(fGoButton, TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(normalImagelist));
-    if (hotImageList)
-        SendMessage(fGoButton, TB_SETHOTIMAGELIST, 0, reinterpret_cast<LPARAM>(hotImageList));
-    SendMessage(fGoButton, TB_ADDSTRINGW,
-        reinterpret_cast<WPARAM>(_AtlBaseModule.GetResourceInstance()), IDS_GOBUTTONLABEL);
-    SendMessage(fGoButton, TB_ADDBUTTONSW, 1, (LPARAM)&buttonInfo);
-
-    IImageList * piml;
-    HRESULT hr = SHGetImageList(SHIL_SMALL, IID_PPV_ARG(IImageList, &piml));
-    if (FAILED_UNEXPECTEDLY(hr))
+    if (fGoButtonShown)
     {
-        SendMessageW(combobox, CBEM_SETIMAGELIST, 0, 0);
-    }
-    else
-    {
-        SendMessageW(combobox, CBEM_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(piml));
+        const TBBUTTON buttonInfo [] = { { 0, 1, TBSTATE_ENABLED, 0 } };
+        HIMAGELIST            normalImagelist;
+        HIMAGELIST            hotImageList;
+        HINSTANCE             shellInstance;
+
+        shellInstance = GetModuleHandle(_T("shell32.dll"));
+        normalImagelist = ImageList_LoadImageW(shellInstance, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL),
+            20, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION);
+        hotImageList = ImageList_LoadImageW(shellInstance, MAKEINTRESOURCE(IDB_GOBUTTON_HOT),
+            20, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION);
+
+        fGoButton = CreateWindowEx(WS_EX_TOOLWINDOW, TOOLBARCLASSNAMEW, 0, WS_CHILD | WS_CLIPSIBLINGS |
+            WS_CLIPCHILDREN | TBSTYLE_LIST | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CCS_NODIVIDER |
+            CCS_NOPARENTALIGN | CCS_NORESIZE,
+            0, 0, 0, 0, m_hWnd, NULL, _AtlBaseModule.GetModuleInstance(), NULL);
+        SendMessage(fGoButton, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
+        SendMessage(fGoButton, TB_SETMAXTEXTROWS, 1, 0);
+        if (normalImagelist)
+            SendMessage(fGoButton, TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(normalImagelist));
+        if (hotImageList)
+            SendMessage(fGoButton, TB_SETHOTIMAGELIST, 0, reinterpret_cast<LPARAM>(hotImageList));
+        SendMessage(fGoButton, TB_ADDSTRINGW,
+            reinterpret_cast<WPARAM>(_AtlBaseModule.GetResourceInstance()), IDS_GOBUTTONLABEL);
+        SendMessage(fGoButton, TB_ADDBUTTONSW, 1, (LPARAM) &buttonInfo);
+
+        IImageList * piml;
+        HRESULT hr = SHGetImageList(SHIL_SMALL, IID_PPV_ARG(IImageList, &piml));
+        if (FAILED_UNEXPECTEDLY(hr))
+        {
+            SendMessageW(combobox, CBEM_SETIMAGELIST, 0, 0);
+        }
+        else
+        {
+            SendMessageW(combobox, CBEM_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(piml));
+        }
     }
 
     // take advice to watch events
@@ -252,6 +254,9 @@ HRESULT STDMETHODCALLTYPE CAddressBand::CloseDW(DWORD dwReserved)
 
     m_hWnd = NULL;
 
+    if (fAddressEditBox) fAddressEditBox.Release();
+    if (fSite) fSite.Release();
+
     return S_OK;
 }
 
@@ -662,8 +667,8 @@ LRESULT CAddressBand::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lPara
 
 HRESULT CreateAddressBand(REFIID riid, void **ppv)
 {
-    CComObject<CAddressBand>                *theMenuBar;
-    HRESULT                                 hResult;
+    CAddressBand                *theMenuBar;
+    HRESULT                     hResult;
 
     if (ppv == NULL)
         return E_POINTER;
index e7e38be..761901c 100644 (file)
@@ -45,7 +45,7 @@ private:
     DWORD                                   fAdviseCookie;
 public:
     CAddressBand();
-    ~CAddressBand();
+    virtual ~CAddressBand();
 private:
     void FocusChange(BOOL bFocus);
 public:
index 2b0cb72..669183a 100644 (file)
@@ -95,6 +95,44 @@ HRESULT IUnknown_TranslateAcceleratorIO(IUnknown * punk, MSG * pmsg)
     return pio->TranslateAcceleratorIO(pmsg);
 }
 
+HRESULT IUnknown_RelayWinEvent(IUnknown * punk, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult)
+{
+    CComPtr<IWinEventHandler> menuWinEventHandler;
+    HRESULT hResult = punk->QueryInterface(IID_PPV_ARG(IWinEventHandler, &menuWinEventHandler));
+    if (FAILED_UNEXPECTEDLY(hResult))
+        return hResult;
+    hResult = menuWinEventHandler->IsWindowOwner(hWnd);
+    if (FAILED_UNEXPECTEDLY(hResult))
+        return hResult;
+    if (hResult == S_OK)
+        return menuWinEventHandler->OnWinEvent(hWnd, uMsg, wParam, lParam, theResult);
+    return S_FALSE;
+}
+
+HRESULT IUnknown_ShowDW(IUnknown * punk, BOOL fShow)
+{
+    CComPtr<IDockingWindow> dockingWindow;
+    HRESULT hResult = punk->QueryInterface(IID_PPV_ARG(IDockingWindow, &dockingWindow));
+    if (FAILED_UNEXPECTEDLY(hResult))
+        return hResult;
+    hResult = dockingWindow->ShowDW(fShow);
+    if (FAILED_UNEXPECTEDLY(hResult))
+        return hResult;
+    return S_OK;
+}
+
+HRESULT IUnknown_CloseDW(IUnknown * punk, DWORD dwReserved)
+{
+    CComPtr<IDockingWindow> dockingWindow;
+    HRESULT hResult = punk->QueryInterface(IID_PPV_ARG(IDockingWindow, &dockingWindow));
+    if (FAILED_UNEXPECTEDLY(hResult))
+        return hResult;
+    hResult = dockingWindow->CloseDW(dwReserved);
+    if (FAILED_UNEXPECTEDLY(hResult))
+        return hResult;
+    return S_OK;
+}
+
 typedef HRESULT(*PMENUBAND_CONSTRUCTOR)(REFIID riid, void **ppv);
 
 class CInternetToolbar;
@@ -180,31 +218,19 @@ CDockSite::~CDockSite()
 
 HRESULT CDockSite::Initialize(IUnknown *containedBand, CInternetToolbar *browser, HWND hwnd, int bandID, int flags)
 {
-    CComPtr<IObjectWithSite>                child;
-    CComPtr<IOleWindow>                     oleWindow;
-    CComPtr<IDeskBand>                      deskBand;
     TCHAR                                   textBuffer[40];
     REBARBANDINFOW                          bandInfo;
     HRESULT                                 hResult;
 
-    hResult = containedBand->QueryInterface(IID_PPV_ARG(IObjectWithSite, &child));
-    if (FAILED(hResult))
-        return hResult;
-    hResult = containedBand->QueryInterface(IID_PPV_ARG(IOleWindow, &oleWindow));
-    if (FAILED(hResult))
-        return hResult;
-    hResult = containedBand->QueryInterface(IID_PPV_ARG(IDeskBand, &deskBand));
-    if (FAILED(hResult))
-        return hResult;
     fContainedBand = containedBand;
     fToolbar = browser;
     fRebarWindow = hwnd;
     fBandID = bandID;
     fFlags = flags;
-    hResult = child->SetSite(static_cast<IOleWindow *>(this));
+    hResult = IUnknown_SetSite(containedBand, static_cast<IOleWindow *>(this));
     if (FAILED(hResult))
         return hResult;
-    hResult = oleWindow->GetWindow(&fChildWindow);
+    hResult = IUnknown_GetWindow(containedBand, &fChildWindow);
     if (FAILED(hResult))
         return hResult;
 
@@ -533,10 +559,9 @@ CInternetToolbar::~CInternetToolbar()
 
 void CInternetToolbar::AddDockItem(IUnknown *newItem, int bandID, int flags)
 {
-    CDockSite           *newSite;
+    CComPtr<CDockSite> newSite;
 
     newSite = new CComObject<CDockSite>;
-    newSite->AddRef();
     newSite->Initialize(newItem, this, fMainReBar, bandID, flags);
 }
 
@@ -624,10 +649,7 @@ HRESULT CInternetToolbar::CreateMenuBar(IShellMenu **menuBar)
     hResult = (*menuBar)->SetMenu((HMENU)V_INTREF(&menuOut), ownerWindow, SMSET_DONTOWN);
     if (FAILED(hResult))
         return hResult;
-    hResult = (*menuBar)->QueryInterface(IID_PPV_ARG(IOleCommandTarget, &commandTarget));
-    if (FAILED(hResult))
-        return hResult;
-    hResult = commandTarget->Exec(&CGID_MenuBand, 3, 1, NULL, NULL);
+    hResult = IUnknown_Exec(*menuBar, CGID_MenuBand, 3, 1, NULL, NULL);
     if (FAILED(hResult))
         return hResult;
     return S_OK;
@@ -635,43 +657,25 @@ HRESULT CInternetToolbar::CreateMenuBar(IShellMenu **menuBar)
 
 HRESULT CInternetToolbar::CreateBrandBand(IUnknown **logoBar)
 {
-    CComPtr<IUnknown>                       tempBand;
-    HRESULT                                 hResult;
-
 #if 1
-    hResult = ::CreateBrandBand(IID_PPV_ARG(IUnknown, logoBar));
+    return ::CreateBrandBand(IID_PPV_ARG(IUnknown, logoBar));
 #else
-    hResult = CoCreateInstance(CLSID_BrandBand, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IUnknown, logoBar));
+    return CoCreateInstance(CLSID_BrandBand, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IUnknown, logoBar));
 #endif
-    if (FAILED(hResult))
-        return hResult;
-    return S_OK;
 }
 
 HRESULT CInternetToolbar::CreateToolsBar(IUnknown **toolsBar)
 {
-    HRESULT                                 hResult;
-
-    hResult = ::CreateToolsBar(IID_PPV_ARG(IUnknown, toolsBar));
-    if (FAILED(hResult))
-        return hResult;
-    return S_OK;
+    return ::CreateToolsBar(IID_PPV_ARG(IUnknown, toolsBar));
 }
 
 HRESULT CInternetToolbar::CreateAddressBand(IUnknown **toolsBar)
 {
-    CComPtr<IAddressBand>                   addressBand;
-    HRESULT                                 hResult;
-
 #if 1
-    hResult = ::CreateAddressBand(IID_PPV_ARG(IUnknown, toolsBar));
+    return ::CreateAddressBand(IID_PPV_ARG(IUnknown, toolsBar));
 #else
-    hResult = CoCreateInstance(CLSID_SH_AddressBand, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IUnknown, toolsBar));
+    return CoCreateInstance(CLSID_SH_AddressBand, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IUnknown, toolsBar));
 #endif
-    if (FAILED(hResult))
-        return hResult;
-    hResult = (*toolsBar)->QueryInterface(IID_PPV_ARG(IAddressBand, &addressBand));
-    return S_OK;
 }
 
 HRESULT CInternetToolbar::LockUnlockToolbars(bool locked)
@@ -825,43 +829,54 @@ HRESULT STDMETHODCALLTYPE CInternetToolbar::ShowDW(BOOL fShow)
     if (fShow)
     {
         hResult = ReserveBorderSpace();
+        if (FAILED_UNEXPECTEDLY(hResult))
+            return hResult;
     }
+
     if (fMenuBar)
     {
-        CComPtr<IDockingWindow> dockingWindow;
-        hResult = fMenuBar->QueryInterface(IID_PPV_ARG(IDockingWindow, &dockingWindow));
-        hResult = dockingWindow->ShowDW(fShow);
+        hResult = IUnknown_ShowDW(fMenuBar, fShow);
+        if (FAILED_UNEXPECTEDLY(hResult))
+            return hResult;
     }
+
     if (fControlsBar)
     {
-        CComPtr<IDockingWindow> dockingWindow;
-        hResult = fControlsBar->QueryInterface(IID_PPV_ARG(IDockingWindow, &dockingWindow));
-        hResult = dockingWindow->ShowDW(fShow);
+        hResult = IUnknown_ShowDW(fControlsBar, fShow);
+        if (FAILED_UNEXPECTEDLY(hResult))
+            return hResult;
     }
     if (fNavigationBar)
     {
-        CComPtr<IDockingWindow> dockingWindow;
-        hResult = fNavigationBar->QueryInterface(IID_PPV_ARG(IDockingWindow, &dockingWindow));
-        hResult = dockingWindow->ShowDW(fShow);
+        hResult = IUnknown_ShowDW(fNavigationBar, fShow);
+        if (FAILED_UNEXPECTEDLY(hResult))
+            return hResult;
     }
     if (fLogoBar)
     {
-        CComPtr<IDockingWindow> dockingWindow;
-        hResult = fLogoBar->QueryInterface(IID_PPV_ARG(IDockingWindow, &dockingWindow));
-        hResult = dockingWindow->ShowDW(fShow);
+        hResult = IUnknown_ShowDW(fLogoBar, fShow);
+        if (FAILED_UNEXPECTEDLY(hResult))
+            return hResult;
     }
     return S_OK;
 }
 
 template<class T>
-void ReleaseCComPtrExpectZero(CComPtr<T>& cptr)
+void ReleaseCComPtrExpectZero(CComPtr<T>& cptr, BOOL forceRelease = FALSE)
 {
     if (cptr.p != NULL)
     {
         int nrc = cptr->Release();
         if (nrc > 0)
         {
-            DbgPrint("WARNING: Unexpected RefCount > 0!\n");
+            DbgPrint("WARNING: Unexpected RefCount > 0 (%d)!\n", nrc);
+            if (forceRelease)
+            {
+                while (nrc > 0)
+                {
+                    nrc = cptr->Release();
+                }
+            }
         }
         cptr.Detach();
     }
@@ -873,32 +888,32 @@ HRESULT STDMETHODCALLTYPE CInternetToolbar::CloseDW(DWORD dwReserved)
 
     if (fMenuBar)
     {
-        CComPtr<IDockingWindow> dockingWindow;
-        hResult = fMenuBar->QueryInterface(IID_PPV_ARG(IDockingWindow, &dockingWindow));
-        hResult = dockingWindow->CloseDW(dwReserved);
+        hResult = IUnknown_CloseDW(fMenuBar, dwReserved);
+        if (FAILED_UNEXPECTEDLY(hResult))
+            return hResult;
+        ReleaseCComPtrExpectZero(fMenuBar);
     }
-    ReleaseCComPtrExpectZero(fMenuBar);
     if (fControlsBar)
     {
-        CComPtr<IDockingWindow> dockingWindow;
-        hResult = fControlsBar->QueryInterface(IID_PPV_ARG(IDockingWindow, &dockingWindow));
-        hResult = dockingWindow->CloseDW(dwReserved);
+        hResult = IUnknown_CloseDW(fControlsBar, dwReserved);
+        if (FAILED_UNEXPECTEDLY(hResult))
+            return hResult;
+        ReleaseCComPtrExpectZero(fControlsBar);
     }
-    ReleaseCComPtrExpectZero(fControlsBar);
     if (fNavigationBar)
     {
-        CComPtr<IDockingWindow> dockingWindow;
-        hResult = fNavigationBar->QueryInterface(IID_PPV_ARG(IDockingWindow, &dockingWindow));
-        hResult = dockingWindow->CloseDW(dwReserved);
+        hResult = IUnknown_CloseDW(fNavigationBar, dwReserved);
+        if (FAILED_UNEXPECTEDLY(hResult))
+            return hResult;
+        ReleaseCComPtrExpectZero(fNavigationBar);
     }
-    ReleaseCComPtrExpectZero(fNavigationBar);
     if (fLogoBar)
     {
-        CComPtr<IDockingWindow> dockingWindow;
-        hResult = fLogoBar->QueryInterface(IID_PPV_ARG(IDockingWindow, &dockingWindow));
-        hResult = dockingWindow->CloseDW(dwReserved);
+        hResult = IUnknown_CloseDW(fLogoBar, dwReserved);
+        if (FAILED_UNEXPECTEDLY(hResult))
+            return hResult;
+        ReleaseCComPtrExpectZero(fLogoBar);
     }
-    ReleaseCComPtrExpectZero(fLogoBar);
     return S_OK;
 }
 
@@ -971,9 +986,6 @@ HRESULT STDMETHODCALLTYPE CInternetToolbar::InitNew()
     CComPtr<IUnknown>                       logoBar;
     CComPtr<IUnknown>                       toolsBar;
     CComPtr<IUnknown>                       navigationBar;
-    CComPtr<IOleWindow>                     menuOleWindow;
-    CComPtr<IOleWindow>                     toolbarOleWindow;
-    CComPtr<IOleWindow>                     navigationOleWindow;
     HRESULT                                 hResult;
 
     /* Create and attach the menubar to the rebar */
@@ -982,8 +994,7 @@ HRESULT STDMETHODCALLTYPE CInternetToolbar::InitNew()
         return hResult;
     AddDockItem(menuBar, ITBBID_MENUBAND, CDockSite::ITF_NOTITLE | CDockSite::ITF_NEWBANDALWAYS | CDockSite::ITF_GRIPPERALWAYS);
 
-    hResult = menuBar->QueryInterface(IID_PPV_ARG(IOleWindow, &menuOleWindow));
-    hResult = menuOleWindow->GetWindow(&fMenuBandWindow);
+    hResult = IUnknown_GetWindow(menuBar, &fMenuBandWindow);
     fMenuBar.Attach(menuBar.Detach());                  // transfer the ref count
 
     // FIXME: The ros Rebar does not properly support fixed-size items such as the brandband,
@@ -1003,10 +1014,7 @@ HRESULT STDMETHODCALLTYPE CInternetToolbar::InitNew()
         return hResult;
     AddDockItem(toolsBar, ITBBID_TOOLSBAND, CDockSite::ITF_NOTITLE | CDockSite::ITF_NEWBANDALWAYS | CDockSite::ITF_GRIPPERALWAYS);
     fControlsBar.Attach(toolsBar.Detach());             // transfer the ref count
-    hResult = fControlsBar->QueryInterface(IID_PPV_ARG(IOleWindow, &toolbarOleWindow));
-    if (FAILED(hResult))
-        return hResult;
-    hResult = toolbarOleWindow->GetWindow(&fToolbarWindow);
+    hResult = IUnknown_GetWindow(fControlsBar, &fToolbarWindow);
     if (FAILED(hResult))
         return hResult;
 
@@ -1015,9 +1023,8 @@ HRESULT STDMETHODCALLTYPE CInternetToolbar::InitNew()
     if (FAILED(hResult))
         return hResult;
     AddDockItem(navigationBar, ITBBID_ADDRESSBAND, CDockSite::ITF_NEWBANDALWAYS | CDockSite::ITF_GRIPPERALWAYS);
-    hResult = navigationBar->QueryInterface(IID_PPV_ARG(IOleWindow, &navigationOleWindow));
-    hResult = navigationOleWindow->GetWindow(&fNavigationWindow);
     fNavigationBar.Attach(navigationBar.Detach());
+    hResult = IUnknown_GetWindow(fNavigationBar, &fNavigationWindow);
 
     return S_OK;
 }
@@ -1330,16 +1337,27 @@ HRESULT STDMETHODCALLTYPE CInternetToolbar::QueryService(REFGUID guidService, RE
 HRESULT STDMETHODCALLTYPE CInternetToolbar::OnWinEvent(
     HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult)
 {
-    CComPtr<IWinEventHandler>               menuWinEventHandler;
     HRESULT                                 hResult;
 
     if (fMenuBar)
     {
-        hResult = fMenuBar->QueryInterface(IID_PPV_ARG(IWinEventHandler, &menuWinEventHandler));
-        if (menuWinEventHandler->IsWindowOwner(hWnd) == S_OK)
-        {
-            return menuWinEventHandler->OnWinEvent(fMenuBandWindow, uMsg, wParam, lParam, theResult);
-        }
+        hResult = IUnknown_RelayWinEvent(fMenuBar, hWnd, uMsg, wParam, lParam, theResult);
+        if (hResult != S_FALSE)
+            return hResult;
+    }
+
+    if (fNavigationBar)
+    {
+        hResult = IUnknown_RelayWinEvent(fNavigationBar, hWnd, uMsg, wParam, lParam, theResult);
+        if (hResult != S_FALSE)
+            return hResult;
+    }
+
+    if (fLogoBar)
+    {
+        hResult = IUnknown_RelayWinEvent(fLogoBar, hWnd, uMsg, wParam, lParam, theResult);
+        if (hResult != S_FALSE)
+            return hResult;
     }
 
     return S_FALSE;
@@ -1347,16 +1365,19 @@ HRESULT STDMETHODCALLTYPE CInternetToolbar::OnWinEvent(
 
 HRESULT STDMETHODCALLTYPE CInternetToolbar::IsWindowOwner(HWND hWnd)
 {
+    UNIMPLEMENTED;
     return E_NOTIMPL;
 }
 
 HRESULT STDMETHODCALLTYPE CInternetToolbar::AddBand(IUnknown *punk)
 {
+    UNIMPLEMENTED;
     return E_NOTIMPL;
 }
 
 HRESULT STDMETHODCALLTYPE CInternetToolbar::EnumBands(UINT uBand, DWORD *pdwBandID)
 {
+    UNIMPLEMENTED;
     return E_NOTIMPL;
 }
 
@@ -1751,37 +1772,12 @@ LRESULT CInternetToolbar::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOO
 {
     LRESULT theResult;
     HRESULT hResult;
-    HWND    target = (HWND) lParam;
 
-    if (fMenuBar)
-    {
-        CComPtr<IWinEventHandler> menuWinEventHandler;
-        hResult = fMenuBar->QueryInterface(IID_PPV_ARG(IWinEventHandler, &menuWinEventHandler));
-        if (SUCCEEDED(hResult))
-        {
-            if (menuWinEventHandler->IsWindowOwner(target) == S_OK)
-            {
-                hResult = menuWinEventHandler->OnWinEvent(target, uMsg, wParam, lParam, &theResult);
-                return FAILED(hResult) ? 0 : theResult;
-            }
-        }
-    }
+    hResult = OnWinEvent((HWND) lParam, uMsg, wParam, lParam, &theResult);
 
-    if (fNavigationBar)
-    {
-        CComPtr<IWinEventHandler> menuWinEventHandler;
-        hResult = fNavigationBar->QueryInterface(IID_PPV_ARG(IWinEventHandler, &menuWinEventHandler));
-        if (SUCCEEDED(hResult))
-        {
-            if (menuWinEventHandler->IsWindowOwner(target) == S_OK)
-            {
-                hResult = menuWinEventHandler->OnWinEvent(target, uMsg, wParam, lParam, &theResult);
-                return FAILED(hResult) ? 0 : theResult;
-            }
-        }
-    }
+    bHandled = hResult == S_OK;
 
-    return 0;
+    return FAILED_UNEXPECTEDLY(hResult) ? 0 : theResult;
 }
 LRESULT CInternetToolbar::OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 {
@@ -1789,37 +1785,13 @@ LRESULT CInternetToolbar::OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
     LRESULT theResult;
     HRESULT hResult;
 
-    notifyHeader = (NMHDR *) lParam;
+    notifyHeader = reinterpret_cast<NMHDR *>(lParam);
 
-    if (fMenuBar)
-    {
-        CComPtr<IWinEventHandler> menuWinEventHandler;
-        hResult = fMenuBar->QueryInterface(IID_PPV_ARG(IWinEventHandler, &menuWinEventHandler));
-        if (SUCCEEDED(hResult))
-        {
-            if (menuWinEventHandler->IsWindowOwner(notifyHeader->hwndFrom) == S_OK)
-            {
-                hResult = menuWinEventHandler->OnWinEvent(notifyHeader->hwndFrom, uMsg, wParam, lParam, &theResult);
-                return FAILED(hResult) ? 0 : theResult;
-            }
-        }
-    }
+    hResult = OnWinEvent(notifyHeader->hwndFrom, uMsg, wParam, lParam, &theResult);
 
-    if (fNavigationBar)
-    {
-        CComPtr<IWinEventHandler> menuWinEventHandler;
-        hResult = fNavigationBar->QueryInterface(IID_PPV_ARG(IWinEventHandler, &menuWinEventHandler));
-        if (SUCCEEDED(hResult))
-        {
-            if (menuWinEventHandler->IsWindowOwner(notifyHeader->hwndFrom) == S_OK)
-            {
-                hResult = menuWinEventHandler->OnWinEvent(notifyHeader->hwndFrom, uMsg, wParam, lParam, &theResult);
-                return FAILED(hResult) ? 0 : theResult;
-            }
-        }
-    }
+    bHandled = hResult == S_OK;
 
-    return 0;
+    return FAILED_UNEXPECTEDLY(hResult) ? 0 : theResult;
 }
 
 LRESULT CInternetToolbar::OnLDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
@@ -1884,8 +1856,8 @@ LRESULT CInternetToolbar::OnLUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &b
 
 HRESULT CreateInternetToolbar(REFIID riid, void **ppv)
 {
-    CComObject<CInternetToolbar>            *theToolbar;
-    HRESULT                                 hResult;
+    CInternetToolbar            *theToolbar;
+    HRESULT                     hResult;
 
     if (ppv == NULL)
         return E_POINTER;
index a825dba..92316b9 100644 (file)
@@ -45,7 +45,7 @@ private:
     CComPtr<IShellMenu>             fFavoritesMenu;
 public:
     CMenuCallback();
-    ~CMenuCallback();
+    virtual ~CMenuCallback();
 
     HRESULT STDMETHODCALLTYPE GetObject(LPSMDATA psmd, REFIID riid, void **ppvObject);
 public:
@@ -94,7 +94,7 @@ public:
     LONG                                    fStartHeight;
 public:
     CInternetToolbar();
-    ~CInternetToolbar();
+    virtual ~CInternetToolbar();
     void AddDockItem(IUnknown *newItem, int bandID, int flags);
     HRESULT ReserveBorderSpace(LONG maxHeight = -1);
     HRESULT CreateMenuBar(IShellMenu **menuBar);
index 339611d..323deb6 100644 (file)
@@ -82,6 +82,78 @@ Win32DbgPrint(const char *filename, int line, const char *lpFormat, ...)
 #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 98c90eb..87765d9 100644 (file)
@@ -29,6 +29,8 @@ BOOL WINAPI Shell_GetImageLists(
     _Out_  HIMAGELIST *phimlSmall
     );
 
+extern HRESULT IUnknown_ShowDW(IUnknown * punk, BOOL fShow);
+
 #include "newatlinterfaces.h"
 
 /*
@@ -732,12 +734,9 @@ CShellBrowser::~CShellBrowser()
 
 HRESULT CShellBrowser::Initialize(LPITEMIDLIST pidl, long b, long c, long d)
 {
-    CComPtr<IDockingWindow>                 dockingWindow;
-    CComPtr<IStream>                        settingsStream;
     CComPtr<IPersistStreamInit>             persistStreamInit;
-    CComPtr<IOleCommandTarget>              commandTarget;
-    CComPtr<IObjectWithSite>                objectSite;
     HRESULT                                 hResult;
+    CComPtr<IUnknown> clientBar;
 
     _AtlInitialConstruct();
 
@@ -756,55 +755,46 @@ HRESULT CShellBrowser::Initialize(LPITEMIDLIST pidl, long b, long c, long d)
     if (FAILED(hResult))
         return hResult;
 #else
-    hResult = CreateInternetToolbar(IID_PPV_ARG(IUnknown, &fClientBars[BIInternetToolbar].clientBar));
+    hResult = CreateInternetToolbar(IID_PPV_ARG(IUnknown, &clientBar));
     if (FAILED(hResult))
         return hResult;
 #endif
 
+    fClientBars[BIInternetToolbar].clientBar = clientBar;
+
     // create interfaces
-    hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
-        IID_PPV_ARG(IDockingWindow, &dockingWindow));
-    if (FAILED(hResult))
-        return hResult;
-    hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
-        IID_PPV_ARG(IPersistStreamInit, &persistStreamInit));
-    if (FAILED(hResult))
-        return hResult;
-    hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
-        IID_PPV_ARG(IOleCommandTarget, &commandTarget));
-    if (FAILED(hResult))
-        return hResult;
-    hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
-        IID_PPV_ARG(IObjectWithSite, &objectSite));
-    if (FAILED(hResult))
+    hResult = clientBar->QueryInterface(IID_PPV_ARG(IPersistStreamInit, &persistStreamInit));
+    if (FAILED_UNEXPECTEDLY(hResult))
         return hResult;
 
-    hResult = objectSite->SetSite(static_cast<IShellBrowser *>(this));
+    hResult = IUnknown_SetSite(clientBar, static_cast<IShellBrowser *>(this));
     if (FAILED(hResult))
         return hResult;
 
-    hResult = commandTarget->Exec(&CGID_PrivCITCommands, 1, 1 /* or 0 */, NULL, NULL);
+    hResult = IUnknown_Exec(clientBar, CGID_PrivCITCommands, 1, 1 /* or 0 */, NULL, NULL);
     if (FAILED(hResult))
         return hResult;
 
     // TODO: create settingsStream from registry entry
-    if (settingsStream.p == NULL)
+    //if (settingsStream.p)
+    //{
+    //    hResult = persistStreamInit->Load(settingsStream);
+    //    if (FAILED_UNEXPECTEDLY(hResult))
+    //        return hResult;
+    //}
+    //else
     {
         hResult = persistStreamInit->InitNew();
         if (FAILED(hResult))
             return hResult;
     }
-    else
-    {
-        hResult = persistStreamInit->Load(settingsStream);
-        if (FAILED(hResult))
-            return hResult;
-    }
-    hResult = dockingWindow->ShowDW(TRUE);
-    if (FAILED(hResult))
+
+    hResult = IUnknown_ShowDW(clientBar, TRUE);
+    if (FAILED_UNEXPECTEDLY(hResult))
         return hResult;
 
-    fToolbarProxy.Initialize(m_hWnd, fClientBars[BIInternetToolbar].clientBar);
+    fToolbarProxy.Initialize(m_hWnd, clientBar);
+
 
     // create status bar
     fStatusBar = CreateWindow(STATUSCLASSNAMEW, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
@@ -812,6 +802,7 @@ HRESULT CShellBrowser::Initialize(LPITEMIDLIST pidl, long b, long c, long d)
                     _AtlBaseModule.GetModuleInstance(), 0);
     fStatusBarVisible = true;
 
+
     // browse 
     hResult = BrowseToPIDL(pidl, BTP_UPDATE_NEXT_HISTORY);
     if (FAILED(hResult))
@@ -1091,14 +1082,8 @@ HRESULT CShellBrowser::GetMenuBand(REFIID riid, void **shellMenu)
     CComPtr<IDeskBand>                      deskBand;
     HRESULT                                 hResult;
 
-    if (fClientBars[BIInternetToolbar].clientBar.p == NULL)
-        return E_FAIL;
-    hResult = fClientBars[BIInternetToolbar].clientBar->QueryInterface(
-        IID_PPV_ARG(IServiceProvider, &serviceProvider));
-    if (FAILED(hResult))
-        return hResult;
-    hResult = serviceProvider->QueryService(SID_IBandSite, IID_PPV_ARG(IBandSite, &bandSite));
-    if (FAILED(hResult))
+    hResult = IUnknown_QueryService(fClientBars[BIInternetToolbar].clientBar, SID_IBandSite, IID_PPV_ARG(IBandSite, &bandSite));
+    if (FAILED_UNEXPECTEDLY(hResult))
         return hResult;
     hResult = bandSite->QueryBand(1, &deskBand, NULL, NULL, 0);
     if (FAILED(hResult))
@@ -1291,7 +1276,6 @@ LRESULT CALLBACK CShellBrowser::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam,
     CShellBrowser                           *pThis = reinterpret_cast<CShellBrowser *>(hWnd);
     _ATL_MSG                                msg(pThis->m_hWnd, uMsg, wParam, lParam);
     LRESULT                                 lResult;
-    CComPtr<IMenuBand>                      menuBand;
     const _ATL_MSG                          *previousMessage;
     BOOL                                    handled;
     WNDPROC                                 saveWindowProc;
@@ -1301,6 +1285,7 @@ LRESULT CALLBACK CShellBrowser::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam,
     previousMessage = pThis->m_pCurrentMsg;
     pThis->m_pCurrentMsg = &msg;
 
+    CComPtr<IMenuBand> menuBand;
     hResult = pThis->GetMenuBand(IID_PPV_ARG(IMenuBand, &menuBand));
     if (SUCCEEDED(hResult) && menuBand.p != NULL)
     {
@@ -1311,6 +1296,7 @@ LRESULT CALLBACK CShellBrowser::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam,
         wParam = msg.wParam;
         lParam = msg.lParam;
     }
+    menuBand.Release();
 
     handled = pThis->ProcessWindowMessage(hWnd, uMsg, wParam, lParam, lResult, 0);
     ATLASSERT(pThis->m_pCurrentMsg == &msg);
@@ -1867,7 +1853,7 @@ HRESULT STDMETHODCALLTYPE CShellBrowser::SetMenuSB(HMENU hmenuShared, HOLEMENU h
     CComPtr<IShellMenu>                     shellMenu;
     HRESULT                                 hResult;
 
-    if (IsMenu(hmenuShared) == FALSE)
+    if (hmenuShared && IsMenu(hmenuShared) == FALSE)
         return E_FAIL;
     hResult = GetMenuBand(IID_PPV_ARG(IShellMenu, &shellMenu));
     if (FAILED(hResult))
@@ -1882,7 +1868,10 @@ HRESULT STDMETHODCALLTYPE CShellBrowser::SetMenuSB(HMENU hmenuShared, HOLEMENU h
 HRESULT STDMETHODCALLTYPE CShellBrowser::RemoveMenusSB(HMENU hmenuShared)
 {
     if (hmenuShared == fCurrentMenuBar)
-        fCurrentMenuBar = NULL;
+    {
+        //DestroyMenu(fCurrentMenuBar);
+        SetMenuSB(NULL, NULL, NULL);
+    }
     return S_OK;
 }
 
@@ -3072,7 +3061,7 @@ LRESULT CShellBrowser::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &b
 }
 
 template<class T>
-void ReleaseCComPtrExpectZero(CComPtr<T>& cptr)
+void ReleaseCComPtrExpectZero(CComPtr<T>& cptr, BOOL forceRelease = FALSE)
 {
     if (cptr.p != NULL)
     {
@@ -3080,6 +3069,13 @@ void ReleaseCComPtrExpectZero(CComPtr<T>& cptr)
         if (nrc > 0)
         {
             DbgPrint("WARNING: Unexpected RefCount > 0!\n");
+            if (forceRelease)
+            {
+                while (nrc > 0)
+                {
+                    nrc = cptr->Release();
+                }
+            }
         }
         cptr.Detach();
     }
@@ -3361,8 +3357,8 @@ LRESULT CShellBrowser::RelayCommands(UINT uMsg, WPARAM wParam, LPARAM lParam, BO
 
 static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters)
 {
-    CComPtr< CComObject<CShellBrowser> >    theCabinet;
-    HRESULT                                 hResult;
+    CComPtr<CShellBrowser>    theCabinet;
+    HRESULT                   hResult;
     MSG Msg;
     BOOL Ret;
     
@@ -3384,14 +3380,14 @@ static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters)
             break;
         }
 
+        if (Msg.message == WM_QUIT)
+            break;
+
         if (theCabinet->v_MayTranslateAccelerator(&Msg) != S_OK)
         {
             TranslateMessage(&Msg);
             DispatchMessage(&Msg);
         }
-
-        if (Msg.message == WM_QUIT)
-            break;
     }
     
     //TerminateProcess(GetCurrentProcess(), hResult);
@@ -3399,7 +3395,9 @@ static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters)
     int nrc = theCabinet->Release();
     if (nrc > 0)
     {
-        DbgPrint("WARNING: There are %d references to the CShellBrowser active or leaked, process will never terminate.\n");
+        DbgPrint("WARNING: There are %d references to the CShellBrowser active or leaked, process will never terminate. Terminating forcefully.\n", nrc);
+
+        //TerminateProcess(GetCurrentProcess(), 1);
     }
 
     theCabinet.Detach();
index dc2dae9..e215891 100644 (file)
@@ -37,12 +37,12 @@ class CToolsBand :
     public IPersistStream
 {
 private:
-    IDockingWindowSite          *fDockSite;
+    CComPtr<IDockingWindowSite> fDockSite;
     GUID                        fExecCommandCategory;
     CComPtr<IOleCommandTarget>  fExecCommandTarget;
 public:
     CToolsBand();
-    ~CToolsBand();
+    virtual ~CToolsBand();
 public:
     // *** IDeskBand methods ***
     virtual HRESULT STDMETHODCALLTYPE GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO* pdbi);
@@ -95,14 +95,12 @@ END_COM_MAP()
 };
 
 CToolsBand::CToolsBand()
+    : fDockSite(NULL)
 {
-    fDockSite = NULL;
 }
 
 CToolsBand::~CToolsBand()
 {
-    if (fDockSite)
-        fDockSite->Release();
 }
 
 HRESULT STDMETHODCALLTYPE CToolsBand::GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO* pdbi)
@@ -267,8 +265,8 @@ HRESULT STDMETHODCALLTYPE CToolsBand::SetSite(IUnknown* pUnkSite){
     HWND                    toolbar;
     HRESULT                 hResult;
 
-    if (fDockSite != NULL)
-        fDockSite->Release();
+    if(fDockSite) fDockSite.Release();
+
     if (pUnkSite == NULL)
         return S_OK;
     hResult = pUnkSite->QueryInterface(IID_PPV_ARG(IDockingWindowSite, &fDockSite));
@@ -364,6 +362,8 @@ HRESULT STDMETHODCALLTYPE CToolsBand::CloseDW(DWORD dwReserved)
 
     m_hWnd = NULL;
 
+    if (fDockSite) fDockSite.Release();
+
     return S_OK;
 }
 
@@ -440,19 +440,19 @@ LRESULT CToolsBand::OnGetButtonInfo(UINT idControl, NMHDR *pNMHDR, BOOL &bHandle
 
 HRESULT CreateToolsBar(REFIID riid, void **ppv)
 {
-    CComObject<CToolsBand>                  *theMenuBar;
-    HRESULT                                 hResult;
+    CToolsBand                  *theToolbar;
+    HRESULT                     hResult;
 
     if (ppv == NULL)
         return E_POINTER;
     *ppv = NULL;
-    ATLTRY (theMenuBar = new CComObject<CToolsBand>);
-    if (theMenuBar == NULL)
+    ATLTRY(theToolbar = new CComObject<CToolsBand>);
+    if (theToolbar == NULL)
         return E_OUTOFMEMORY;
-    hResult = theMenuBar->QueryInterface(riid, reinterpret_cast<void **>(ppv));
+    hResult = theToolbar->QueryInterface(riid, reinterpret_cast<void **>(ppv));
     if (FAILED(hResult))
     {
-        delete theMenuBar;
+        delete theToolbar;
         return hResult;
     }
     return S_OK;
index 1caa3f9..1f3a5f7 100644 (file)
@@ -1382,7 +1382,6 @@ void CDefView::DoActivate(UINT uState)
             INT mic = GetMenuItemCount(m_hMenu);
             for (int i = 0; i < mic; i++)
             {
-                HMENU submenu = GetSubMenu(m_hMenu, 0);
                 DeleteMenu(m_hMenu, 0, MF_BYPOSITION);
             }