const WM_RESOLVE = WM_USER+100;
type TWMRESOLVE = record
Msg:word;
wParam:word;
lParam:dword;
end;
procedure WMRESOLVE(var Msg:TWMRESOLVE);Message WM_RESOLVE;
formcreate;
var WSAData: TWSAData;
begin
if (WSAStartup(MAKEWORD(2,0), WSAData)<> 0) then
raise exception.create('winsock version error');
end;
BtnGetHost;
begin
hAsyncHandle := WSAAsyncGetHostByName(handle, WM_RESOLVE, pchar('www.3322.org'), pchar(@buf),MAXGETHOSTSTRUCT);
end;
procedure tform.WMRESOLVE(var Msg:TWMRESOLVE);
begin
if buf.h_addr=nil then
begin
edit.text:='failed';
exit;
end;
edit.text :=format('%d.%d.%d.%d',
[ord(buf.h_addr^[0]),ord(buf.h_addr^[1]),ord(buf.h_addr^[2]),ord(buf.h_addr^[3])]);
edit2.text:=buf.h_name;
end;
formdestroy;
begin
WSACleanUP;
end;