简体   繁体   English

如何从Windows库的GUID获取PIDL?

[英]How to get a PIDL from a Windows library's GUID?

How can I get the PIDL of a library from its GUID? 如何从其GUID获取库的PIDL?

For example, if I have the GUID of the Documents library ("{7B0DB17D-9CD2-4A93-9733-46CC89022E7C}"), how can I convert that into the library's ID list? 例如,如果我具有文档库的GUID(“ {7B0DB17D-9CD2-4A93-9733-46CC89022E7C}”),如何将其转换为库的ID列表?

I thought SHParseDisplayName would do the job, but it returns "file not found." 我以为SHParseDisplayName可以完成这项工作,但是它返回“找不到文件”。

Bear in mind that what I need is the PIDL of the library, not of its default folder. 请记住,我需要的是库的PIDL,而不是默认文件夹的PIDL。

This is straight C++, no .Net. 这是直接的C ++,没有.Net。

TIA TIA

Edit: This is the code that works, from the response below (without error checks). 编辑:这是从下面的响应(没有错误检查)起作用的代码。 guid is a GUID string prepended with 'shell:::', eg, 'shell:::{7B0DB17D-9CD2-4A93-9733-46CC89022E7C}'. guid是GUID字符串,前缀为'shell :::',例如'shell ::: {7B0DB17D-9CD2-4A93-9733-46CC89022E7C}。

IShellFolder* pDesktop;
LPITEMIDLIST pidl;
SHGetDesktopFolder(&pDesktop);
pDesktop->ParseDisplayName(nullptr, nullptr, guid, nullptr, &pidl, 0);

Edit 2: Even easier: SHParseDisplayName works if the 'shell:::' is prepended: 编辑2:甚至更容易:如果以'shell :::'为前缀,则SHParseDisplayName可以工作:

SHParseDisplayName(guid, nullptr, &pidl, 0, nullptr); 

According to the documentation for IShellFolder::ParseDisplayName you can simply pass it a filename in the form ::{GUID} if you are using the desktop folder. 根据IShellFolder::ParseDisplayName的文档,如果您使用的是桌面文件夹,则可以直接以::{GUID}形式将其传递给文件名。

Edit: the documentation appears to be incomplete, according to this answer you need to add shell: to the start of the string. 编辑:文档似乎不完整,根据此答案,您需要在字符串的开头添加shell: :。

p->ParseDisplayName(m_hWnd, NULL, _T("shell:::{7B0DB17D-9CD2-4A93-9733-46CC89022E7C}"), NULL, &pidl, NULL);

You want the function SHGetKnownFolderIDList . 您需要函数SHGetKnownFolderIDList

For example: 例如:

PIDLIST_ABSOLUTE pidl;
HRESULT hr = SHGetKnownFolderItem(FOLDERID_DocumentsLibrary, 0, NULL, out pidl);

Bonus Chatter 奖金Chat不休

There are three shell functions for dealing with KNOWNFOLDERs 有三个用于处理KNOWNFOLDER的Shell函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM