From: David Quintana Date: Tue, 28 Oct 2014 21:40:50 +0000 (+0000) Subject: [RSHELL] X-Git-Tag: backups/shell-experiments@75904~101 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=40a2e0335930e80b98286766aeee3028d3075d37 [RSHELL] * CMenuBand: Refcount before assigning a return pointer. * CMenuDeskBar: Revert change and protect the refcounting in case I was wrong to assume there will be exactly one OnFinalMessage for each OnCreate. * CMenuToolbars: Add a debug message. * CStartMenu: Refcount correctly. svn path=/branches/shell-experiments/; revision=65088 --- diff --git a/base/shell/rshell/CMenuBand.cpp b/base/shell/rshell/CMenuBand.cpp index b3d162a2b41..a9979b95f38 100644 --- a/base/shell/rshell/CMenuBand.cpp +++ b/base/shell/rshell/CMenuBand.cpp @@ -628,21 +628,22 @@ HRESULT STDMETHODCALLTYPE CMenuBand::SetClient(IUnknown *punkClient) return S_OK; } - HRESULT hr = punkClient->QueryInterface(IID_PPV_ARG(IMenuPopup, &m_subMenuChild)); - - return hr; + return punkClient->QueryInterface(IID_PPV_ARG(IMenuPopup, &m_subMenuChild)); } HRESULT STDMETHODCALLTYPE CMenuBand::GetClient(IUnknown **ppunkClient) { // HACK, so I can test for a submenu in the DeskBar - if (ppunkClient) + if (!ppunkClient) + return E_POINTER; + *ppunkClient = NULL; + + if (m_subMenuChild) { - if (m_subMenuChild) - *ppunkClient = m_subMenuChild; - else - *ppunkClient = NULL; + m_subMenuChild->AddRef(); + *ppunkClient = m_subMenuChild; } + return S_OK; } diff --git a/base/shell/rshell/CMenuDeskBar.cpp b/base/shell/rshell/CMenuDeskBar.cpp index bece0f42e3b..673e7933a29 100644 --- a/base/shell/rshell/CMenuDeskBar.cpp +++ b/base/shell/rshell/CMenuDeskBar.cpp @@ -39,7 +39,8 @@ CMenuDeskBar::CMenuDeskBar() : m_IconSize(0), m_Banner(NULL), m_Shown(FALSE), - m_ShowFlags(0) + m_ShowFlags(0), + m_didAddRef(FALSE) { } @@ -49,7 +50,11 @@ CMenuDeskBar::~CMenuDeskBar() LRESULT CMenuDeskBar::_OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { - this->AddRef(); + if (!m_didAddRef) + { + this->AddRef(); + m_didAddRef = TRUE; + } bHandled = FALSE; return 0; @@ -57,6 +62,11 @@ LRESULT CMenuDeskBar::_OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &b void CMenuDeskBar::OnFinalMessage(HWND /* hWnd */) { + if (m_didAddRef) + { + this->Release(); + m_didAddRef = FALSE; + } } HRESULT STDMETHODCALLTYPE CMenuDeskBar::Initialize(THIS) diff --git a/base/shell/rshell/CMenuDeskBar.h b/base/shell/rshell/CMenuDeskBar.h index 51a5cd0c7ad..7c63a187a67 100644 --- a/base/shell/rshell/CMenuDeskBar.h +++ b/base/shell/rshell/CMenuDeskBar.h @@ -50,6 +50,8 @@ private: BOOL m_Shown; DWORD m_ShowFlags; + BOOL m_didAddRef; + virtual void OnFinalMessage(HWND hWnd); public: CMenuDeskBar(); diff --git a/base/shell/rshell/CMenuToolbars.cpp b/base/shell/rshell/CMenuToolbars.cpp index 88e885ee336..aa879a24c2f 100644 --- a/base/shell/rshell/CMenuToolbars.cpp +++ b/base/shell/rshell/CMenuToolbars.cpp @@ -1374,6 +1374,7 @@ HRESULT CMenuSFToolbar::GetShellFolder(DWORD *pdwFlags, LPITEMIDLIST *ppidl, REF pidl = ILClone(m_idList); if (!pidl) { + ERR("ILClone failed!\n"); (*reinterpret_cast(ppv))->Release(); return E_FAIL; } diff --git a/base/shell/rshell/CStartMenu.cpp b/base/shell/rshell/CStartMenu.cpp index bc46d5edf1a..79c7864a5d2 100644 --- a/base/shell/rshell/CStartMenu.cpp +++ b/base/shell/rshell/CStartMenu.cpp @@ -262,16 +262,13 @@ public: IBandSite* pBandSite, IDeskBar* pDeskBar) { - m_pShellMenu.Attach(pShellMenu); - m_pBandSite.Attach(pBandSite); - m_pDeskBar.Attach(pDeskBar); + m_pShellMenu = pShellMenu; + m_pBandSite = pBandSite; + m_pDeskBar = pDeskBar; } ~CShellMenuCallback() { - m_pShellMenu.Release(); - m_pBandSite.Release(); - m_pDeskBar.Release(); } HRESULT _SetProgramsFolder(IShellFolder * psf, LPITEMIDLIST pidl) diff --git a/base/shell/rshell/precomp.h b/base/shell/rshell/precomp.h index 9b23dbe2c0b..c1d1fee1816 100644 --- a/base/shell/rshell/precomp.h +++ b/base/shell/rshell/precomp.h @@ -38,9 +38,9 @@ #define COBJMACROS //#define DEBUG_CCOMOBJECT -//#define DEBUG_CCOMOBJECT_CREATION 1 -//#define DEBUG_CCOMOBJECT_DESTRUCTION 1 -//#define DEBUG_CCOMOBJECT_REFCOUNTING 0 +#define DEBUG_CCOMOBJECT_CREATION 1 +#define DEBUG_CCOMOBJECT_DESTRUCTION 1 +#define DEBUG_CCOMOBJECT_REFCOUNTING 1 #include #include diff --git a/include/reactos/undocshell.h b/include/reactos/undocshell.h index 426efea0bc2..5b1e785b5ae 100644 --- a/include/reactos/undocshell.h +++ b/include/reactos/undocshell.h @@ -730,6 +730,24 @@ void ReleaseCComPtrExpectZero(CComPtr& cptr, BOOL forceRelease = FALSE) } } +template +HRESULT inline ShellDebugObjectCreator(REFIID riid, R ** ppv) +{ + CComPtr obj; + HRESULT hResult; + + if (ppv == NULL) + return E_POINTER; + *ppv = NULL; + ATLTRY(obj = new CComDebugObject); + if (obj.p == NULL) + return E_OUTOFMEMORY; + hResult = obj->QueryInterface(riid, reinterpret_cast(ppv)); + if (FAILED(hResult)) + return hResult; + return S_OK; +} + template HRESULT inline ShellObjectCreator(REFIID riid, R ** ppv) {