I'm using SHOpenFolderAndSelectItems in order to open up a new explorer window showing a particular location (PIDL). I'm not interested in opening just file paths, so I need to use a PIDL as far as I know!
This works, however, I'm not interested in selecting any of the items in the window. If I don't pass any items to be selected, the parent folder is opened instead, as per the documentation:
A count of items in the selection array, apidl. If cidl is zero, then pidlFolder must point to a fully specified ITEMIDLIST describing a single item to select. This function opens the parent folder and selects that item.
How am I able to simply open the location pointed to by my passed PIDL?
As a test, I passed one item to be selected, pointing to a null pointer. This seems to work, but I'm afraid this might have unintended side effects. This behavior doesn't seem to be documented. Is there a better way to go about what I want to achieve, or is the way I'm using this function now correct?
SHOpenFolder**AndSelectItems**()
should be a good indication that this is the wrong function for you to use. If you just want to open the folder, use ShellExecuteEx()
instead, eg:
SHELLEXECUTEINFO sei = {0};
sei.cbSize = sizeof(sei);
sei.fMask = SEE_MASK_IDLIST;
sei.hwnd = ...;
sei.lpVerb = TEXT("explore"); // <-- not "open"
sei.lpIDList = ...; // <-- your pidl
sei.nShow = SW_SHOW;
ShellExecuteEx(&sei);