Skip to content

Commit 86a3ce2

Browse files
committed
Change ComPtr from atl to wrl
1 parent 32519b4 commit 86a3ce2

File tree

4 files changed

+41
-50
lines changed

4 files changed

+41
-50
lines changed

Explorer.vcxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
<Link>
106106
<GenerateDebugInformation>true</GenerateDebugInformation>
107107
<SubSystem>Windows</SubSystem>
108-
<AdditionalDependencies>Comctl32.lib;Mpr.lib;UxTheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
108+
<AdditionalDependencies>Comctl32.lib;Shlwapi.lib;Mpr.lib;UxTheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
109109
</Link>
110110
<Midl>
111111
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -119,7 +119,7 @@
119119
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120120
</ResourceCompile>
121121
<PostBuildEvent>
122-
<Command>copy "$(TargetPath)" "D:\Applications\Notepad++x86\plugins\Explorer</Command>
122+
<Command>copy /Y "$(TargetPath)" "D:\apps\Notepad++\plugins\Explorer"</Command>
123123
</PostBuildEvent>
124124
</ItemDefinitionGroup>
125125
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -140,7 +140,7 @@
140140
<Link>
141141
<GenerateDebugInformation>true</GenerateDebugInformation>
142142
<SubSystem>Windows</SubSystem>
143-
<AdditionalDependencies>Comctl32.lib;Mpr.lib;UxTheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
143+
<AdditionalDependencies>Comctl32.lib;Shlwapi.lib;Mpr.lib;UxTheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
144144
</Link>
145145
<Midl>
146146
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -174,7 +174,7 @@
174174
<ForcedIncludeFiles>pch.h</ForcedIncludeFiles>
175175
</ClCompile>
176176
<Link>
177-
<AdditionalDependencies>odbc32.lib;odbccp32.lib;shlwapi.lib;Msimg32.lib;Comctl32.lib;Mpr.lib;UxTheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
177+
<AdditionalDependencies>Comctl32.lib;Shlwapi.lib;Msimg32.lib;Mpr.lib;UxTheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
178178
<GenerateDebugInformation>true</GenerateDebugInformation>
179179
<SubSystem>Windows</SubSystem>
180180
<OptimizeReferences>true</OptimizeReferences>
@@ -193,7 +193,7 @@
193193
<Culture>0x0407</Culture>
194194
</ResourceCompile>
195195
<PostBuildEvent>
196-
<Command>copy "$(TargetPath)" "D:\Applications\Notepad++x86\plugins\Explorer</Command>
196+
<Command>copy /Y "$(TargetPath)" "D:\apps\Notepad++\plugins\Explorer"</Command>
197197
</PostBuildEvent>
198198
</ItemDefinitionGroup>
199199
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -213,7 +213,7 @@
213213
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
214214
</ClCompile>
215215
<Link>
216-
<AdditionalDependencies>odbc32.lib;odbccp32.lib;shlwapi.lib;Msimg32.lib;Comctl32.lib;Mpr.lib;UxTheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
216+
<AdditionalDependencies>Comctl32.lib;Shlwapi.lib;Msimg32.lib;Mpr.lib;UxTheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
217217
<GenerateDebugInformation>true</GenerateDebugInformation>
218218
<SubSystem>Windows</SubSystem>
219219
<OptimizeReferences>true</OptimizeReferences>

src/Explorer/ContextMenu.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
3131

3232
#include "Explorer.h"
3333

34-
struct __declspec(uuid("000214e6-0000-0000-c000-000000000046")) IShellFolder;
35-
3634
class ContextMenu
3735
{
3836
public:

src/Explorer/Explorer.cpp

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2626
#include <shlwapi.h>
2727
#include <shlobj.h>
2828
#include <dbt.h>
29-
#include <atlbase.h>
30-
3129
#include <ranges>
30+
#include <wrl/client.h>
3231

3332
#include "NppInterface.h"
3433
#include "ExplorerDialog.h"
@@ -241,10 +240,10 @@ extern "C" __declspec(dllexport) void setInfo(NppData notpadPlusData)
241240
helpDlg .init(g_hInst, g_nppData._nppHandle);
242241

243242
explorerDlg.VisibleChanged([](bool visible) {
244-
::SendMessage(g_nppData._nppHandle, NPPM_SETMENUITEMCHECK, funcItem[0]._cmdID, (LPARAM)visible);
243+
::SendMessage(g_nppData._nppHandle, NPPM_SETMENUITEMCHECK, funcItem[DOCKABLE_EXPLORER_INDEX]._cmdID, (LPARAM)visible);
245244
});
246245
favesDlg.VisibleChanged([](bool visible) {
247-
::SendMessage(g_nppData._nppHandle, NPPM_SETMENUITEMCHECK, funcItem[1]._cmdID, (LPARAM)visible);
246+
::SendMessage(g_nppData._nppHandle, NPPM_SETMENUITEMCHECK, funcItem[DOCKABLE_FAVORTIES_INDEX]._cmdID, (LPARAM)visible);
248247
});
249248

250249
/* Subclassing for Notepad */
@@ -896,46 +895,40 @@ void ExtractIcons(LPCTSTR currentPath, LPCTSTR fileName, DevType type, LPINT piI
896895
}
897896

898897
// Resolve files if they are shortcuts
899-
HRESULT ResolveShortCut(const std::wstring &shortcutPath, LPTSTR lpszFilePath, int maxBuf)
898+
HRESULT ResolveShortCut(const std::wstring &shortcutPath, LPWSTR lpszFilePath, int maxBuf)
900899
{
901-
HRESULT hRes = S_FALSE;
902-
CComPtr<IShellLink> ipShellLink;
903-
lpszFilePath[0] = '\0';
904-
905-
// Get a pointer to the IShellLink interface
906-
hRes = CoCreateInstance(CLSID_ShellLink,
907-
nullptr,
908-
CLSCTX_INPROC_SERVER,
909-
IID_IShellLink,
910-
(void**)&ipShellLink);
911-
912-
if (hRes == S_OK) {
913-
// Get a pointer to the IPersistFile interface
914-
CComQIPtr<IPersistFile> ipPersistFile(ipShellLink);
915-
916-
// Open the shortcut file and initialize it from its contents
917-
hRes = ipPersistFile->Load(shortcutPath.c_str(), STGM_READ);
918-
if (hRes == S_OK) {
919-
// Try to find the target of a shortcut, even if it has been moved or renamed
920-
hRes = ipShellLink->Resolve(nullptr, SLR_UPDATE);
921-
if (hRes == S_OK) {
922-
// Get the path to the shortcut target
923-
WCHAR szPath[MAX_PATH];
924-
hRes = ipShellLink->GetPath(szPath, MAX_PATH, nullptr, SLGP_RAWPATH);
925-
if (hRes == S_OK) {
926-
_tcsncpy(lpszFilePath, szPath, maxBuf);
927-
928-
if (::PathIsDirectory(lpszFilePath) != FALSE) {
929-
if (lpszFilePath[wcslen(lpszFilePath) - 1] != '\\') {
930-
wcsncat(lpszFilePath, L"\\", MAX_PATH);
931-
}
932-
}
933-
}
934-
}
935-
}
900+
Microsoft::WRL::ComPtr<IShellLink> shellLink;
901+
HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));
902+
if (FAILED(hr)) {
903+
return hr;
904+
}
905+
906+
Microsoft::WRL::ComPtr<IPersistFile> persistFile;
907+
hr = shellLink.As(&persistFile);
908+
if (FAILED(hr)) {
909+
return hr;
910+
}
911+
912+
hr = persistFile->Load(shortcutPath.c_str(), STGM_READ);
913+
if (FAILED(hr)) {
914+
return hr;
915+
}
916+
917+
hr = shellLink->Resolve(nullptr, SLR_UPDATE);
918+
if (FAILED(hr)) {
919+
return hr;
920+
}
921+
922+
hr = shellLink->GetPath(lpszFilePath, maxBuf, nullptr, SLGP_RAWPATH);
923+
if (FAILED(hr)) {
924+
return hr;
925+
}
926+
927+
if (::PathIsDirectory(lpszFilePath) && lpszFilePath[wcslen(lpszFilePath) - 1] != L'\\') {
928+
wcsncat_s(lpszFilePath, maxBuf, L"\\", 1);
936929
}
937930

938-
return hRes;
931+
return S_OK;
939932
}
940933

941934

src/Explorer/Explorer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ HIMAGELIST GetSmallImageList(BOOL bSystem);
175175
void ExtractIcons(LPCTSTR currentPath, LPCTSTR fileName, DevType type, LPINT iIconNormal, LPINT iIconSelected, LPINT iIconOverlayed);
176176

177177
/* Resolve Links */
178-
HRESULT ResolveShortCut(const std::wstring& shortcutPath, LPTSTR lpszFilePath, int maxBuf);
178+
HRESULT ResolveShortCut(const std::wstring& shortcutPath, LPWSTR lpszFilePath, int maxBuf);
179179

180180
/* current open files */
181181
void UpdateDocs();

0 commit comments

Comments
 (0)