I have an app that needs to run on XP, but I want to be able to call ::SHCreateItemFromParsingName() which is only available from Vista onwards.
This: http://social.msdn.microsoft.com/Forums/vstudio/en-US/04eab1a9-5024-4199-b66c-8d20a83d4af4/shcreateitemfromparsingname-analog-on-xp?forum=vcgeneral
Said:
I believe you could achieve the same effect as follows: SHParseDisplayName to obtain item PIDL, then SHGetDesktopFolder, and finally IShellFolder::BindToObject
Which I've attempted:
IFileDialog *pfd;
....
PIDLIST_ABSOLUTE pidl;
HRESULT hresult = ::SHParseDisplayName(m_path, 0, &pidl, SFGAO_FOLDER, 0);
if (SUCCEEDED(hresult))
{
IShellFolder *psf;
hresult = ::SHGetDesktopFolder(&psf);
if (SUCCEEDED(hresult))
{
IShellItem *child;
hresult = psf->BindToObject(pidl, 0, IID_IShellFolder, (void**)&child);
if (SUCCEEDED(hresult))
{
pfd->SetFolder(child);
}
}
}
I think I'm mainly struggling with the BindToObject (as I'm not a particularly skilled windows programmer!)
Is this even vaguely right?
Based on @Raymond Chen comment, this seems to be a working replacement.
PIDLIST_ABSOLUTE pidl;
HRESULT hresult = ::SHParseDisplayName(m_path, 0, &pidl, SFGAO_FOLDER, 0);
if (SUCCEEDED(hresult))
{
IShellItem *psi;
hresult = ::SHCreateShellItem(NULL, NULL, pidl, &psi);
if (SUCCEEDED(hresult))
{
pfd->SetFolder(psi);
}
ILFree(pidl);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With