M
Mobile Boy 36
Hello,
I have to write a vb.net class to make and hangup a dialup connection.
Is this possible by managed code ?
I tried to do it by pinvoke but the complex structures are giving problems
In C++ you have got the following declaration:
DWORD RASAPI RasDial (LPRASDIALEXTENSIONS dialExtensions,
LPTSTR phoneBookPath,
LPRASDIALPARAMS rasDialParam,
DWORD NotifierType,
LPVOID notifier,
LPHRASCONN pRasConn);
I tried to put that in vb.net. This is my attempt (it does not work -
unspecified error)
Does someone know how I can get this piece of code working in Vb.NET ?
What dll do I have to use for the rasdial (coredll.dl0)...
Does someone have a vb.net class handling ras connections?
Some help would be greatly appreciated...
THIS IS MY CODE:
Public Class RAS
Private Const RAS95_MaxEntryName = 256
Private Const RAS_MaxPhoneNumber = 128
Private Const RAS_MaxCallbackNumber = RAS_MaxPhoneNumber
Private Const UNLEN = 256
Private Const PWLEN = 256
Private Const DNLEN = 12
Public Structure RASDIALPARAMS
Public dwSize As Integer ' 1052
Public szEntryName() As As Byte 'RAS95_MaxEntryName
Public szPhoneNumber() As Byte 'RAS_MaxPhoneNumber
Public szCallbackNumber() As Byte 'RAS_MaxCallbackNumber
Public szUserName() As Byte ' UNLEN
Public szPassword() As Byte 'PWLEN
Public szDomain() As Byte 'DNLEN
End Structure
'DWORD RASAPI RasDial (LPRASDIALEXTENSIONS dialExtensions,
' LPTSTR phoneBookPath,
' LPRASDIALPARAMS rasDialParam,
' DWORD NotifierType,
' LPVOID notifier,
' LPHRASCONN pRasConn);
<System.Runtime.InteropServices.DllImport("coredll.dll",
EntryPoint:="RasDialW",
CharSet:=System.Runtime.InteropServices.CharSet.Unicode)> _
Public Shared Function RasDial _
(ByVal dialExtensions As Integer, ByVal lpcstrphoneBookPath As String,
_
ByVal rasDialParam As RASDIALPARAMS, ByVal NotifierType As Integer, _
ByVal lpvoidnotifier As Object, ByVal pRasConn As Integer) As Integer
End Function
Public Shared Function Dial(ByVal Connection As String, ByVal UserName
As String, ByVal Password As String) As Boolean
Dim rp As RASDIALPARAMS, h As Integer, resp As Integer
rp.dwSize = Len(rp) + 6
rp.szEntryName = Connection
rp.szPhoneNumber = ""
rp.szCallbackNumber = "*"
rp.szUserName = UserName.ToCharArray
rp.szPassword = Password
rp.szDomain = "*"
resp = RasDial(0, 0, rp, 0, 0, h) 'AddressOf RasDialFunc
Dial = (resp = 0)
End Function
I have to write a vb.net class to make and hangup a dialup connection.
Is this possible by managed code ?
I tried to do it by pinvoke but the complex structures are giving problems
In C++ you have got the following declaration:
DWORD RASAPI RasDial (LPRASDIALEXTENSIONS dialExtensions,
LPTSTR phoneBookPath,
LPRASDIALPARAMS rasDialParam,
DWORD NotifierType,
LPVOID notifier,
LPHRASCONN pRasConn);
I tried to put that in vb.net. This is my attempt (it does not work -
unspecified error)
Does someone know how I can get this piece of code working in Vb.NET ?
What dll do I have to use for the rasdial (coredll.dl0)...
Does someone have a vb.net class handling ras connections?
Some help would be greatly appreciated...
THIS IS MY CODE:
Public Class RAS
Private Const RAS95_MaxEntryName = 256
Private Const RAS_MaxPhoneNumber = 128
Private Const RAS_MaxCallbackNumber = RAS_MaxPhoneNumber
Private Const UNLEN = 256
Private Const PWLEN = 256
Private Const DNLEN = 12
Public Structure RASDIALPARAMS
Public dwSize As Integer ' 1052
Public szEntryName() As As Byte 'RAS95_MaxEntryName
Public szPhoneNumber() As Byte 'RAS_MaxPhoneNumber
Public szCallbackNumber() As Byte 'RAS_MaxCallbackNumber
Public szUserName() As Byte ' UNLEN
Public szPassword() As Byte 'PWLEN
Public szDomain() As Byte 'DNLEN
End Structure
'DWORD RASAPI RasDial (LPRASDIALEXTENSIONS dialExtensions,
' LPTSTR phoneBookPath,
' LPRASDIALPARAMS rasDialParam,
' DWORD NotifierType,
' LPVOID notifier,
' LPHRASCONN pRasConn);
<System.Runtime.InteropServices.DllImport("coredll.dll",
EntryPoint:="RasDialW",
CharSet:=System.Runtime.InteropServices.CharSet.Unicode)> _
Public Shared Function RasDial _
(ByVal dialExtensions As Integer, ByVal lpcstrphoneBookPath As String,
_
ByVal rasDialParam As RASDIALPARAMS, ByVal NotifierType As Integer, _
ByVal lpvoidnotifier As Object, ByVal pRasConn As Integer) As Integer
End Function
Public Shared Function Dial(ByVal Connection As String, ByVal UserName
As String, ByVal Password As String) As Boolean
Dim rp As RASDIALPARAMS, h As Integer, resp As Integer
rp.dwSize = Len(rp) + 6
rp.szEntryName = Connection
rp.szPhoneNumber = ""
rp.szCallbackNumber = "*"
rp.szUserName = UserName.ToCharArray
rp.szPassword = Password
rp.szDomain = "*"
resp = RasDial(0, 0, rp, 0, 0, h) 'AddressOf RasDialFunc
Dial = (resp = 0)
End Function