inline BOOL AtlGetShellPidl(LPCITEMIDLIST pidl, IShellFolder** ppFolder, LPITEMIDLIST* pidlRel) { ATLASSERT(pidl); ATLASSERT(ppFolder); ATLASSERT(pidlRel); *ppFolder = NULL; *pidlRel = NULL; // Get the desktop folder as a starting point CComPtr<IShellFolder> spFolder; if( FAILED( ::SHGetDesktopFolder(&spFolder) ) ) return FALSE; CPidl pidlMain; pidlMain.Copy(pidl); // Traverse each PIDL item and create a new IShellFolder for each of // them. Eventually we get to the last IShellFolder object and is left // with a simple (as opposed to complex) PIDL. int nCount = pidlMain.GetCount(); while( --nCount > 0 ) { // Get the next PIDL entry CPidl pidlNext; pidlNext.Attach( pidlMain.CopyFirstItem() ); if( pidlNext.IsEmpty() ) return FALSE; // Bind to the folder specified in the new item ID list. CComPtr<IShellFolder> spNextFolder; if( FAILED( spFolder->BindToObject(pidlNext, NULL, IID_IShellFolder, (LPVOID*) &spNextFolder)) ) return FALSE; spFolder = spNextFolder; // Strip first PIDL entry and copy remaining CPidl temp; temp.Copy( pidlMain.GetNextItem() ); pidlMain.Attach(temp.Detach()); } *ppFolder = spFolder.Detach(); *pidlRel = pidlMain.Detach(); return TRUE; };