Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SHBrowseForFolder - header file?

Posted on 1997-05-28
8
Medium Priority
?
835 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
[X]
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
  • 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 600 total points
ID: 1301861
I included the following two header files for it.

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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

660 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