Skip to content

Commit

Permalink
Fix crash in explorer background context menu logic (#8977)
Browse files Browse the repository at this point in the history
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 e207236)
  • Loading branch information
hereafter authored and DHowett committed Feb 5, 2021
1 parent b092bdd commit 2594edc
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/cascadia/ShellExtension/OpenTerminalHere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,16 @@ std::wstring OpenTerminalHere::_GetPathFromExplorer() const
return path;
}

auto shell = create_instance<IShellWindows>(CLSID_ShellWindows);
com_ptr<IShellWindows> shell;
try
{
shell = create_instance<IShellWindows>(CLSID_ShellWindows, CLSCTX_ALL);
}
catch (...)
{
//look like try_create_instance is not available no more
}

if (shell == nullptr)
{
return path;
Expand All @@ -285,6 +294,7 @@ std::wstring OpenTerminalHere::_GetPathFromExplorer() const
com_ptr<IWebBrowserApp> tmp;
if (FAILED(disp->QueryInterface(tmp.put())))
{
disp = nullptr; // get rid of DEBUG non-nullptr warning
continue;
}

Expand All @@ -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)
Expand Down

0 comments on commit 2594edc

Please sign in to comment.