static IShellFolderPtr GetShellFolderFromIL(LPITEMIDLIST pidl)
{
HRESULT hr = S_OK;
if (pidl == NULL)
{
return NULL;
}
IShellFolderPtr spShellFolderParent;
hr = ::SHGetDesktopFolder(&spShellFolderParent);
if (FAILED(hr))
{
return NULL;
}
LPITEMIDLIST pidlDesktop = NULL;
hr = ::SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidlDesktop);
if (FAILED(hr))
{
return NULL;
}
BOOL br = CILHelper::Emulate_ILIsEqual(pidl, pidlDesktop);
if (br)
{
return spShellFolderParent;
}
IShellFolderPtr spShellFolder;
LPITEMIDLIST pidlNext = pidl;
while (pidlNext->mkid.cb)
{
LPITEMIDLIST pidlSub = CILHelper::Emulate_ILCloneFirst(pidlNext);
spShellFolder = NULL;
hr = spShellFolderParent->BindToObject(pidlSub, NULL, __uuidof(IShellFolder), (void**)&spShellFolder);
if (FAILED(hr))
{
return NULL;
}
spShellFolderParent = spShellFolder;
CILHelper::Emulate_ILFree(pidlSub);
pidlNext = CILHelper::Emulate_ILGetNext(pidlNext);
}
return spShellFolder;
}
static IShellFolderPtr GetShellFolderFromCSIDL(int nFolder)
{
HRESULT hr = S_OK;
LPITEMIDLIST pidl = NULL;
hr = ::SHGetSpecialFolderLocation(NULL, nFolder, &pidl);
if (FAILED(hr))
{
return NULL;
}
IShellFolderPtr spShellFolder = CShellFolderHelper::GetShellFolderFromIL(pidl);
CILHelper::Emulate_ILFree(pidl);
return spShellFolder;
}
static IShellFolderPtr GetShellFolderFromPath(LPCTSTR szFolderName)
{
LPITEMIDLIST pidl = CILHelper::Emulate_ILCreateFromPath(szFolderName);
if (pidl == NULL)
{
return NULL;
}
IShellFolderPtr spShellFolder = CShellFolderHelper::GetShellFolderFromIL(pidl);
CILHelper::Emulate_ILFree(pidl);
return spShellFolder;
}