none
BROWSEINFO BIF_SHAREABLE flag problem using SHBrowseForFolder RRS feed

  • Question

  • Hello all,

     

    I am new to these forums so I hope I have chosen the right place to post this.  I am using C++ so this seems like the right place although maybe platform SDK is the right place.  Sorry if this is not right.

     

    Anyway, I am using the SHBrowseForFolder function to allow a user to select a folder to output data to and I have come across a problem using the BIF_SHAREABLE flag which I set in the BROWSEINFO  structure which is a passed into the SHBrowseForFolder function .  According to the documentation here http://msdn2.microsoft.com/en-us/library/ms538017.aspx setting this flag will allow the browse dialog box to display shareable resources on remote systems.  However, in the testing I have done this flag seems to work the opposite way that it is supposed to according to how I interpreted the documentation.

     

    On some of my test machines (Windows XP Pro and Home which both have Version 5 or 6 of the DLL called) I have network drives mapped to drive letters and if they are disconnected then with the BIF_SHAREABLE flag set they will show up in the browse list but if they are connected then they do not show up anymore .  If I don't set the  BIF_SHAREABLE flag then all of the mapped drives end up showing up which seems like the opposite behavior I would expect.

     

    Here is a portion of the code that is relevant in case it will help:


    Code Snippet

     BROWSEINFO bi;
     LPITEMIDLIST pidlBrowse; // PIDL selected by user
     LPMALLOC pMalloc;
     tstr titlestr = GetResourceStr(title);
     TCHAR pathwork[_MAX_PATH];

     

     int version = GetDLLVersion(_T("SHELL32.DLL"));
     SHGetMalloc(&pMalloc);

     memset(&bi,0,sizeof bi);
     bi.hwndOwner = hDlg;
     bi.pidlRoot = NULL;
     bi.pszDisplayName = pathwork;
     bi.lpszTitle = titlestr.c_str();


     bi.ulFlags = BIF_RETURNONLYFSDIRS;
     if (version >= 0x50000)
         bi.ulFlags |= BIF_NEWDIALOGSTYLE | BIF_SHAREABLE; 

     

     bi.lpfn = BrowseCallbackProc;
     bi.lParam = (long)pathwork;

     

     // Browse for a folder and return its PIDL.
     pidlBrowse = SHBrowseForFolder(&bi);

     

     


     

    For now I have just commented out the BIF_SHAREABLE flag which gives me the behavior I want and expect but I would like to understand why the function is acting this way.  I am just overlooking something simple?

    Friday, August 17, 2007 12:00 AM

All replies

  • This is possibly an error. There is also a discrepancy between the documentation and the comments in ShlObj.h. 

     

    The header file says

     

    #define BIF_SHAREABLE   0x8000  // sharable resources displayed (remote shares, requires BIF_USENEWUI)

     

    and the documentation says "The BIF_NEWDIALOGSTYLE flag must also be set" 

     

    Actually you can see network shares with just

        //OleInitialize(NULL);
        BROWSEINFO bi = { 0 };
        bi.lpszTitle = "Test";
        //bi.ulFlags = BIF_RETURNONLYFSDIRS| BIF_NEWDIALOGSTYLE  ;
        SHBrowseForFolder ( &bi );

     

    also the documentation says you must call OleInitialize or CoInitialize before calling SHBrowseForFolder. I tried it without calling either and it worked OK.  You can report it here if you want to.

    Monday, August 20, 2007 6:41 AM
  • Thank you very much for the reply.  I hope it is a discrepancy I just would like to find out for sure.  Assuming anything is just not something I wish to do.

     

    Also, the following is not a discrepancy or error:

     

    "#define BIF_SHAREABLE   0x8000  // sharable resources displayed (remote shares, requires BIF_USENEWUI)

    and the documentation says "The BIF_NEWDIALOGSTYLE flag must also be set" "

     

    BIF_USENEWUI is defined with the "NEWDIALOGSTYLE" flag so no discrepancy:

     

    #define BIF_USENEWUI (BIF_NEWDIALOGSTYLE | BIF_EDITBOX)

     

    I also noticed the that the documentation says OleInitialize() or CoInitialize() must be called before SHBrowseForFolder() but I do neither and have not run into a problem yet either.

     

    I am checking out that link you gave me, thank you very much.

    Monday, August 20, 2007 10:28 PM
  • Anyway, I am using the SHBrowseForFolder function to allow a user to select a folder to output data to and I have come across a problem using the BIF_SHAREABLE flag which I set in the BROWSEINFO  structure which is a passed into the SHBrowseForFolder function .  According to the documentation here http://msdn2.microsoft.com/en-us/library/ms538017.aspx setting this flag will allow the browse dialog box to display shareable resources on remote systems.  However, in the testing I have done this flag seems to work the opposite way that it is supposed to according to how I interpreted the documentation.

     

    On some of my test machines (Windows XP Pro and Home which both have Version 5 or 6 of the DLL called) I have network drives mapped to drive letters and if they are disconnected then with the BIF_SHAREABLE flag set they will show up in the browse list but if they are connected then they do not show up anymore .  If I don't set the  BIF_SHAREABLE flag then all of the mapped drives end up showing up which seems like the opposite behavior I would expect.

     

    FWIW, the behavior you describe makes sense to me. BIF_SHAREABLE says "show me the resources I can connect to"; if I'm already connected to a resource, it no longer qualifies.

    Tuesday, August 21, 2007 12:50 AM
  •  Sdi wrote:

    FWIW, the behavior you describe makes sense to me. BIF_SHAREABLE says "show me the resources I can connect to"; if I'm already connected to a resource, it no longer qualifies.

     

    How do you define "resources I can connect to" ?   Are you sure "resources you can connect to" are being shown when BIF_SHAREABLE is turned on ? 

    Tuesday, August 21, 2007 12:40 PM
  •  Sdi wrote:

    FWIW, the behavior you describe makes sense to me. BIF_SHAREABLE says "show me the resources I can connect to"; if I'm already connected to a resource, it no longer qualifies.

     

    The documentation for BIF_SHAREABLE says "The browse dialog box can display shareable resources on remote systems." it DOES NOT SAY "can display non-connected shareable resources on remote systems" so I disagree with what you said, shareable is shareable whether it is connected or not.

     

    In my point of view according to the documentation that flag basically just means "if there are any shareable resources show them" ALONG with all other types of drives specified.  Essentially the list should match what shows up when you go to "My Computer" (ie "Hard disk drives", "Devices with removable storage","Network Drives","Network Neighborhood),etc) which it does if I don't specify the BIF_SHAREABLE flag but I want to know why that happens since that seems like the opposite behavior the flag is supposed to have.

    Wednesday, August 22, 2007 11:12 PM
  • I'm glad this thread exists. I just ran into the same problem as Andy and went searching for an answer.
    Friday, February 6, 2009 10:26 PM
  • I also have run into the same problem that SHBrowseForFolder is NOT showing up mapped network drives, though the flag BIF_SHAREABLE is being set as per MSDN. Does someone have a solution for this?

    Thanks in Advance.


    Anand K Reddy
    akx++ Solutions


    Tuesday, June 12, 2012 8:48 PM
  • Oh, Ya - Did not pay much attention and answer to my question lies in the beginning of the thread itself - True that mapped network drives are showing up only when BIF_SHAREABLE flag is NOT set. Thank you Andy for putting your thoughts on this here.

    Anand K Reddy
    akx++ Solutions


    Wednesday, June 13, 2012 7:32 AM