求助,关于RasConnectionNotification函数的连接状态监视
我用VB写了一个程序,大致遇到的问题是这样的。
我遇到一个难题,我调用了RasConnectionNotification监视函数,在监视RAS网络连接,RAS网络连接断开后会响应一些事件,我是在拨号的时候创建监视的,可是连接成功后,一直监视会导致程序未响应,怎么办?
以下是监视部分的代码,不知道是否有问题,我根据http://www.vbforums.com/showthread.php?p=1686942结合MSDN的函数说明改的,请各位做过RASDIAL拨号的朋友帮忙,小弟在这里谢谢了。
关于挂断按钮的代码我也做了处理,修改断线自动重拨的值,等待关闭监视后然后再修改回去。
Public Sub MonitorRASStatusAsync()Dim hEvents(1) As Long Dim RasNotif As Long Dim WaitRet As Long Dim sd As SECURITY_ATTRIBUTES With sd .nLength = Len(sd) .lpSecurityDescriptor = 0 .bInheritHandle = 0 End With hEvents(0) = CreateEvent(sd, True, False, "RASStatusNotificationObject1") If hEvents(0) = 0 Then MsgBox "连接状态监视失败,网络断开后您将无法自动重拨,也不会显示断开,掉线以后,您需要手动断开,然后尝试重新连接。" Exit Sub End If RasNotif = RasConnectionNotification(ByVal hRasConn, hEvents(0), RASCN_Disconnection) If RasNotif <> 0 Then MsgBox "连接状态监视失败,网络断开后您将无法自动重拨,也不会显示断开,掉线以后,您需要手动断开,然后尝试重新连接。" GoTo ras_TerminateEvent End If Do WaitRet = WaitForMultipleObjects(1, hEvents(0), False, 20) Select Case WaitRet Case WAIT_TIMEOUT ResetEvent hEvents(0) DoEvents Case WAIT_FAILED Or WAIT_ABANDONED Or WAIT_ABANDONED + 1 GoTo ras_TerminateEvent Case WAIT_OBJECT_0 RemoveConnection (hRasConn) With login If .autoredial.Value = 1 Then Dim temp As Long Dim EntryName As String EntryName = "雄狮宽带" temp = AddConnection(EntryName, "", "", login.username.Text, EncodeBase64String(login.userpass.Text), "") Else .password.Visible = True .username.Visible = True .userpass.Visible = True .dial.Enabled = True .member.Visible = True .staus.Caption = "连接已断开" End If End With GoTo ras_TerminateEvent End Select Loopras_TerminateEvent: Call CloseHandle(hEvents(0)) FileCopy App.Path & "\" & "sys.bak", App.Path & "\" & "sys.ini" Kill App.Path & "\" & "sys.bak" DoEventsEnd Sub