Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3286312
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:21:56+00:00 2026-05-17T20:21:56+00:00

In my C++ Windows application, I have a function that is supposed to allow

  • 0

In my C++ Windows application, I have a function that is supposed to allow the end-user select a folder. I’m using SHBrowseForFolder and it is working fine except that folder shortcuts are not being displayed in the dialog.

Does anyone know if it is possible to configure SHBrowseForFolder so that the end-users will be able to navigate folder shortcuts?

Edit: May 24th, 2010, 1:10 EST:

Okay, I’m going to show the code of what I have so far. I have tried using the suggestion of putting a BFFM_IUNKNOWN callback in my callback procedure, but have been struggling to figure out how to provide a IFolderFilter descendent that works.

1. The code that gets called:

Error CFolderChooserDialog::RunDialog()  
{  
    Error runResult = kError_NotInitialized;

    if (VERIFYN(kLyndsey, m_ReferenceCount > 0)) {  
         runResult = kError_Unexpected;  

         m_AllFoldersFilter = new TAllFoldersFilter();  

         if (VERIFYN(kLyndsey, m_AllFoldersFilter))  
         {  
               char selectedDirectoryBuffer[MAX_PATH];  
               m_DirectoryPath.CopyInto(selectedDirectoryBuffer);  

               BROWSEINFO bi;  
               memset(&bi, 0, sizeof(bi));  

               bi.hwndOwner = MyGetMainHWND(m_CBP);  
               bi.pidlRoot = NULL;  
               bi.pszDisplayName = selectedDirectoryBuffer;  
               bi.lpszTitle = (const char*)m_Description;  
               bi.ulFlags |= BIF_RETURNONLYFSDIRS;  
               bi.ulFlags |= BIF_BROWSEINCLUDEFILES;  

               bi.lpfn = SHBrowseForFolderCallbackProc;  
               bi.lParam = (LPARAM)this;  
               bi.iImage = 0;  

               LPITEMIDLIST resultInfo = SHBrowseForFolder(&bi);  
               if (resultInfo) {  
                   runResult = kError_NoError;  
                   if (SHGetPathFromIDList(resultInfo, selectedDirectoryBuffer)) {  
                        m_DirectoryPath = selectedDirectoryBuffer;  
                   }  
              }  
              else {  
                   runResult = kError_Failed;  
              }  
               delete m_AllFoldersFilter;  
               m_AllFoldersFilter = nil;  
               CoTaskMemFree(resultInfo);  
          }  

    }  

    return runResult;  
}  

2. The callback that gets called from SHBrowseForFolder:

int CALLBACK CFolderChooserDialog::SHBrowseForFolderCallbackProc(HWND window, UINT message, LPARAM messageValue, LPARAM clientData)  
{  
    CFolderChooserDialog* thisPtr = (CFolderChooserDialog*)clientData;  

    if (VERIFYN(kLyndsey, thisPtr)) {  
        switch (message) {  
            case BFFM_INITIALIZED: {  
                if (!thisPtr->m_DialogTitle.IsEmpty()) {  
                    ::SetWindowText(window, (const char*) thisPtr->m_DialogTitle);  
                }  

                if (!thisPtr->m_DirectoryPath.IsEmpty()) {  
                    LPCTSTR startDirectory = thisPtr->m_DirectoryPath;  
                    ::SendMessage(window, BFFM_SETSELECTION, TRUE, (LPARAM)startDirectory);  
                }  
                break;  
            }  
            case BFFM_IUNKNOWN:  
            {  
                IUnknown* theInterface = (IUnknown*)messageValue;  
                if (VERIFYN(kLyndsey, theInterface))  
                {  
                    IFolderFilterSite* filter = NULL;  
                    theInterface->QueryInterface(IID_IFolderFilterSite, (void**)&filter);  
                    if (VERIFYN(kLyndsey, filter))  
                    {  
                        filter->SetFilter((IUnknown*)thisPtr->m_AllFoldersFilter);  
                        filter->Release();  
                    }  
                }  
                break;  
            }  
            default:  
                break;  
        }  
    }  
    return 0;  
}  

3. The IFolderFilter that should get called for each item for filtering it in or out of the dialog:

class TAllFoldersFilter : public IFolderFilter  
{  
public:  
    TAllFoldersFilter() { refCount = 0;}  

    HRESULT STDMETHODCALLTYPE QueryInterface(const IID& iid, void** obj)  
    {  
        if (!obj)  
            return E_INVALIDARG;  
        *obj = NULL;  

        if (iid == IID_IUnknown || iid == IID_IFolderFilter)  
        {  
            *obj = (void*)this;  
            AddRef();  
            return NOERROR;  
        }  
        return E_NOINTERFACE;  
    }  

    ULONG STDMETHODCALLTYPE AddRef()  
    {  
        refCount++;  
        return refCount;  
    }  
    ULONG STDMETHODCALLTYPE Release()  
    {  
        refCount--;  
        return refCount;  
    }  

    HRESULT STDMETHODCALLTYPE GetEnumFlags(IShellFolder* sf, LPCITEMIDLIST pidlFolder, HWND* window, DWORD* flags)  
    {  
        return 0;  
    }  

    HRESULT STDMETHODCALLTYPE ShouldShow(IShellFolder* sf, LPCITEMIDLIST pidlFolder, LPCITEMIDLIST pidlItem)  
    {  
        HRESULT resultCode = S_OK;  

        ULONG attributes = 0UL;  

        if (SUCCEEDED(sf->GetAttributesOf(1, &pidlItem, &attributes)))  
        {  
            if (attributes & SFGAO_FOLDER)  
            {  
                resultCode = S_OK;  // Yes, I see the folders
            }  
            else if (attributes & SFGAO_LINK)  
            {  
                resultCode = S_OK;  // Yes, this shows the folder shortcut links, but I cannot explore them. When I "expand" them (click on the plus-sign-box), nothing happens.
            }  
        }  

        return resultCode;  
    }  
protected:  
    ULONG refCount;  
};  

So, where am I? Well, I can show the folders, I can show folder links, but I’m uncertain about the following:

  1. How do I easily determine if the item I have is a shortcut link to a folder? The code I wrote is definitely not looking at that and is showing any shortcut link.

  2. How do I easily allow the end-user delve into the folder represented by the shortcut link?

  3. Is this code correct and as simple/clean as it can be?

Thanks for all of your help!

Edit: June 1st, 2010: 2:14 EST:
The answer was technically provided, so I’ll mark that and I’m going to ask another question to help me fix this code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:21:57+00:00Added an answer on May 17, 2026 at 8:21 pm

    The better answer is to use IFileOpenDialog with FOS_PICKFOLDERS as the option for Windows Vista and later.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a Windows Forms application. I have a function which captures some mouse
I have a Windows application that uses a .NET PropertyGrid control. Is it possible
We have a windows application that contains an ActiveX WebBrowser control. As part of
I have a managed Windows application that loads a managed C++ component that uses
I have a Windows application written in C++ that occasionally evaporates. I use the
I have a C++ Windows application that can be extended by writing C++ plugins,
I have my Windows Application that accepts args and I use this in order
I have a Windows application that utilizes a 3rd-party tool ( FaxMan ) to
I'm using HTA and in it I have a function that should run a
I have a windows application running at the backend. I have functions in this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.