Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SHBrowseForFolder - header file?

Posted on 1997-05-28
8
769 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 Query 2 97
How to know only "File created" with EventLog 3 35
FizzBuzz challenge 9 82
Problem to App 4 97
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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