SHBrowseForFolder - header file?

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?
WaldoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

laleonardCommented:
It compiles fine for me when I include shlobj.h - can you send us the exact and total error messages?
0
WaldoAuthor Commented:
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
chensuCommented:
I included the following two header files for it.

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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

WaldoAuthor Commented:
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
chensuCommented:
Send it to me by E-Mail.

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

0
chensuCommented:
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
WaldoAuthor Commented:
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
chensuCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.