Solved

Browse for folder function

Posted on 2003-11-12
9
1,474 Views
Last Modified: 2010-05-18
I found a function that should let a user to select a folder. However, trying to compile it I got following errors:
  [C++ Error] shobjidl.h(2193): E2238 Multiple declaration for 'FOLDERSETTINGS'
  [C++ Error] shobjidl.h(8095): E2238 Multiple declaration for 'DESKBANDINFO'
  [C++ Error] shlobj.h(1422): E2238 Multiple declaration for 'FVSHOWINFO'
  [C++ Error] shlobj.h(3457): E2238 Multiple declaration for 'SHELLFLAGSTATE'
  [C++ Error] Unit1.cpp(55): E2451 Undefined symbol 'Label1'
  [C++ Error] Unit1.cpp(59): E2451 Undefined symbol 'Label2'

I am using Borland C++ Builder 6. How should i fix this problem? I included the following unit1.cpp file that i was using. I noticed that when i add #include <shlobj.h> even to an empty project it shows the same errors. Any ideas how to fix it?

--------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------

#include <vcl.h>
#include <shlobj.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    BROWSEINFO    info;
    char          szDir[MAX_PATH];
    char          szDisplayName[MAX_PATH];
    LPITEMIDLIST  pidl;
    LPMALLOC      pShellMalloc;

    // SHBrowseForFolder returns a PIDL. The memory for the PIDL is
    // allocated by the shell. Eventually, we will need to free this
    // memory, so we need to get a pointer to the shell malloc COM
    // object that will free the PIDL later on.
    if(SHGetMalloc(&pShellMalloc) == NO_ERROR)
    {
        // if we were able to get the shell malloc object,
        // then proceed by initializing the BROWSEINFO stuct
        memset(&info, 0x00,sizeof(info));
        info.hwndOwner = Handle;                 // Owner window
        info.pidlRoot  = 0;                      // root folder
        info.pszDisplayName = szDisplayName;     // return display name
        info.lpszTitle = "Browse Title";         // label caption
        info.ulFlags   = BIF_RETURNONLYFSDIRS;   // config flags
        info.lpfn = 0;                           // callback function

        // execute the browsing dialog
        pidl = SHBrowseForFolder(&info);

        // pidl will be null if they cancel the browse dialog.
        // pidl will be not null when they select a folder
        if(pidl)
        {
            // try to convert the pidl to a display string
            // return is true if success
            if(SHGetPathFromIDList(pidl, szDir))
            {
                // set one caption to the directory path
                Label1->Caption = szDir;
            }

            // set another caption based on the display name
            Label2->Caption = info.pszDisplayName;

            // use the shell malloc com object to free the pidl.
            // then call Relasee to signal that we don't need
            // the shell malloc object anymore
            pShellMalloc->Free(pidl);
        }
        pShellMalloc->Release();
    }
}
//---------------------------------------------------------------------------
0
Comment
Question by:kabix
[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
9 Comments
 
LVL 3

Expert Comment

by:Kashra
ID: 9736458
Well, those kinds of errors could come from a header file that doesn't have flags to prevent multiple includes.

You should check the header file to see if it has an #ifndef statement at the beginning. If not, you should put the following on either end of the header file:

#ifndef INCLUDE_THIS_HEADER_ONLY_ONCE_SHLOBJ_H
#define INCLUDE_THIS_HEADER_ONLY_ONCE_SHLOBJ_H

// REST OF HEADER FILE HERE

#endif

The last two errors are obvious. You are using the variables Label1 and Label2 without ever defining them.
0
 
LVL 4

Author Comment

by:kabix
ID: 9743621
Hey,
I tried with a simplier code that uses the same file. Below I included the cpp file that i was trying to compile. In my case I wasnt able to compile because i got the errors which are below as well.
I tried to put
#ifndef INCLUDE_THIS_HEADER_ONLY_ONCE_SHLOBJ_H
#define INCLUDE_THIS_HEADER_ONLY_ONCE_SHLOBJ_H
in both of the files however c++ showed a bunch of other errors. I installed brand new version of Borland C++ Builder 6 but it still does the same. How could I fix this error?


ERRORS:
[C++ Error] shobjidl.h(2191): E2238 Multiple declaration for 'FOLDERSETTINGS'
[C++ Error] shobjidl.h(8093): E2238 Multiple declaration for 'DESKBANDINFO'
[C++ Error] shlobj.h(1422): E2238 Multiple declaration for 'FVSHOWINFO'
[C++ Error] shlobj.h(3457): E2238 Multiple declaration for 'SHELLFLAGSTATE'


UNIT1.CPP
//---------------------------------------------------------------------------

#include <vcl.h>
#include <shlobj.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  ShellExecute(Handle, "open", "d:\\website\\index.htm", NULL,NULL,SW_SHOWDEFAULT);
}
//---------------------------------------------------------------------------
0
 
LVL 3

Expert Comment

by:Kashra
ID: 9743843
Did you remember to put #endif at the end of the file as well? You should only be putting those flags in the header files that are actually giving the errors (shobjidl.h and shlobj.h).

Otherwise, its difficult to tell what is wrong without seeing the code from the header files themselves (preferably the lines giving the errors, of course)
0
Industry Leaders: 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!

 
LVL 1

Expert Comment

by:georgiek50
ID: 9798301
This is what I have used in my code, and it works great:

static BROWSEINFO bi;
LPITEMIDLIST         pidl;

bi.hwndOwner =  hwnd;
bi.pidlRoot  = NULL;              // This is to search entire computer (you can specify your own root)

bi.pszDisplayName = szFolderName;
pidl = SHBrowseForFolder(&bi);

if ( pidl == NULL )
     return FALSE;

SHGetPathFromIDList(pidl, szFolderPath);
0
 
LVL 4

Author Comment

by:kabix
ID: 9798471
Kashra: i added endif at the end of each file however it did not work. Any other ideas how to fix it?
0
 
LVL 3

Expert Comment

by:Kashra
ID: 9799212
I've got no other ideas at the moment, I'm sorry. The only other times I see error messages like that are when I forget to use keyword "inline" in front of my inlined functions, but if you're using a commercial header file then that's not very likely.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10249078
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 10284510
PAQed, with points refunded (50)

Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

623 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