Solved

SHBrowseForFolder - header file?

Posted on 1997-05-28
8
735 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

9 Experts available now in Live!

Get 1:1 Help Now