From 2594edcec099e3e47080f6fd826d79477510f315 Mon Sep 17 00:00:00 2001 From: hereafter Date: Tue, 2 Feb 2021 01:30:54 +0800 Subject: [PATCH] Fix crash in explorer background context menu logic (#8977) Fix a bug brought in with PR: #8638 see, #8936 #8638 * [x] Closes #8936 * [x] CLA signed * [x] Tests passed With the help from @nc-x, the issue is reproduced and fixed by this patch. CLSCTX_IN_PROCESS is not good enough for all cases to create IShellWindows interface. Put a CLSCTX_ALL fixes the issue. Another debugging warning dialogs for reusing not null com_ptr in the loop is fixed too. (This was shown in debug builds only) (cherry picked from commit e207236713d475b337947ae60174ec2cd4db7ce2) --- src/cascadia/ShellExtension/OpenTerminalHere.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cascadia/ShellExtension/OpenTerminalHere.cpp b/src/cascadia/ShellExtension/OpenTerminalHere.cpp index bd748338d7a..e50c249986c 100644 --- a/src/cascadia/ShellExtension/OpenTerminalHere.cpp +++ b/src/cascadia/ShellExtension/OpenTerminalHere.cpp @@ -266,7 +266,16 @@ std::wstring OpenTerminalHere::_GetPathFromExplorer() const return path; } - auto shell = create_instance(CLSID_ShellWindows); + com_ptr shell; + try + { + shell = create_instance(CLSID_ShellWindows, CLSCTX_ALL); + } + catch (...) + { + //look like try_create_instance is not available no more + } + if (shell == nullptr) { return path; @@ -285,6 +294,7 @@ std::wstring OpenTerminalHere::_GetPathFromExplorer() const com_ptr tmp; if (FAILED(disp->QueryInterface(tmp.put()))) { + disp = nullptr; // get rid of DEBUG non-nullptr warning continue; } @@ -293,8 +303,11 @@ std::wstring OpenTerminalHere::_GetPathFromExplorer() const if (hwnd == tmpHWND) { browser = tmp; + disp = nullptr; // get rid of DEBUG non-nullptr warning break; //found } + + disp = nullptr; // get rid of DEBUG non-nullptr warning } if (browser != nullptr)