From 9752afbebc27962946466c0a4f23f4ca2af34bb7 Mon Sep 17 00:00:00 2001 From: ge0rdi Date: Mon, 31 Aug 2020 20:11:50 +0200 Subject: [PATCH] ModernSettings: Use smart pointers --- .../StartMenuHelper/ModernSettingsContextMenu.cpp | 6 ++---- .../StartMenuHelper/ModernSettingsShellFolder.cpp | 11 +++-------- .../StartMenuHelper/ModernSettingsShellFolder.h | 3 ++- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Src/StartMenu/StartMenuHelper/ModernSettingsContextMenu.cpp b/Src/StartMenu/StartMenuHelper/ModernSettingsContextMenu.cpp index 6deee67..bf282fe 100644 --- a/Src/StartMenu/StartMenuHelper/ModernSettingsContextMenu.cpp +++ b/Src/StartMenu/StartMenuHelper/ModernSettingsContextMenu.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "ModernSettings.h" #include "ModernSettingsContextMenu.h" +#include "ComHelper.h" #define MENUVERB_OPEN 0 @@ -177,13 +178,10 @@ HRESULT CModernSettingsContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO pici) { if (uID == MENUVERB_OPEN && m_pdtobj) { - LPITEMIDLIST pidl; + CAbsolutePidl pidl; hr = SHGetIDListFromObject(m_pdtobj, &pidl); if (SUCCEEDED(hr)) - { hr = OpenItemByPidl(pidl); - ILFree(pidl); - } } } diff --git a/Src/StartMenu/StartMenuHelper/ModernSettingsShellFolder.cpp b/Src/StartMenu/StartMenuHelper/ModernSettingsShellFolder.cpp index 37ba950..a9e973e 100644 --- a/Src/StartMenu/StartMenuHelper/ModernSettingsShellFolder.cpp +++ b/Src/StartMenu/StartMenuHelper/ModernSettingsShellFolder.cpp @@ -341,7 +341,7 @@ HRESULT CModernSettingsShellFolder::GetUIObjectOf(HWND hwnd, UINT cidl, PCUITEMI { if (!s.icon.empty()) { - IDefaultExtractIconInit* pdxi; + CComPtr pdxi; hr = SHCreateDefaultExtractIcon(IID_PPV_ARGS(&pdxi)); if (SUCCEEDED(hr)) { @@ -353,8 +353,6 @@ HRESULT CModernSettingsShellFolder::GetUIObjectOf(HWND hwnd, UINT cidl, PCUITEMI hr = pdxi->SetNormalIcon(icon_path, location); if (SUCCEEDED(hr)) hr = pdxi->QueryInterface(riid, ppv); - - pdxi->Release(); } } else @@ -368,7 +366,6 @@ HRESULT CModernSettingsShellFolder::GetUIObjectOf(HWND hwnd, UINT cidl, PCUITEMI extract->SetGlyph(glyph); hr = extract->QueryInterface(riid, ppv); } - } } } @@ -409,7 +406,7 @@ HRESULT CModernSettingsShellFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl, SHGDN else { WCHAR szDisplayName[MAX_PATH]; - PWSTR pszThisFolder; + CComString pszThisFolder; hr = SHGetNameFromIDList(m_pidl, (shgdnFlags & SHGDN_FORADDRESSBAR) ? SIGDN_DESKTOPABSOLUTEEDITING : SIGDN_DESKTOPABSOLUTEPARSING, &pszThisFolder); if (SUCCEEDED(hr)) { @@ -417,8 +414,6 @@ HRESULT CModernSettingsShellFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl, SHGDN StringCchCat(szDisplayName, ARRAYSIZE(szDisplayName), L"\\"); StringCchCat(szDisplayName, ARRAYSIZE(szDisplayName), setting.fileName.data()); - CoTaskMemFree(pszThisFolder); - hr = StringToStrRet(szDisplayName, pName); } } @@ -535,7 +530,7 @@ HRESULT CModernSettingsShellFolder::GetClassID(CLSID* pClassID) // IPersistFolder method HRESULT CModernSettingsShellFolder::Initialize(PCIDLIST_ABSOLUTE pidl) { - m_pidl = ILCloneFull(pidl); + m_pidl = pidl; return m_pidl ? S_OK : E_FAIL; } diff --git a/Src/StartMenu/StartMenuHelper/ModernSettingsShellFolder.h b/Src/StartMenu/StartMenuHelper/ModernSettingsShellFolder.h index a6d84b4..e5d0a31 100644 --- a/Src/StartMenu/StartMenuHelper/ModernSettingsShellFolder.h +++ b/Src/StartMenu/StartMenuHelper/ModernSettingsShellFolder.h @@ -3,6 +3,7 @@ #pragma once #include "resource.h" +#include "ComHelper.h" #include "StartMenuHelper_i.h" #include #include @@ -78,7 +79,7 @@ END_COM_MAP() private: std::wstring_view GetColumnDisplayName(PCUITEMID_CHILD pidl, UINT iColumn); - PIDLIST_ABSOLUTE m_pidl = nullptr; // where this folder is in the name space + CAbsolutePidl m_pidl; // where this folder is in the name space }; OBJECT_ENTRY_AUTO(__uuidof(ModernSettingsShellFolder), CModernSettingsShellFolder)