dahall / Vanara

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
MIT License
1.81k stars 196 forks source link

ContextMenu related problems #468

Closed zhuxb711 closed 5 months ago

zhuxb711 commented 6 months ago

Describe the bug and how to reproduce

  1. InvokeVerb will not work if do not enum the ContextMenu of a ShellItem
  2. Throw exception at here if failure using .ThrowIfFailed() https://github.com/dahall/Vanara/blob/fe637c0ec3a6803a95e602063bf303cc5a6a78a7/Windows.Shell.Common/ShellObjects/ShellContextMenu.cs#L225

What code is involved

For problem 1:

Work:

ShellContextMenu ContextMenu = new ShellItem("<File path>").ContextMenu;

if (ContextMenu.GetItems(Shell32.CMF.CMF_DEFAULTONLY).FirstOrDefault((Item) => string.Equals(Item.Verb, "open", StringComparison.OrdinalIgnoreCase)) is ShellContextMenu.MenuItemInfo Info)
{
    ContextMenu.InvokeVerb(Info.Verb);
}

Not work:

ShellFile.ShellCoreItem.ContextMenu.InvokeVerb("open");

Expected behavior

  1. InvokeVerb() should work at both situation
  2. InvokeVerb() should throw exception rather than failed silently.
dahall commented 6 months ago

Fixed in upcoming 4.0.2. Thanks for hint.