Public Const RAS_MaxEntryName = 256
Private Type RASENTRYNAME
dwSize As Long
szEntryName(RAS_MaxEntryName) As Byte
End Type
c 中 Char aa[16] 代表長度是16,可放 15個byte所以對應(yīng)於vb便是 aa(15) as Byte
如此才是長度16 ( 0--15)。故VB的宣告中不能再用szEntryName(RAS_MaxEntryName+1)
但是Lenb(RASENTRYNAME)的長度卻是 261 (4+257),的確,這是vb的問題,而c 的SizeOf
傳回的是4的倍數(shù)(32位元嘛)故值為264,所以我們計算某個Structure的長度時,要再多一
些運算。
以下的Fuction只適用於32位元的win95/ NT,
'以下在Form中
Private hConn as Long
Private Sub Command1_Click()
hConn = Dialup("我的連線", "user", "passwd")
if hConn = 0 Then
Debug.Print "連線失敗"
end if
End Sub
Private Sub Command2_Click()
Call HangUp(hConn)
End Sub
'以下在.bas中
Option Explicit
Public Const RAS_MaxEntryName = 256
Public Const RAS_MaxDeviceName = 128
Public Const RAS_MaxDeviceType = 16
Public Const RAS_MaxPhoneNumber = 128
Public Const RAS_MaxCallbackNumber = 128
Public Const UNLEN = 256
Public Const PWLEN = 256
Public Const DNLEN = 15
Public Const ERROR_INVALID_HANDLE = 6
Type RASDIALPARAMS
dwSize As Long '1052
szEntryName(RAS_MaxEntryName) As Byte
szPhoneNumber(RAS_MaxPhoneNumber) As Byte
szCallbackNumber(RAS_MaxCallbackNumber) As Byte
szUserName(UNLEN) As Byte
szPassword(PWLEN) As Byte
szDomain(DNLEN) As Byte
End Type
Type RASCONNSTATUS
dwSize As Long '144
RasConnState As Long
dwError As Long
szDeviceType(RAS_MaxDeviceType) As Byte
szDeviceName(RAS_MaxDeviceName) As Byte
End Type
Declare Function RasGetErrorString Lib "rasapi32" _
Alias "RasGetErrorStringA" (ByVal ErrValue As Long, ByVal lpErrStr As String, _
ByVal cSize As Long) As Long
Declare Function RasDial Lib "rasapi32" _
Alias "RasDialA" (DialExt As Long, ByVal lpPhoneBook As String, _
RasDialParam As RASDIALPARAMS, ByVal NotifyType As Long, _
ByVal Notifter As Long, hRasConn As Long) As Long
Declare Function RasHangUp Lib "rasapi32" Alias _
"RasHangUpA" (ByVal hRasConn As Long) As Long
Declare Function RasGetConnectStatus Lib "rasapi32" Alias _
"RasGetConnectStatusA" (ByVal hRasConn As Long, _
lprasconnstatus As RASCONNSTATUS) As Long
Declare Function RasGetEntryDialParams Lib "rasapi32" _
Alias "RasGetEntryDialParamsA" (ByVal lpszPhonebook As String, _
lpRasDialParams As RASDIALPARAMS, _
lpfPassword As Byte) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Type RASENTRYNAME
dwSize As Long
szEntryName(RAS_MaxEntryName) As Byte
End Type
c 中 Char aa[16] 代表長度是16,可放 15個byte所以對應(yīng)於vb便是 aa(15) as Byte
如此才是長度16 ( 0--15)。故VB的宣告中不能再用szEntryName(RAS_MaxEntryName+1)
但是Lenb(RASENTRYNAME)的長度卻是 261 (4+257),的確,這是vb的問題,而c 的SizeOf
傳回的是4的倍數(shù)(32位元嘛)故值為264,所以我們計算某個Structure的長度時,要再多一
些運算。
以下的Fuction只適用於32位元的win95/ NT,
'以下在Form中
Private hConn as Long
Private Sub Command1_Click()
hConn = Dialup("我的連線", "user", "passwd")
if hConn = 0 Then
Debug.Print "連線失敗"
end if
End Sub
Private Sub Command2_Click()
Call HangUp(hConn)
End Sub
'以下在.bas中
Option Explicit
Public Const RAS_MaxEntryName = 256
Public Const RAS_MaxDeviceName = 128
Public Const RAS_MaxDeviceType = 16
Public Const RAS_MaxPhoneNumber = 128
Public Const RAS_MaxCallbackNumber = 128
Public Const UNLEN = 256
Public Const PWLEN = 256
Public Const DNLEN = 15
Public Const ERROR_INVALID_HANDLE = 6
Type RASDIALPARAMS
dwSize As Long '1052
szEntryName(RAS_MaxEntryName) As Byte
szPhoneNumber(RAS_MaxPhoneNumber) As Byte
szCallbackNumber(RAS_MaxCallbackNumber) As Byte
szUserName(UNLEN) As Byte
szPassword(PWLEN) As Byte
szDomain(DNLEN) As Byte
End Type
Type RASCONNSTATUS
dwSize As Long '144
RasConnState As Long
dwError As Long
szDeviceType(RAS_MaxDeviceType) As Byte
szDeviceName(RAS_MaxDeviceName) As Byte
End Type
Declare Function RasGetErrorString Lib "rasapi32" _
Alias "RasGetErrorStringA" (ByVal ErrValue As Long, ByVal lpErrStr As String, _
ByVal cSize As Long) As Long
Declare Function RasDial Lib "rasapi32" _
Alias "RasDialA" (DialExt As Long, ByVal lpPhoneBook As String, _
RasDialParam As RASDIALPARAMS, ByVal NotifyType As Long, _
ByVal Notifter As Long, hRasConn As Long) As Long
Declare Function RasHangUp Lib "rasapi32" Alias _
"RasHangUpA" (ByVal hRasConn As Long) As Long
Declare Function RasGetConnectStatus Lib "rasapi32" Alias _
"RasGetConnectStatusA" (ByVal hRasConn As Long, _
lprasconnstatus As RASCONNSTATUS) As Long
Declare Function RasGetEntryDialParams Lib "rasapi32" _
Alias "RasGetEntryDialParamsA" (ByVal lpszPhonebook As String, _
lpRasDialParams As RASDIALPARAMS, _
lpfPassword As Byte) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)