Board index » cppbuilder » How to use TBrowseInfo in BCB

How to use TBrowseInfo in BCB


2005-08-03 02:33:17 PM
cppbuilder112
Dear all,
I try rewriting a sample program in Delphi to BCB. It makes use of the
TBrowseInfo structure. Excerpt from original code likes:
function TForm1.BrowseForFolder:string;
var
BrowseInfo : TBrowseInfo;
PIDL : PItemIDList;
SelectedPath : array[0..MAX_PATH] of Char;
begin
Result := '';
FillChar(BrowseInfo,SizeOf(BrowseInfo),#0);
BrowseInfo.hwndOwner := Handle;
BrowseInfo.pszDisplayName := @SelectedPath[0];
BrowseInfo.lpszTitle := 'Select a folder';
BrowseInfo.ulFlags := BIF_RETURNONLYFSDIRS;
PIDL := SHBrowseForFolder(BrowseInfo);
if Assigned(PIDL) then
if SHGetPathFromIDList(PIDL, SelectedPath) then
Result := string(SelectedPath);
end;
Rewriting it into C++,
void __fastcall TForm1::BrowseForFolder(String str)
{
TBrowseInfo *pBrowseInfo;
PItemIDList PIDL;
char SelectedPath[MAX_PATH];
String Result = "";
pBrowseInfo = new TBrowseInfo(NULL);
memset(pBrowseInfo, sizeof(*pBrowseInfo), 0x00);
pBrowseInfo->hwndOwner = Handle;
pBrowseInfo->pszDisplayName = &SelectedPath[0];
pBrowseInfo->lpszTitle = "Select a folder";
pBrowseInfo->ulFlags = BIF_RETURNONLYFSDIRS;
:
:
}
Cannot get it be compiled. BCB complaints that:
E2450 Undefined structure '_browseinfoA'
I find _browseinfoA is declared in shlobj.hpp and I did include this header
file. Whatelse I have to do to get it compiled?
Thanks for kind advice,
Patrick
 
 

Re:How to use TBrowseInfo in BCB

"Patrick Wong" < XXXX@XXXXX.COM >wrote in message
Quote
Cannot get it be compiled. BCB complaints that:
E2450 Undefined structure '_browseinfoA'
You are supposed to be using the Win32 API BROWSEINFO structure directly:
AnsiString __fastcall TForm1::BrowseForFolder()
{
BROWSEINFO BrowseInfo = {0};
LPITEMIDLIST pidl;
char SelectedPath[MAX_PATH+1];
AnsiString Result;
BrowseInfo.hwndOwner = Handle;
BrowseInfo.pszDisplayName = SelectedPath;
BrowseInfo.lpszTitle = "Select a folder";
BrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS;
pidl = SHBrowseForFolder(&BrowseInfo);
if( pidl )
{
if( SHGetPathFromIDList(pidl, SelectedPath) )
Result = SelectedPath;
CoTaskMemFree(pidl);
}
return Result;
}
With that said, the VCL already has a SelectDirectory() function that does
everything the above code is doing:
#include <FileCtrl.hpp>
AnsiString Folder;
if( SelectDirectory("Select a folder", "", Folder) )
// use Folder as needed...
Gambit
 

Re:How to use TBrowseInfo in BCB

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

You are supposed to be using the Win32 API BROWSEINFO structure directly:

I tried that before.
1. Without #include <shlobj.h>
E2451 Undefined symbol 'BROWSEINFO'
2. With #include <shlobj.h>
E2238 Multiple declaration for 'FVSHOWINFO'
E2238 Multiple declaration for 'FOLDERSETTINGS'
E2238 Multiple declaration for 'DESKBANDINFO'
E2238 Multiple declaration for 'SHELLFLAGSTATE'
Am I missing anything?
 

{smallsort}

Re:How to use TBrowseInfo in BCB

"Patrick Wong" < XXXX@XXXXX.COM >wrote in message
Quote
2. With #include <shlobj.h>
E2238 Multiple declaration for 'FVSHOWINFO'
E2238 Multiple declaration for 'FOLDERSETTINGS'
E2238 Multiple declaration for 'DESKBANDINFO'
E2238 Multiple declaration for 'SHELLFLAGSTATE'
Add NO_WIN32_LEAN_AND_MEAN to the Conditionals list in the Project Options.
Gambit
 

Re:How to use TBrowseInfo in BCB

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Patrick Wong" < XXXX@XXXXX.COM >wrote in message
news:42f07bc7$ XXXX@XXXXX.COM ...


Add NO_WIN32_LEAN_AND_MEAN to the Conditionals list in the Project
Options.

This works. Many thanks.