Ved v tomto linku -->
http://edn.embarcadero.com/article/26876 <-- je nasledovny priklad:
Kód:
function EnumerateFunc( hwnd: HWND; hdc: HDC ; lpnr: PNetResource ): Boolean;
const
cbBuffer : DWORD = 16384; // 16K is a good size
var
hEnum, dwResult, dwResultEnum : DWORD;
lpnrLocal : array
[0..16384 div SizeOf(TNetResource)] of TNetResource; // pointer to enumerated structures
i : integer;
cEntries : Longint;
begin
centries := -1; // enumerate all possible entries
// Call the WNetOpenEnum function to begin the enumeration.
dwResult := WNetOpenEnum(
RESOURCE_CONTEXT, // Enumerate currently connected resources.
RESOURCETYPE_DISK, // all resources
0, // enumerate all resources
lpnr, // NULL first time the function is called
hEnum // handle to the resource
);
if (dwResult <> NO_ERROR) then
begin
// Process errors with an application-defined error handler
Result := False;
Exit;
end;
// Initialize the buffer.
FillChar( lpnrLocal, cbBuffer, 0 );
// Call the WNetEnumResource function to continue
// the enumeration.
dwResultEnum := WNetEnumResource(hEnum, // resource handle
DWORD(cEntries), // defined locally as -1
@lpnrLocal, // LPNETRESOURCE
cbBuffer); // buffer size
// This is just printing
for i := 0 to cEntries - 1 do
begin
// loop through each structure and
// get remote name of resource... lpnrLocal[i].lpRemoteName)
end;
// Call WNetCloseEnum to end the enumeration.
dwResult := WNetCloseEnum(hEnum);
if(dwResult <> NO_ERROR) then
begin
// Process errors... some user defined function here
Result := False;
end
else
Result := True;
end;
Pridaj k premennym este tieto premenne:
Kód:
HostEnt: PHostEnt;
InAddr: TInAddr;
Potom v kode je zakomentovana cast:
Kód:
// loop through each structure and
// get remote name of resource... lpnrLocal[i].lpRemoteName)
miesto nej skus dat do toho cyklu for toto:
Kód:
HostEnt:= GetHostByName( lpnrLocal[i].lpRemoteName );
if (HostEnt <> nil) then
begin
with InAddr, HostEnt^ do
begin
S_un_b.s_b1:= h_addr^[0];
S_un_b.s_b2:= h_addr^[1];
S_un_b.s_b3:= h_addr^[2];
S_un_b.s_b4:= h_addr^[3];
end;
ShowMessage( 'Adresa = ' + inet_ntoa(InAddr) );
Je to pisane z hlavy, tak treba sa s tym pohrat, ak to nepojde. Este pred tym, ako uvediem priklad volania funkcie, treba zmazat argument hdc a hwnd, pretoze sa vo funkcii nepouzivaju ( a viac menej ani lpnr, ale ten uz nechajme ), cize takto:
Kód:
function EnumerateFunc( lpnr: PNetResource ): Boolean;
Volat by sa potom mala nasledovne( predpokladam volanie z nejakej metody formulara, napr OnCreate, pretoze prvy parameter je jeho :
Kód:
if ( EnumerateFunc( nil ) = true ) then
ShowMessage( 'Uspesne ukoncenie funkcie.' )
else
ShowMessage( 'Chyba pri enumeracii siete.' );