Solved

SHBrowseForFolder - header file?

Posted on 1997-05-28
8
750 Views
Last Modified: 2013-11-20
I'm using VC++ Ver 4.0.  I've got an application 90% complete using MFC.  I now want to call SHBrowseForFolder to bring up a Dialog box which would allow the user to select a directory.  When I compile I get Undeclared identifier on this function.  I tried to include shlobj.h but got some other errors.  WHICH HEADER FIILE SHOULD I INCLUDE?
0
Comment
Question by:Waldo
  • 4
  • 3
8 Comments
 

Expert Comment

by:laleonard
ID: 1301859
It compiles fine for me when I include shlobj.h - can you send us the exact and total error messages?
0
 

Author Comment

by:Waldo
ID: 1301860
This is the errors when I include "shlobj.h" after I includeed all my other #include files:
C:\MSDEV\INCLUDE\shlobj.h(1079) : error C2501: 'NETRESOURCE' : missing decl-specifiers
C:\MSDEV\INCLUDE\shlobj.h(1079) : error C2146: syntax error : missing ';' before identifier 'nr'
C:\MSDEV\INCLUDE\shlobj.h(1079) : error C2501: 'nr' : missing decl-specifiers
When I include it before all my other #include files (in specific "stdafx.h"I get the following:
D:\Lazer Wise\Serial Numbers\Serial NumbersDlg.cpp(205) : error C2065: 'BROWSEINFO' : undeclared identifier
D:\Lazer Wise\Serial Numbers\Serial NumbersDlg.cpp(205) : error C2146: syntax error : missing ';' before identifier 'bi'
D:\Lazer Wise\Serial Numbers\Serial NumbersDlg.cpp(205) : error C2065: 'bi' : undeclared identifier
D:\Lazer Wise\Serial Numbers\Serial NumbersDlg.cpp(206) : error C2065: 'SHBrowseForFolder' : undeclared identifier
D:\Lazer Wise\Serial Numbers\Serial NumbersDlg.cpp(206) : error C2064: term does not evaluate to a function

Thanx for the help
0
 
LVL 23

Accepted Solution

by:
chensu earned 150 total points
ID: 1301861
I included the following two header files for it.

#include <objbase.h>
#include <shlobj.h>

0
 

Author Comment

by:Waldo
ID: 1301862
Sorry, this still doesn't work.  I generated a small - very small app to demonstrate the problem.  I would like to send it to you but don't know how.  I'll increase the points with 50 if you can solve this for me.  Remember I'm using VC++ 4.0
Thanx
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 23

Expert Comment

by:chensu
ID: 1301863
Send it to me by E-Mail.

My E-Mail address is <chensu@hotmail.com>.

0
 
LVL 23

Expert Comment

by:chensu
ID: 1301864
I compiled your source code with Microsoft Visual C++ 4.2. It produced "Browse.exe - 0 error(s), 0 warning(s)". So, I think it is likely there is some mistake in SHLOBJ.H of V4.0. Two solutions:

1. Upgrade to V4.2.
2. Try including WINNETWK.H that defines NETRESOURCE before including SHLOBJ.H.

0
 

Author Comment

by:Waldo
ID: 1301865
Hi Chensu,

Tom Bradly - somewhere out on the Internet - suggested to remove the following line from stdafx.h:

#define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers

It worked.  My Browse also compiled without any errors.  But now I don't get the Browse Dialog to open when I press on the button.  I think that I've got to play around with my LPBROWSEINFO variable a bit.  I'll mail you if I have any more problems.

0
 
LVL 23

Expert Comment

by:chensu
ID: 1301866
Sorry, I didn't look into the stdafx.h.

Regarding the BROWSEINFO, you should allocate the structure and pass the address to SHBrowseForFolder instead of passing a pointer to it.

The following code is a part of my program that may be helpful for you.

// pointer to the shell's IMalloc interface.
    LPMALLOC pMalloc;

      // Get the shell's allocator.
    if (SUCCEEDED(::SHGetMalloc(&pMalloc)))
      {
        // Allocate a buffer to receive browse information.
            LPSTR lpBuffer;
        if ((lpBuffer = (LPSTR)pMalloc->Alloc(MAX_PATH)) != NULL)
            {
              // Get the PIDL for the Programs folder.
            LPITEMIDLIST pidlPrograms;  // PIDL for Programs folder
            if (SUCCEEDED(::SHGetSpecialFolderLocation(pWnd->GetSafeHwnd(),
                                                               CSIDL_PROGRAMS,
                                                                                 &pidlPrograms)))
                  {
                // Fill in the BROWSEINFO structure.
                BROWSEINFO bi =
                        {
                              pWnd->GetSafeHwnd(),
                    pidlPrograms,
                    lpBuffer,
                    "Choose a Program Group",
                    0,
                    NULL,
                    0
                        };
   
                // Browse for a folder and return its PIDL selected by user.
                LPITEMIDLIST pidlBrowse = ::SHBrowseForFolder(&bi);
                if (pidlBrowse != NULL)
                        {
                    // Show the display name (SHGDN_NORMAL or SHGDN_INFOLDER),
                              // title, and file system path.
                    pWnd->MessageBox(lpBuffer, "Display name", MB_OK);
                   
                              if (::SHGetPathFromIDList(pidlBrowse, lpBuffer))
                        pWnd->MessageBox(lpBuffer, "Path name", MB_OK);
 
                    // Free the PIDL returned by SHBrowseForFolder.
                    pMalloc->Free(pidlBrowse);
                        }
 
                // Free the PIDL returned by SHGetSpecialFolderLocation
                        pMalloc->Free(pidlPrograms);
                  }

            // Clean up.
            pMalloc->Free(lpBuffer);
            }

          // Release the shell's allocator.
        pMalloc->Release();
      }

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now