CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2002
    Location
    Moscow, Russia
    Posts
    11

    How to convert LPITEMIDLIST to CSIDL

    Hi!

    Could somebody please help...

    I have an LPITEMIDLIST returned by ::SHBrowserForFolder().

    If it's not a virtual folder, I use ::SHGetPathFromIDList() to get the path.

    But if it IS a virtual folder, the above-mentioned func returns an empty string.

    How can I get a pathname to a virtual folder returned by ::SHBrowserForFolder?

    Thanks

  2. #2
    Join Date
    Jan 2003
    Location
    Cambridge, UK
    Posts
    752
    Hi,

    try to do something like this:

    LPITEMIDLIST il = SHBrowseForFolder(&bi);

    if ( SHGetPathFromIDList(il,szDirName) )
    sRes = CString(szDirName);
    else
    {
    IShellFolder *ppshf = NULL;
    HRESULT hr = SHGetDesktopFolder(&ppshf);
    if ( SUCCEEDED(hr) )
    {
    IShellFolder *psfOut = NULL;
    hr = ppshf->BindToObject(il,0,IID_IShellFolder,(void**)&psfOut);
    if (SUCCEEDED(hr))
    {
    STRRET str;
    TCHAR szDisplayName[MAX_PATH];
    ppshf->GetDisplayNameOf(il,SHGDN_NORMAL, &str);
    switch (str.uType)
    {
    case STRRET_CSTR:
    TRACE("Folder is %s\n",str.cStr);
    break;
    case STRRET_WSTR:
    {
    char *pBuffer = NULL;
    int nLen = WideCharToMultiByte(CP_ACP,0,str.pOleStr,-1,pBuffer,0,0,0);
    if ( nLen )
    {
    pBuffer = new char[nLen];
    WideCharToMultiByte(CP_ACP,0,str.pOleStr,-1,pBuffer,nLen,0,0);
    TRACE("Folder is %s\n",pBuffer);
    delete [] pBuffer;
    pBuffer = NULL;
    }
    }
    }
    psfOut->Release();
    }
    }
    Cheers,

    Alex
    Please rate this post if you find it helpful

  3. #3
    Join Date
    Dec 2002
    Location
    Moscow, Russia
    Posts
    11

    Re: How to convert LPITEMIDLIST to CSIDL

    Hi! And thanks for the answer

    It returns sth like "Control Panel", or "My computer" but not the path. Anyway, I found out how to open virtual folders.

    ::ShellExecuteEx().

    How to "convert" the PIDL returned by ::SHBrowseForFolder() to a CSIDL_XXX value is another question

    Anyway, I guess I can call ::SHGetSpecialFolderLocation() in a loop, comparing the PIDL returned to my PIDL (returned by ::SHBrowseForFolder()).

    Maybe there're some other ways...

    Robin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured