拨号连接提示"尝试读取或写入受保护的内存。这通常指示其他内存已损坏。"
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。代码如下:Imports System.Runtime.InteropServices
Module link
Public hRasConn As Integer '定义一个指向RAS调用的全局句柄
Public Const APINULL = 0&
Public Const UNLEN = 256
Public Const DNLEN = 15
Public Const PWLEN = 256
Public Structure RASCONN95
Public dwSize As Integer
Public hRasConn As Integer
Public szEntryName As String
Public szDeviceType As String
Public szDeviceName As String
End Structure
Public Structure RASCONNSTATUS95
Public dwSize As Integer
Public RasConnState As Integer
Public dwError As Integer
Public szDeviceType As String
Public szDeviceName As String
End Structure
Public Structure RASDIALPARAMS95
Public dwSize As Integer
Public szEntryName As String
Public szPhoneNumber As String
Public szCallbackNumber As String
Public szUserName As String
Public szPassword As String
Public szDomain As String
End Structure
Public Declare Auto Function RasDial Lib "RasApi32.DLL" Alias "RasDialA" (ByVal lpRasDialExtensions As Integer, ByVal lpszPhonebook As String, ByVal lprasdialparams As RASDIALPARAMS95, ByVal dwNotifierType As Integer, ByVal lpvNotifier As Integer, ByRef lphRasConn As Integer) As Integer
Public Declare Auto Function RasHangUp Lib "RasApi32.DLL" Alias "RasHangUpA" (ByVal hRasConn As Integer) As Integer
Public Function AddConnection(ByVal strNewEntryName As String, ByVal strNewPhoneNumber As String, ByVal strNewCallbackNumber As String, ByVal strNewUsername As String, ByVal strNewPassword As String, ByVal strNewDomain As String) As Integer
Dim lprasdialparams As RASDIALPARAMS95
Dim lngRetCode As Integer
Dim lngRetHangUp As Integer
lprasdialparams.dwSize = Marshal.SizeOf(GetType(RASDIALPARAMS95))
lprasdialparams.szEntryName = strNewEntryName
lprasdialparams.szPhoneNumber = strNewPhoneNumber
lprasdialparams.szCallbackNumber = strNewCallbackNumber
lprasdialparams.szUserName = strNewUsername
lprasdialparams.szPassword = strNewPassword
lprasdialparams.szDomain = strNewDomain
lngRetCode = RasDial(APINULL, vbNullString, lprasdialparams, APINULL, APINULL, hRasConn)
If lngRetCode > 0 Then
lngRetHangUp = RasHangUp(hRasConn)
End If
AddConnection = lngRetCode
End Function
End Module