ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
October 2022
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
23 participants
162 discussions
Start a n
N
ew thread
[reactos] 01/02: [ATL] Prohibit the use of AddRef/Release on objects inside CComPtr
by Mark Jansen
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a414c88daeb4ba91e0cc1…
commit a414c88daeb4ba91e0cc121f7cfbf51ef2d3151a Author: Mark Jansen <mark.jansen(a)reactos.org> AuthorDate: Sun Sep 18 20:57:38 2022 +0200 Commit: Mark Jansen <mark.jansen(a)reactos.org> CommitDate: Sun Oct 2 00:38:23 2022 +0200 [ATL] Prohibit the use of AddRef/Release on objects inside CComPtr This mimics what MS's CComPtr is doing:
https://learn.microsoft.com/en-us/cpp/atl/reference/ccomptrbase-class?view=…
The reasoning behind this is that AddRef/Release is handled by the CComPtr, so anyone calling that is most likely not using the CComPtr correct. --- sdk/lib/atl/atlcomcli.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sdk/lib/atl/atlcomcli.h b/sdk/lib/atl/atlcomcli.h index cba78101d2d..e6effc2ffcf 100644 --- a/sdk/lib/atl/atlcomcli.h +++ b/sdk/lib/atl/atlcomcli.h @@ -59,6 +59,13 @@ inline HRESULT AtlHresultFromLastError() throw() return HRESULT_FROM_WIN32(dwError); } +template <class T> +class _NoAddRefReleaseOnCComPtr : public T +{ + private: + virtual ULONG STDMETHODCALLTYPE AddRef() = 0; + virtual ULONG STDMETHODCALLTYPE Release() = 0; +}; template<class T> class CComPtr @@ -173,10 +180,10 @@ public: return p; } - T *operator -> () + _NoAddRefReleaseOnCComPtr<T> *operator -> () const { ATLASSERT(p != NULL); - return p; + return (_NoAddRefReleaseOnCComPtr<T> *)p; } };
2 years, 2 months
1
0
0
0
[reactos] 01/01: [SHELL32] CDefView: Rework context menu handling
by Mark Jansen
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=544b7344982bdd6a1e118…
commit 544b7344982bdd6a1e1180e1a9964744ff0653b0 Author: Mark Jansen <mark.jansen(a)reactos.org> AuthorDate: Thu Sep 22 23:03:21 2022 +0200 Commit: Mark Jansen <mark.jansen(a)reactos.org> CommitDate: Sun Oct 2 00:36:42 2022 +0200 [SHELL32] CDefView: Rework context menu handling Previously, we would share one object between a multitude of options. Now, the only two options that need to store something for later use each have their own space for it. The context menu always cleans up after itself, the File menu does not. CORE-18345 CORE-18361 CORE-18366 --- dll/win32/shell32/CDefView.cpp | 164 ++++++++++++++++++++++------------------- 1 file changed, 89 insertions(+), 75 deletions(-) diff --git a/dll/win32/shell32/CDefView.cpp b/dll/win32/shell32/CDefView.cpp index 98b597c59d4..0bff83e1c9f 100644 --- a/dll/win32/shell32/CDefView.cpp +++ b/dll/win32/shell32/CDefView.cpp @@ -58,7 +58,7 @@ typedef struct static void ClientToListView(HWND hwndLV, POINT *ppt) { - POINT Origin; + POINT Origin = {}; /* FIXME: LVM_GETORIGIN is broken. See CORE-17266 */ if (!ListView_GetOrigin(hwndLV, &Origin)) @@ -68,6 +68,33 @@ ClientToListView(HWND hwndLV, POINT *ppt) ppt->y += Origin.y; } +// Helper struct to automatically cleanup the IContextMenu +// We want to explicitly reset the Site, so there are no circular references +struct MenuCleanup +{ + CComPtr<IContextMenu> &m_pCM; + HMENU &m_hMenu; + + MenuCleanup(CComPtr<IContextMenu> &pCM, HMENU& menu) + : m_pCM(pCM), m_hMenu(menu) + { + } + ~MenuCleanup() + { + if (m_hMenu) + { + DestroyMenu(m_hMenu); + m_hMenu = NULL; + } + if (m_pCM) + { + IUnknown_SetSite(m_pCM, NULL); + m_pCM.Release(); + } + } +}; + + class CDefView : public CWindowImpl<CDefView, CWindow, CControlWinTraits>, public CComObjectRootEx<CComMultiThreadModelNoCS>, @@ -116,6 +143,7 @@ class CDefView : DWORD m_grfKeyState; // CComPtr<IContextMenu> m_pCM; + CComPtr<IContextMenu> m_pFileMenu; BOOL m_isEditing; BOOL m_isParentFolderSpecial; @@ -169,7 +197,7 @@ class CDefView : void OnDeactivate(); void DoActivate(UINT uState); HRESULT drag_notify_subitem(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect); - HRESULT InvokeContextMenuCommand(UINT uCommand); + HRESULT InvokeContextMenuCommand(CComPtr<IContextMenu> &pCM, UINT uCommand); LRESULT OnExplorerCommand(UINT uCommand, BOOL bUseSelection); // *** IOleWindow methods *** @@ -1310,13 +1338,6 @@ HRESULT CDefView::FillFileMenu() if (!hFileMenu) return E_FAIL; - /* Release cached IContextMenu */ - if (m_pCM) - { - IUnknown_SetSite(m_pCM, NULL); - m_pCM.Release(); - } - /* Cleanup the items added previously */ for (int i = GetMenuItemCount(hFileMenu) - 1; i >= 0; i--) { @@ -1327,15 +1348,20 @@ HRESULT CDefView::FillFileMenu() m_cidl = m_ListView.GetSelectedCount(); - /* Store the context menu in m_pCM and keep it in order to invoke the selected command later on */ - HRESULT hr = GetItemObject((m_cidl ? SVGIO_SELECTION : SVGIO_BACKGROUND), - IID_PPV_ARG(IContextMenu, &m_pCM)); + /* In case we still have this left over, clean it up! */ + if (m_pFileMenu) + { + IUnknown_SetSite(m_pFileMenu, NULL); + m_pFileMenu.Release(); + } + /* Store the context menu in m_pFileMenu and keep it in order to invoke the selected command later on */ + HRESULT hr = GetItemObject((m_cidl ? SVGIO_SELECTION : SVGIO_BACKGROUND), IID_PPV_ARG(IContextMenu, &m_pFileMenu)); if (FAILED_UNEXPECTEDLY(hr)) return hr; HMENU hmenu = CreatePopupMenu(); - hr = m_pCM->QueryContextMenu(hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, 0); + hr = m_pFileMenu->QueryContextMenu(hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, 0); if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -1470,7 +1496,7 @@ UINT CDefView::GetSelections() return m_cidl; } -HRESULT CDefView::InvokeContextMenuCommand(UINT uCommand) +HRESULT CDefView::InvokeContextMenuCommand(CComPtr<IContextMenu> &pCM, UINT uCommand) { CMINVOKECOMMANDINFO cmi; @@ -1485,7 +1511,11 @@ HRESULT CDefView::InvokeContextMenuCommand(UINT uCommand) if (GetKeyState(VK_CONTROL) & 0x8000) cmi.fMask |= CMIC_MASK_CONTROL_DOWN; - HRESULT hr = m_pCM->InvokeCommand(&cmi); + HRESULT hr = pCM->InvokeCommand(&cmi); + // Most of our callers will do this, but in case they don't do that (File menu!) + IUnknown_SetSite(pCM, NULL); + pCM.Release(); + if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -1513,33 +1543,24 @@ HRESULT CDefView::OpenSelectedItems() if (!hMenu) return E_FAIL; - hResult = GetItemObject(SVGIO_SELECTION, IID_PPV_ARG(IContextMenu, &m_pCM)); + CComPtr<IContextMenu> pCM; + hResult = GetItemObject(SVGIO_SELECTION, IID_PPV_ARG(IContextMenu, &pCM)); + MenuCleanup _(pCM, hMenu); if (FAILED_UNEXPECTEDLY(hResult)) - goto cleanup; + return hResult; - hResult = m_pCM->QueryContextMenu(hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_DEFAULTONLY); + hResult = pCM->QueryContextMenu(hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_DEFAULTONLY); if (FAILED_UNEXPECTEDLY(hResult)) - goto cleanup; + return hResult; uCommand = GetMenuDefaultItem(hMenu, FALSE, 0); if (uCommand == (UINT)-1) { - hResult = E_FAIL; - goto cleanup; + ERR("GetMenuDefaultItem returned -1\n"); + return E_FAIL; } - InvokeContextMenuCommand(uCommand); - -cleanup: - - if (hMenu) - DestroyMenu(hMenu); - - if (m_pCM) - { - IUnknown_SetSite(m_pCM, NULL); - m_pCM.Release(); - } + InvokeContextMenuCommand(pCM, uCommand); return hResult; } @@ -1555,6 +1576,12 @@ LRESULT CDefView::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &b TRACE("(%p)\n", this); + if (m_hContextMenu != NULL) + { + ERR("HACK: Aborting context menu in nested call!\n"); + return 0; + } + m_hContextMenu = CreatePopupMenu(); if (!m_hContextMenu) return E_FAIL; @@ -1578,15 +1605,16 @@ LRESULT CDefView::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &b } m_cidl = m_ListView.GetSelectedCount(); - + /* In case we still have this left over, clean it up! */ hResult = GetItemObject( m_cidl ? SVGIO_SELECTION : SVGIO_BACKGROUND, IID_PPV_ARG(IContextMenu, &m_pCM)); + MenuCleanup _(m_pCM, m_hContextMenu); if (FAILED_UNEXPECTEDLY(hResult)) - goto cleanup; + return 0; /* Use 1 as the first id as we want 0 the mean that the user canceled the menu */ hResult = m_pCM->QueryContextMenu(m_hContextMenu, 0, CONTEXT_MENU_BASE_ID, FCIDM_SHVIEWLAST, CMF_NORMAL); if (FAILED_UNEXPECTEDLY(hResult)) - goto cleanup; + return 0; /* There is no position requested, so try to find one */ if (lParam == ~0) @@ -1624,29 +1652,17 @@ LRESULT CDefView::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &b y = pt.y; } + // This runs the message loop, calling back to us with f.e. WM_INITPOPUP (hence why m_hContextMenu and m_pCM exist) uCommand = TrackPopupMenu(m_hContextMenu, TPM_LEFTALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, x, y, 0, m_hWnd, NULL); if (uCommand == 0) - goto cleanup; + return 0; if (uCommand == FCIDM_SHVIEW_OPEN && OnDefaultCommand() == S_OK) - goto cleanup; - - InvokeContextMenuCommand(uCommand - CONTEXT_MENU_BASE_ID); + return 0; -cleanup: - if (m_pCM) - { - IUnknown_SetSite(m_pCM, NULL); - m_pCM.Release(); - } - - if (m_hContextMenu) - { - DestroyMenu(m_hContextMenu); - m_hContextMenu = NULL; - } + InvokeContextMenuCommand(m_pCM, uCommand - CONTEXT_MENU_BASE_ID); return 0; } @@ -1656,18 +1672,22 @@ LRESULT CDefView::OnExplorerCommand(UINT uCommand, BOOL bUseSelection) HRESULT hResult; HMENU hMenu = NULL; - hResult = GetItemObject( bUseSelection ? SVGIO_SELECTION : SVGIO_BACKGROUND, IID_PPV_ARG(IContextMenu, &m_pCM)); - if (FAILED_UNEXPECTEDLY( hResult)) - goto cleanup; + CComPtr<IContextMenu> pCM; + hResult = GetItemObject( bUseSelection ? SVGIO_SELECTION : SVGIO_BACKGROUND, IID_PPV_ARG(IContextMenu, &pCM)); + if (FAILED_UNEXPECTEDLY(hResult)) + return 0; + + MenuCleanup _(pCM, hMenu); + if ((uCommand != FCIDM_SHVIEW_DELETE) && (uCommand != FCIDM_SHVIEW_RENAME)) { hMenu = CreatePopupMenu(); if (!hMenu) return 0; - hResult = m_pCM->QueryContextMenu(hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL); + hResult = pCM->QueryContextMenu(hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL); if (FAILED_UNEXPECTEDLY(hResult)) - goto cleanup; + return 0; } if (bUseSelection) @@ -1690,18 +1710,7 @@ LRESULT CDefView::OnExplorerCommand(UINT uCommand, BOOL bUseSelection) return 0; } - InvokeContextMenuCommand(uCommand); - -cleanup: - if (m_pCM) - { - IUnknown_SetSite(m_pCM, NULL); - m_pCM.Release(); - } - - if (hMenu) - DestroyMenu(hMenu); - + InvokeContextMenuCommand(pCM, uCommand); return 0; } @@ -1936,10 +1945,12 @@ LRESULT CDefView::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHand case FCIDM_SHVIEW_NEWFOLDER: return OnExplorerCommand(dwCmdID, FALSE); default: - /* WM_COMMAND messages from the file menu are routed to the CDefView so as to let m_pCM handle the command */ - if (m_pCM && dwCmd == 0) + /* WM_COMMAND messages from the file menu are routed to the CDefView so as to let m_pFileMenu handle the command */ + if (m_pFileMenu && dwCmd == 0) { - InvokeContextMenuCommand(dwCmdID); + HMENU Dummy = NULL; + MenuCleanup _(m_pFileMenu, Dummy); + InvokeContextMenuCommand(m_pFileMenu, dwCmdID); } } @@ -2370,10 +2381,10 @@ HRESULT SHSetMenuIdInMenuMsg(UINT uMsg, LPARAM lParam, UINT CmdId); */ LRESULT CDefView::OnCustomItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { - if (!m_pCM.p) + if (!m_pCM) { /* no menu */ - ERR("no menu!!!\n"); + ERR("no context menu!!!\n"); return FALSE; } @@ -2409,7 +2420,10 @@ LRESULT CDefView::OnInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL int nPos = LOWORD(lParam); UINT menuItemId; - OnCustomItem(uMsg, wParam, lParam, bHandled); + if (m_pCM) + { + OnCustomItem(uMsg, wParam, lParam, bHandled); + } HMENU hViewMenu = GetSubmenuByID(m_hMenu, FCIDM_MENU_VIEW);
2 years, 2 months
1
0
0
0
← Newer
1
...
14
15
16
17
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Results per page:
10
25
50
100
200