Get file path in shell extension
See the question and my original answer on StackOverflowI quote the official IShellExtInit::Initialize method documentation:
For shortcut menu extensions, pdtobj identifies the selected file objects, hkeyProgID identifies the file type of the object with focus, and pidlFolder is either NULL (for file objects) or specifies the folder for which the shortcut menu is being requested (for folder background shortcut menus).
So in your case, pidlFolder
is probably NULL, and anyway you're mostly interested by the selected Shell Item(s); there can be more than one item selected when the context menu was invoked.
So, instead, use the SHCreateShellItemArrayFromDataObject method on pdtobj
, enumerate all Shell Items from there and use IShellItem::GetDisplayName on each item.
For the Shell Item's "name", note you can use SIGDN_FILESYSPATH
if you're sure it's a file system file, but you can also use SIGDN_DESKTOPABSOLUTEPARSING
for "virtual" Shell Items (items from other namespace extensions for example).