Takes a pointer to a fully-qualified item identifier list (PIDL), and returns a specified interface pointer on the parent object.
Syntax
HRESULT SHBindToParent(
PCIDLIST_ABSOLUTE pidl,
REFIID riid,
VOID **ppv,
PCUITEMID_CHILD *ppidlLast
);
Parameters
- pidl
-
[in] The item's pointer to an item identifier list (PIDL).
- riid
-
[in] The REFIID of one of the interfaces exposed by the item's parent object.
- ppv
-
[out] A pointer to the interface specified by riid. You must release the object when you are finished.
- ppidlLast
-
[out] The item's PIDL relative to the parent folder. This PIDL can be used with many of the methods supported by the parent folder's interfaces. If you set ppidlLast to NULL, the PIDL is not returned.
Note SHBindToParent does not allocate a new PIDL; it simply receives a pointer through this parameter. Therefore, you are not responsible for freeing this resource.
Return Value
Returns S_OK if successful, or an error value otherwise.
Example
The following code fragment uses SHBindToParent to retrieve the display name from an item's PIDL. The StrRetToBuf function is used to convert the STRRET structure returned by IShellFolder::GetDisplayNameOf into a string.
// pidlItem is the item's PIDL
// pidlRelative is the item's PIDL relative to the parent folder
IShellFolder* psfParent; /* A pointer to the parent folder object's
IShellFolder interface. */
STRRET str; // The display name's STRRET structure.
TCHAR szDisplayName[MAX_PATH]; // The display name's string.
HRESULT hres = SHBindToParent(pidlItem,
IID_IShellFolder,
(void**) &psfParent,
&pidlRelative);
if(SUCCEEDED(hres))
{
psfParent->GetDisplayNameOf(pidlRelative, SHGDN_NORMAL, &str);
psfParent->Release();
StrRetToBuf(&str,
pidlItem,
szDisplayName,
sizeof(szDisplayName)/sizeof((szDisplayName)[0]));
}
Function Information
| Minimum DLL Version | shell32.dll version 5.0 or later |
|---|
| Custom Implementation | No |
|---|
| Header | shlobj.h |
|---|
| Import library | shell32.lib |
|---|
| Minimum operating systems |
Windows 2000, Windows Millennium Edition |
|---|