Skip to content

Commit 9752afb

Browse files
committed
ModernSettings: Use smart pointers
1 parent e210b4a commit 9752afb

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

Src/StartMenu/StartMenuHelper/ModernSettingsContextMenu.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "stdafx.h"
66
#include "ModernSettings.h"
77
#include "ModernSettingsContextMenu.h"
8+
#include "ComHelper.h"
89

910
#define MENUVERB_OPEN 0
1011

@@ -177,13 +178,10 @@ HRESULT CModernSettingsContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO pici)
177178
{
178179
if (uID == MENUVERB_OPEN && m_pdtobj)
179180
{
180-
LPITEMIDLIST pidl;
181+
CAbsolutePidl pidl;
181182
hr = SHGetIDListFromObject(m_pdtobj, &pidl);
182183
if (SUCCEEDED(hr))
183-
{
184184
hr = OpenItemByPidl(pidl);
185-
ILFree(pidl);
186-
}
187185
}
188186
}
189187

Src/StartMenu/StartMenuHelper/ModernSettingsShellFolder.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ HRESULT CModernSettingsShellFolder::GetUIObjectOf(HWND hwnd, UINT cidl, PCUITEMI
341341
{
342342
if (!s.icon.empty())
343343
{
344-
IDefaultExtractIconInit* pdxi;
344+
CComPtr<IDefaultExtractIconInit> pdxi;
345345
hr = SHCreateDefaultExtractIcon(IID_PPV_ARGS(&pdxi));
346346
if (SUCCEEDED(hr))
347347
{
@@ -353,8 +353,6 @@ HRESULT CModernSettingsShellFolder::GetUIObjectOf(HWND hwnd, UINT cidl, PCUITEMI
353353
hr = pdxi->SetNormalIcon(icon_path, location);
354354
if (SUCCEEDED(hr))
355355
hr = pdxi->QueryInterface(riid, ppv);
356-
357-
pdxi->Release();
358356
}
359357
}
360358
else
@@ -368,7 +366,6 @@ HRESULT CModernSettingsShellFolder::GetUIObjectOf(HWND hwnd, UINT cidl, PCUITEMI
368366
extract->SetGlyph(glyph);
369367
hr = extract->QueryInterface(riid, ppv);
370368
}
371-
372369
}
373370
}
374371
}
@@ -409,16 +406,14 @@ HRESULT CModernSettingsShellFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl, SHGDN
409406
else
410407
{
411408
WCHAR szDisplayName[MAX_PATH];
412-
PWSTR pszThisFolder;
409+
CComString pszThisFolder;
413410
hr = SHGetNameFromIDList(m_pidl, (shgdnFlags & SHGDN_FORADDRESSBAR) ? SIGDN_DESKTOPABSOLUTEEDITING : SIGDN_DESKTOPABSOLUTEPARSING, &pszThisFolder);
414411
if (SUCCEEDED(hr))
415412
{
416413
StringCchCopy(szDisplayName, ARRAYSIZE(szDisplayName), pszThisFolder);
417414
StringCchCat(szDisplayName, ARRAYSIZE(szDisplayName), L"\\");
418415
StringCchCat(szDisplayName, ARRAYSIZE(szDisplayName), setting.fileName.data());
419416

420-
CoTaskMemFree(pszThisFolder);
421-
422417
hr = StringToStrRet(szDisplayName, pName);
423418
}
424419
}
@@ -535,7 +530,7 @@ HRESULT CModernSettingsShellFolder::GetClassID(CLSID* pClassID)
535530
// IPersistFolder method
536531
HRESULT CModernSettingsShellFolder::Initialize(PCIDLIST_ABSOLUTE pidl)
537532
{
538-
m_pidl = ILCloneFull(pidl);
533+
m_pidl = pidl;
539534
return m_pidl ? S_OK : E_FAIL;
540535
}
541536

Src/StartMenu/StartMenuHelper/ModernSettingsShellFolder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#pragma once
55
#include "resource.h"
6+
#include "ComHelper.h"
67
#include "StartMenuHelper_i.h"
78
#include <shlobj.h>
89
#include <string>
@@ -78,7 +79,7 @@ END_COM_MAP()
7879
private:
7980
std::wstring_view GetColumnDisplayName(PCUITEMID_CHILD pidl, UINT iColumn);
8081

81-
PIDLIST_ABSOLUTE m_pidl = nullptr; // where this folder is in the name space
82+
CAbsolutePidl m_pidl; // where this folder is in the name space
8283
};
8384

8485
OBJECT_ENTRY_AUTO(__uuidof(ModernSettingsShellFolder), CModernSettingsShellFolder)

0 commit comments

Comments
 (0)