Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement for ::SHCreateItemFromParsingName() on Windows XP

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?

like image 396
steeveeet Avatar asked Jan 02 '14 14:01

steeveeet


1 Answers

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);
}
like image 142
steeveeet Avatar answered Oct 14 '22 02:10

steeveeet