DragDropHandlers IShellExtInit :: Initialize和NETHOOD UNC路径

时间:2011-04-22 08:08:24

标签: windows winapi explorer windows-explorer windows-shell

我在HKCR \ Folder \ shellex \ DragDropHandlers下注册了一个shell扩展,我需要在目标文件夹上调用GetVolumePathName()+ GetVolumeInformation()(在IShellExtInit::Initialize传递给你的PIDL)

问题在于,当某个东西被放在“Nethood快捷方式”(My Network Places\sharename)上时,传递给Initialize的PIDL指的是Nethood快捷方式,而不是UNC路径! (在PIDL上调用SHGetPathFromIDList会返回"%USERPROFILE%\NetHood\SHARE on MACHINE",而不是像您期望的那样返回"\\MACHINE\SHARE"

我还尝试创建PIDL的IShellItem并使用各种SIGDN值调用IShellItem :: GetDisplayName,但它们都没有返回UNC路径。

如何从此PIDL获取UNC路径?

1 个答案:

答案 0 :(得分:1)

// 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;