Search code examples
windowswinapiexplorerwindows-explorerwindows-shell

DragDropHandlers IShellExtInit::Initialize and NETHOOD UNC paths


I have a shell extension registered under HKCR\Folder\shellex\DragDropHandlers and I need to call GetVolumePathName()+GetVolumeInformation() on the target folder (PIDL passed to you in IShellExtInit::Initialize)

The problem is that when something is dropped on a "Nethood shortcut" (My Network Places\sharename) the PIDL passed to Initialize refers to the Nethood shortcut and not the UNC path! (Calling SHGetPathFromIDList on the PIDL returns "%USERPROFILE%\NetHood\SHARE on MACHINE" and not "\\MACHINE\SHARE" like you would expect)

I also tried creating a IShellItem of the PIDL and calling IShellItem::GetDisplayName with various SIGDN values but none of them return the UNC path.

How can I get the UNC path from this PIDL?


Solution

  • // error checking omitted
    IShellFolder* pFolder = NULL;
    LPCITEMIDLIST pidlChild = NULL;
    hr = SHBindToParent(pidl, IID_IShellFolder, (void**)&pFolder, &pidlChild);
    SFGAOF Attributes = SFGAO_LINK;
    hr = pFolder->GetAttributesOf(1, &pidlChild, &Attributes);
    if(Attributes & SFGAO_LINK)
    {
        // item is a link; get it's target path
        IShellLink* pLink = NULL;
        hr = pFolder->GetUIObjectOf(NULL, 1, &pidlChild, IID_IShellLink, NULL, (void**)&pLink);
        TCHAR szPath[MAX_PATH];
        hr = pLink->GetPath(szPath, MAX_PATH, NULL, 0); // szPath now contains path of UNC share
        pLink->Release();
        pLink = NULL;
    }
    pFolder->Release();
    pFolder = NULL;