Board index » cppbuilder » network neighborhood

network neighborhood


2006-01-17 11:27:08 AM
cppbuilder17
Hello:
I wish to have an explorer style view of network neighborhood. How do I get
remote machine names of network neighborhood. Help please.
Thanks,
Sudesh
 
 

Re:network neighborhood

Quote
I wish to have an explorer style view of network neighborhood.
How do I get remote machine names of network neighborhood.
I have found this code in my archive:
// ...
#include "SHLOBJ.H"
// ...
#include <FileCtrl.hpp>
#include <StrUtils.hpp>
// ...
AnsiString BrowseForComputer(HWND WinHandle, AnsiString title)
{
PItemIDList IDRoot;
TBrowseInfo BrowseInfo;
SHGetSpecialFolderLocation(WinHandle, CSIDL_NETWORK, &IDRoot);
Char Path[MAX_PATH];
ZeroMemory(&BrowseInfo, sizeof(TBrowseInfo));
ZeroMemory(Path, MAX_PATH);
BrowseInfo.hwndOwner = WinHandle;
BrowseInfo.pidlRoot = IDRoot;
BrowseInfo.lpszTitle = title.c_str();
BrowseInfo.pszDisplayName = Path;
// Include this flag to show computer only
BrowseInfo.ulFlags = BIF_BROWSEFORCOMPUTER;// or BIF_RETURNONLYFSDIRS ;
// Show the browse dialog, get the Item ID for the selected item and
convert it to a path
if ( SHBrowseForFolder(&BrowseInfo) != NULL )
return (AnsiString)Path;
else
return "-1";
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Edit1->Text = BrowseForComputer( Handle, "");
}
--
Best regards,
Vladimir Stefanovic
 

Re:network neighborhood

"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
Quote
AnsiString BrowseForComputer(HWND WinHandle, AnsiString title)
You should pass string values by const reference:
AnsiString BrowseForComputer(HWND WinHandle, const AnsiString &title)
Quote
PItemIDList IDRoot;
You are never freeing this ITEMIDLIST. That is a memory leak.
Quote
SHGetSpecialFolderLocation(WinHandle, CSIDL_NETWORK, &IDRoot);
You are not checking whether SHGetSpecialFolderLocation() fails or succeeds.
Quote
Char Path[MAX_PATH];
You should include room for a null-terminator:
Char Path[MAX_PATH+1];
ZeroMemory(Path, sizeof(Path));
Otherwise, if the OS returns a value that is exactly MAX_PATH characters in
length, your buffer will not be terminated properly.
Quote
if ( SHBrowseForFolder(&BrowseInfo) != NULL )
That is another memory leak. You are not freeing the ITEMIDLIST that
SHBrowseForFolder() returns.
Use this code instead:
// if you are using BCB5+, you need to add
// NO_WIN32_LEAN_AND_MEAN to the project's
// Conditionals list in order for shlobj.h to compile ...
#include <shlobj.h>
AnsiString __fastcall BrowseForComputer(HWND WinHandle, const AnsiString
&title)
{
BROWSEINFO bi = {0};
char szItem[MAX_PATH+1] = {0};
LPITEMIDLIST pidlRoot = NULL;
if( SUCCEEDED(::SHGetSpecialFolderLocation(WinHandle, CSIDL_NETWORK,
&pidlRoot)) )
{
bi.hwndOwner = WinHandle;
bi.pidlRoot = pidlRoot;
bi.lpszTitle = title.c_str();
bi.pszDisplayName = szItem;
bi.ulFlags = BIF_BROWSEFORCOMPUTER;
LPITEMIDLIST pidlResult = ::SHBrowseForFolder(&BrowseInfo);
bool Ok = (pidlResult != NULL);
::CoTaskMemFree(pidlRoot);
::CoTaskMemFree(pidlResult);
if( Ok )
return AnsiString(szItem);
}
return "";
}
Gambit
 

{smallsort}

Re:network neighborhood

Thanks Remy
Instead of such dialog, I wish to get list of computers on LAN and then
display it in a TreeView component.
How to do that?
Thanks,
Sudesh