Hi all!!
i'm new on forum but using lazarus with wince and inet for some days!!
i searching how to find all IP on the device. Looking for some code on the net i found this (sorry about the portuguese variables and coments) which uses Winsock:
if WSAStartup($0101, GInitData) <> 0 then FormPrinc.Label11.Caption := 'Nenhum add'
else begin
GetHostName(TempBuf, SizeOf(TempBuf));
FormPrinc.Label11.Caption := TempBuf + ' : ';
// busca ip
phe :=GetHostByName(TempBuf);
if phe = nil then begin
end
else begin
i := 0;
pptr := PaPInAddr(Phe^.h_addr_list);
while pptr^[i] <> nil do begin
FormPrinc.Label11.Caption := FormPrinc.Label11.Caption + StrPas(inet_ntoa(pptr^[i]^));
Inc(i);
end;
WSACleanup;
end;
end; // se conseguiu pegar winsock
thats ok, but it seems to result just on the first network adapter found. Normally smartphones have more than one (Active sync, wireless, 3G)...
anyone knows if there is possible to list all adapters and look for all ips? If there is no such functions ready to do this i'll be pleased to help to develop this. The problem is: I dont know where to start...
i found some code to search for device list for lazarus and delphi, but on wince there is some functions missing.
type
PNetResourceArray = ^TNetResourceArray;
TNetResourceArray = array[0..100] of TNetResource;
function CreateNetResourceList(ResourceType: DWord;
NetResource: PNetResource;
out Entries: DWord;
out List: PNetResourceArray): Boolean;
var
EnumHandle: THandle;
BufSize: DWord;
Res: DWord;
begin
Result := False;
List := Nil;
Entries := 0;
if WNetOpenEnum(RESOURCE_GLOBALNET,
ResourceType,
0,
NetResource,
EnumHandle) = NO_ERROR then begin
try
BufSize := $4000; // 16 kByte
GetMem(List, BufSize);
try
repeat
Entries := DWord(-1);
FillChar(List^, BufSize, 0);
Res := WNetEnumResource(EnumHandle, Entries, List, BufSize);
if Res = ERROR_MORE_DATA then
begin
ReAllocMem(List, BufSize);
end;
until Res <> ERROR_MORE_DATA;
Result := Res = NO_ERROR;
if not Result then
begin
FreeMem(List);
List := Nil;
Entries := 0;
end;
except
FreeMem(List);
raise;
end;
finally
WNetCloseEnum(EnumHandle);
end;
end;
end;
In this case WNetEnumResource (dont know the origin) should do the work of WSAStartup (winsock).
Any ideia??
thanks!