SHGetNameFromIDList fails for FTP PIDLs

258 views Asked by At

If I add an FTP network location on Windows, it creates a .lnk file pointing to the location. If I open the link via IShellLink, obtain its IShellFile target, and bind it to IShellFolder, I can enumerate the files on the remote location (after logging in) using IShellFolder::EnumObjects, and the correct files are returned.

However, if I try to obtain a name of any file there, via SHGetNameFromIDList or IShellItem::GetDisplayName, the function fails with 0x80070057 (invalid parameter) HRESULT. I know for sure that the PIDL is valid, because I can construct IShellItem, and its size is 72 bytes, but any attempt to obtain the path fails. Accessing any properties I can think of on IShellItem2, constructed from the PIDL, also fails, as well as simply calling SHGetPathFromIDList.

So, how do I obtain any meaningful name from the PIDL, preferably in SIGDN_PARENTRELATIVEPARSING? Why do all these operations fail? I thought any PIDL is at least a file path or a CLSID, but this PIDL simply cannot be queried for anything.

I am aware that there are tons of better solutions for accessing FTP, but I have this question for Shell32 in general, not for FTP specifically.

I have also converted the PIDL to bytes via ILSaveToStream, and I can see the name of the file is definitely there.

1

There are 1 answers

1
IS4 On BEST ANSWER

It turned out that IShellFolder::EnumObjects returned relative PIDLs. For some reason, names of relative FTP PIDLs cannot be obtained, although they are clearly stored in the SHITEMID.

Well, calling ILCombine on the folder and file PIDLs made everything work as expected.