Skip to content

Commit

Permalink
[ImageResizer]Fix silent context menu crash (#22503)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimecbernardo committed Dec 5, 2022
1 parent ba9e244 commit d300b00
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class __declspec(uuid("8F491918-259F-451A-950F-8C3EBF4864AF")) ImageResizerConte

IFACEMETHODIMP GetState(_In_opt_ IShellItemArray* selection, _In_ BOOL okToBeSlow, _Out_ EXPCMDSTATE* cmdState)
{
if (nullptr == selection) {
// We've observed that it's possible that a null gets passed instead of an empty array. Just don't show the context menu in this case.
*cmdState = ECS_HIDDEN;
return S_OK;
}

if (!CSettingsInstance().GetEnabled())
{
*cmdState = ECS_HIDDEN;
Expand All @@ -90,9 +96,14 @@ class __declspec(uuid("8F491918-259F-451A-950F-8C3EBF4864AF")) ImageResizerConte
#pragma warning(suppress : 26812)
PERCEIVED type;
PERCEIVEDFLAG flag;
IShellItem* shellItem;
IShellItem* shellItem=nullptr;
//Check extension of first item in the list (the item which is right-clicked on)
selection->GetItemAt(0, &shellItem);
HRESULT getItemResult = selection->GetItemAt(0, &shellItem);
if (S_OK != getItemResult || nullptr == shellItem) {
// Some safeguards to avoid runtime errors.
*cmdState = ECS_HIDDEN;
return S_OK;
}
LPTSTR pszPath;
// Retrieves the entire file system path of the file from its shell item
shellItem->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
Expand Down

0 comments on commit d300b00

Please sign in to comment.