C
cddyjcxb
Unregistered / Unconfirmed
GUEST, unregistred user!
用ICS中的WSocket控件做ASP DNS组件时,发现WSocket不执行OnDnsLookupDone事件。造成查询不了DNS。
源文件如下:
//*****************DNS.DPR
library DNS;
{%File 'ConnectDns.asp'}
uses
ComServ,
DNS_TLB in 'DNS_TLB.pas',
DnsLookup in 'DnsLookup.pas' {ConnectDns: CoClass};
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
{$R *.TLB}
{$R *.RES}
begin
end.
//*******************DnsLookup.pas
unit DnsLookup;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, AspTlb, DNS_TLB, StdVcl,WinSock, WSocket,Classes,SysUtils;
type
TConnectDns = class(TASPObject, IConnectDns)
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
function DnsLookup(const DomainDns: WideString): OleVariant; safecall;
private
WSocket:TWSocket;
ReturnIpList:String;
procedure DnsLookupDone(Sender: TObject;Error: Word);
end;
implementation
uses ComServ;
procedure TConnectDns.OnEndPage;
begin
WSocket.Free;
inherited OnEndPage;
end;
procedure TConnectDns.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
WSocket:=TWSocket.Create(nil);
WSocket.OnDnsLookupDone:=DnsLookupDone;
end;
function TConnectDns.DnsLookup(const DomainDns: WideString): OleVariant;
begin
WSocket.DnsLookup(DomainDns);
Result:=ReturnIpList;
end;
procedure TConnectDns.DnsLookupDone(Sender: TObject;Error: Word);
var
i:integer;
begin
if Error = 0 then begin
for i:=0 to WSocket.DnsResultList.Count-1 do
ReturnIpList := ReturnIpList+WSocket.DnsResultList;
end
else
ReturnIpList:= 'NOT FOUND, ERROR #' + IntToStr(Error);
end;
initialization
TAutoObjectFactory.Create(ComServer, TConnectDns, Class_ConnectDns,
ciMultiInstance, tmApartment);
end.
//***************dns.asp
<HTML>
<BODY>
<TITLE> Testing Delphi ASP </TITLE>
<CENTER>
<H3> You should see the results of your Delphi Active Server method below </H3>
</CENTER>
<HR>
<% Set DelphiASPObj = Server.CreateObject("DNS.ConnectDns")
Response.write DelphiASPObj.DnsLookup("news.sina.com.cn")
%>
<HR>
</BODY>
</HTML>
----------------------
源文件如下:
//*****************DNS.DPR
library DNS;
{%File 'ConnectDns.asp'}
uses
ComServ,
DNS_TLB in 'DNS_TLB.pas',
DnsLookup in 'DnsLookup.pas' {ConnectDns: CoClass};
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
{$R *.TLB}
{$R *.RES}
begin
end.
//*******************DnsLookup.pas
unit DnsLookup;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, AspTlb, DNS_TLB, StdVcl,WinSock, WSocket,Classes,SysUtils;
type
TConnectDns = class(TASPObject, IConnectDns)
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
function DnsLookup(const DomainDns: WideString): OleVariant; safecall;
private
WSocket:TWSocket;
ReturnIpList:String;
procedure DnsLookupDone(Sender: TObject;Error: Word);
end;
implementation
uses ComServ;
procedure TConnectDns.OnEndPage;
begin
WSocket.Free;
inherited OnEndPage;
end;
procedure TConnectDns.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
WSocket:=TWSocket.Create(nil);
WSocket.OnDnsLookupDone:=DnsLookupDone;
end;
function TConnectDns.DnsLookup(const DomainDns: WideString): OleVariant;
begin
WSocket.DnsLookup(DomainDns);
Result:=ReturnIpList;
end;
procedure TConnectDns.DnsLookupDone(Sender: TObject;Error: Word);
var
i:integer;
begin
if Error = 0 then begin
for i:=0 to WSocket.DnsResultList.Count-1 do
ReturnIpList := ReturnIpList+WSocket.DnsResultList;
end
else
ReturnIpList:= 'NOT FOUND, ERROR #' + IntToStr(Error);
end;
initialization
TAutoObjectFactory.Create(ComServer, TConnectDns, Class_ConnectDns,
ciMultiInstance, tmApartment);
end.
//***************dns.asp
<HTML>
<BODY>
<TITLE> Testing Delphi ASP </TITLE>
<CENTER>
<H3> You should see the results of your Delphi Active Server method below </H3>
</CENTER>
<HR>
<% Set DelphiASPObj = Server.CreateObject("DNS.ConnectDns")
Response.write DelphiASPObj.DnsLookup("news.sina.com.cn")
%>
<HR>
</BODY>
</HTML>
----------------------