var
HostName: array[0..10] of char;
PHE: PHostEnt;
I: Integer;
begin
I := GetHostName(HostName, Sizeof(HostName));
PHE := GetHostByName(HostName);
end;为什么I的值为-1 为什么HostName的值为? PHE的值是什么,我应该怎样得到他的值?
HostName: array[0..10] of char;
PHE: PHostEnt;
I: Integer;
begin
I := GetHostName(HostName, Sizeof(HostName));
PHE := GetHostByName(HostName);
end;为什么I的值为-1 为什么HostName的值为? PHE的值是什么,我应该怎样得到他的值?
winsock;
procedure TForm1.Button1Click(Sender: TObject);
var
HostName: array[0..10] of char;
PHE: PHostEnt;
wsaDat:WSADATA;
ConsultResult:String;
I:Integer;
begin I:=WSAStartup(MAKEWORD(2,0),wsaDat);
if I<>0 then exit;
I := GetHostName(HostName, Sizeof(HostName));
if I<>0 then raise Exception.CreateFmt('GetHostName Fail![Socket Error %s]',[WSAGetLastError()]);
HostName:='sdf';
PHE := GetHostByName(HostName);
if phe=nil then raise Exception.CreateFmt('GetHostByName Fail![Socket Error %d]',[WSAGetLastError()]);
WSACleanup();
ConsultResult:=Format('%d.%d.%d.%d',
[ord(phe.h_addr^[0]),
ord(phe.h_addr^[1]),
ord(phe.h_addr^[2]),
ord(phe.h_addr^[3])]);
ShowMessage(ConsultResult);
end;