如何获取IShellFolder的PIDL [英] How to obtain the PIDL of an IShellFolder

查看:231
本文介绍了如何获取IShellFolder的PIDL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个 IShellFolder 接口指针。我如何获得其PIDL?

If I have an IShellFolder interface pointer. How might I obtain its PIDL?

我可以看到如何枚举它的孩子,我可以看到如何使用它来比较任何两个孩子。

I can see how to enumerate its children, and I can see how to use it to compare any two children. But how might I get its own pidl?

我问,因为我想知道:


这是IShellFolder ==另一个IShellFolder

Is this IShellFolder == Another IShellFolder

我可以使用 IShellFolder :: CompareIDs ),但我必须拥有两个文件夹的ID。

I can use IShellFolder::CompareIDs(), but I have to have the IDs of both folders.

推荐答案

查询ISersFolder的IPersistFolder2,它有GetCurFolder(),它返回其绝对PIDL。然后我可以简单地使用IShellFolder的桌面来CompareIDs()来确定它们是否相等。我看到 SHGetIDListFromObject 。我不能只使用那个函数,因为它的Vista,我需要XP兼容性。

I found that you can query an IShellFolder for its IPersistFolder2, which has GetCurFolder(), which returns its absolute PIDL. I could then simply use the IShellFolder for the desktop to CompareIDs() to determine if they're equal. I found the outlines of this while looking at SHGetIDListFromObject. I couldn't just use that function, because its Vista, and I need XP compatibility.

这是一个草图如何工作(假设你有一个ifolder_desktop和ifolder_other ,它们是IShellFolder指针,Pidl是一个简单的帮助器,确保IDLIST被正确释放):

Here's a sketch of how it works (assuming you have an ifolder_desktop, and ifolder_other, which are IShellFolder pointers. Pidl is a simple helper that ensures that the IDLISTs are deallocated properly):

CComQIPtr<IPersistFolder2> ipf2_desktop(ifolder_desktop);
CComQIPtr<IPersistFolder2> ipf2_folder(ifolder_other);

Pidl pidl_desktop, pidl_folder;
VERIFY(SUCCEEDED(ipf2_desktop->GetCurFolder(pidl_desktop)));
VERIFY(SUCCEEDED(ipf2_folder->GetCurFolder(pidl_folder)));

HRESULT hr = ifolder_desktop->CompareIDs(NULL, pidl_desktop, pidl_folder);
pCmdUI->Enable(SUCCEEDED(hr) && HRESULT_CODE(hr) != 0);

如果有人对我的简单Pidl类感兴趣:

In case anyone is interested in my simple Pidl class:

class Pidl
{
public:
    // create empty
    Pidl() : m_pidl(NULL) { }

    // create one of specified size
    explicit Pidl(size_t size) : m_pidl(Pidl_Create(size)) {}

    // create a copy of a given PIDL
    explicit Pidl(const ITEMIDLIST * pidl) : m_pidl(Pidl_Copy(pidl)) {}

    // create an absolute PIDL from a parent + child
    Pidl(const ITEMIDLIST_ABSOLUTE * pParent, const ITEMIDLIST_RELATIVE * pChild) : m_pidl(Pidl_Concatenate(pParent, pChild)) { }

    // return our PIDL for general use (but retain ownership of it)
    operator const ITEMIDLIST * () { return m_pidl; }

    // return a pointer to our pointer, for use in functions that assign to a PIDL
    operator ITEMIDLIST ** () 
    {
        free();
        return &m_pidl; 
    }

    // release ownership of our PIDL
    ITEMIDLIST * release() 
    { 
        ITEMIDLIST * pidl = m_pidl;
        m_pidl = NULL;
        return pidl;
    }

    void free()
    {
        if (m_pidl)
            //Pidl_Free(m_pidl);
            ILFree(m_pidl);
    }

    // automatically free our pidl (if we have one)
    ~Pidl()
    {
        free();
    }

private:
    ITEMIDLIST * m_pidl;
};

这篇关于如何获取IShellFolder的PIDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆