如何得知用户 拔开网线 了?(50分)

废话,你才贴地址,我怎么给你?加分的事呢? 别太小气哦 &nbsp;:)<br>已发!
 
不会小气的。:)
 
我的就是网卡呀。无法侦测到连接状态。
 
那就只有使用“系统通知事件”了。<br>概览:关于系统通知事件<br>http://search.microsoft.com/gomsuri.asp?n=10&amp;c=rp_Results&amp;siteid=us/dev&amp;target=http://msdn.microsoft.com/library/en-us/syncmgr/syncmgr/about_system_event_notification_service.asp<br>Network 事件接口 ISensNetwork 资料:<br>http://search.microsoft.com/gomsuri.asp?n=2&amp;c=rp_Results&amp;siteid=us/dev&amp;target=http://msdn.microsoft.com/library/en-us/syncmgr/syncmgr/notifications.asp
 
Delphi 下 CoCreateInstance 函数在 Ole2.pas 中定义。
 
可惜 我们太菜了。。。。<br>要是小雨哥有空时,整理一个较好的完整资料。<br>就好了。:)
 
看得我好累呀。。。难呀。。。
 
另问:&gt;&gt;&gt;&gt;如果需要双向检测 (如 MSN) ,可以使用 WaitForMultipleObjects 函数<br>&nbsp; &nbsp;双向的含义是什么?具体应用是怎么样的情况?<br>
 
你给我的代码就是只能对拔号上网的情况,是不是?
 
学习学习。
 
能是用操作系统的 iphlpapi.dll 通过调用API函数 SENDAPR 来检查
 
用Ping是不行的。如果服务器端的防火墙不让Ping,就错误了。用GetHostByname还是可以的。<br>试试这个。<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; WSData:TWSAData;<br>&nbsp; Buffer:array[0..63]of Char;<br>&nbsp; HostEnt:pHostEnt;<br>&nbsp; PPInAddr:^PInAddr;<br>&nbsp; //字符串格式IP<br>&nbsp; IPString:String;<br>begin<br>&nbsp; IPString:='';<br>&nbsp; WSAStartUp($101,WSData);<br>&nbsp; try<br>&nbsp; &nbsp; GetHostName(Buffer,SizeOf(Buffer));<br>&nbsp; &nbsp; HostEnt:=GetHostByName(Buffer);<br>&nbsp; &nbsp; if Assigned(HostEnt) then begin<br>&nbsp; &nbsp; &nbsp; PPInAddr:=@(PInAddr(HostEnt.H_Addr_List^));<br>&nbsp; &nbsp; &nbsp; while Assigned(PPInAddr^) do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; IPString:=StrPas(INet_NToA(PPInAddr^^));<br>&nbsp; &nbsp; &nbsp; &nbsp; if IPString='127.0.0.1' then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showmessage('没有连接')<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showmessage(IPString+'已经连接');<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(PPInAddr);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; WSACleanUp;<br>&nbsp; end;<br>end;<br>
 
用Ping是不行的。如果服务器端的防火墙不让Ping,就错误了。用GetHostByname还是可以的。<br>试试这个。<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; WSData:TWSAData;<br>&nbsp; Buffer:array[0..63]of Char;<br>&nbsp; HostEnt:pHostEnt;<br>&nbsp; PPInAddr:^PInAddr;<br>&nbsp; //字符串格式IP<br>&nbsp; IPString:String;<br>begin<br>&nbsp; IPString:='';<br>&nbsp; WSAStartUp($101,WSData);<br>&nbsp; try<br>&nbsp; &nbsp; GetHostName(Buffer,SizeOf(Buffer));<br>&nbsp; &nbsp; HostEnt:=GetHostByName(Buffer);<br>&nbsp; &nbsp; if Assigned(HostEnt) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; PPInAddr:=@(PInAddr(HostEnt.H_Addr_List^));<br>&nbsp; &nbsp; &nbsp; while Assigned(PPInAddr^) do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; IPString:=StrPas(INet_NToA(PPInAddr^^));<br>&nbsp; &nbsp; &nbsp; &nbsp; if IPString='127.0.0.1' then showmessage('没有连接')<br>&nbsp; &nbsp; &nbsp; &nbsp; else showmessage(IPString+'已经连接');<br>&nbsp; &nbsp; &nbsp; &nbsp; Inc(PPInAddr);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; WSACleanUp;<br>&nbsp; end;<br>end;<br><br>//=====================================<br>大家以为上面代码如何?
 
我试了。在执行到WSAStartUp($101,WSData);时,程序出现异常。<br>怎么回事?怎么处理?
 
顶一下.
 
假如网线上没有任何信号,那么肯定有一条线上具有高电平,拔掉网线,高电平信号丢失,网卡控制芯片就会产生一个中断信号,操作系统截获这个信号做出反应。<br>这个是win2000以后新加的功能吧。或许很老的网卡(如ne2000)可能从硬件上就不支持也说不定。
 
顶一下. &nbsp;
 
顶部