S
saurabh
I had used rasapi32 to dial my ras connection for broadband, and it
was dialling the connection fine, but recently I think I accidently
changed something, and now it has stopped working.
Now the callbackfuction is returning with the dwError of 604('wrong
information specified' i think). Please help me as I am at my wits
end, as to what could I have possible changed to cause this.
To try this code, just add a button on your form, and use this code:
---------------------------------------------------------------------
Imports System.Runtime.InteropServices
Public Class Form1
Const RAS95_MaxEntryName As Short = 256
Const RAS95_MaxDeviceType As Byte = 16
Const RAS95_MaxDeviceName As Byte = 32
Const RAS95_StructSize As Short = 412
Public Const RAS_MaxEntryName As Int32 = 257
Public Const MAX_PATH As Int32 = 260
Const RAS_MaxPhoneNumber = 128
Const RAS_MaxCallbackNumber = RAS_MaxPhoneNumber
Const UNLEN = 256
Const PWLEN = 256
Const DNLEN = 15
Private Const RDEOPT_IgnoreModemSpeaker = 4&
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim calledback As myrasdialfunc = AddressOf RasDialFunc
Dial("Broadband Connection", "saurabh", "xxx", calledback)
End Sub
Public Delegate Function myrasdialfunc(ByVal hrasconn As IntPtr,
ByVal unMsg As Integer, ByVal rasconnstate As Integer, ByVal dwError
As Integer, ByVal dwexterror As Integer) As Integer
Private Declare Auto Function RasDial Lib "rasapi32.dll" _
(ByRef lprasdialextensions As RASDIALEXTENSIONS, _
ByVal lpcstr As String, ByRef lprasdialparamsa As RASDIALPARAMS,
_
ByVal dword As Integer, ByVal lpvoid As myrasdialfunc, ByRef
lphrasconn As IntPtr) As Long
<StructLayout(LayoutKind.Sequential, Pack:=1,
CharSet:=CharSet.Auto)> _
Private Structure RASDIALEXTENSIONS
Public dwSize As Integer
Public dwfOptions As Integer
Public hwndParent As Integer
Public Reserved As Integer
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure RASDIALPARAMS
Public dwSize As Integer ' 1052
<MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=RAS95_MaxEntryName + 1)> Public szEntryName As String
<MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=RAS_MaxPhoneNumber + 1)> Public szPhoneNumber As String
<MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=RAS_MaxCallbackNumber + 1)> Public szCallbackNumber As
String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=UNLEN + 1)>
Public szUserName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=PWLEN + 1)>
Public szPassword As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DNLEN + 1)>
Public szDomain As String
End Structure
Private Shared Function RasDialFunc(ByVal hrasconn As IntPtr,
ByVal unMsg As Integer, ByVal rasconnstate As Integer, ByVal dwError
As Integer, ByVal dwexterror As Integer) As Integer
Try
Console.WriteLine("Dialling -------- " & rasconnstate)
Console.WriteLine("error -------- " & dwError)
Console.WriteLine("Ext error -------- " & dwexterror)
If rasconnstate <> 0 Then
If rasconnstate = 8192 Then
'Connected. Yipeee!!
End If
End If
Catch exp As Exception
MessageBox.Show(exp.Message)
End Try
End Function
Public Function Dial(ByVal Connection As String, ByVal UserName As
String, ByVal Password As String, ByVal callback As myrasdialfunc) As
IntPtr
Dim rp As New RASDIALPARAMS(), h As New IntPtr(), resp As
Integer
Dim rasext As New RASDIALEXTENSIONS()
With rasext
.hwndParent = 0&
.Reserved = 0
.dwfOptions = RDEOPT_IgnoreModemSpeaker
.dwSize = Marshal.SizeOf(GetType(RASDIALEXTENSIONS))
End With
With rp
.szEntryName = Connection
.szUserName = UserName
.szPassword = Password
.szPhoneNumber = ""
.szCallbackNumber = ""
.szDomain = "*"
.dwSize = Marshal.SizeOf(GetType(RASDIALPARAMS))
End With
If UserName = "" Then
MessageBox.Show("Username/Password empty. Please enter it
in the application settings")
Exit Function
End If
resp = RasDial(rasext, Nothing, rp, 1, callback, h)
'AddressOf RasDialFunc
'error 756 = already being dialled
Console.WriteLine("rasdial - " & resp)
Return h
End Function
End Class
was dialling the connection fine, but recently I think I accidently
changed something, and now it has stopped working.
Now the callbackfuction is returning with the dwError of 604('wrong
information specified' i think). Please help me as I am at my wits
end, as to what could I have possible changed to cause this.
To try this code, just add a button on your form, and use this code:
---------------------------------------------------------------------
Imports System.Runtime.InteropServices
Public Class Form1
Const RAS95_MaxEntryName As Short = 256
Const RAS95_MaxDeviceType As Byte = 16
Const RAS95_MaxDeviceName As Byte = 32
Const RAS95_StructSize As Short = 412
Public Const RAS_MaxEntryName As Int32 = 257
Public Const MAX_PATH As Int32 = 260
Const RAS_MaxPhoneNumber = 128
Const RAS_MaxCallbackNumber = RAS_MaxPhoneNumber
Const UNLEN = 256
Const PWLEN = 256
Const DNLEN = 15
Private Const RDEOPT_IgnoreModemSpeaker = 4&
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim calledback As myrasdialfunc = AddressOf RasDialFunc
Dial("Broadband Connection", "saurabh", "xxx", calledback)
End Sub
Public Delegate Function myrasdialfunc(ByVal hrasconn As IntPtr,
ByVal unMsg As Integer, ByVal rasconnstate As Integer, ByVal dwError
As Integer, ByVal dwexterror As Integer) As Integer
Private Declare Auto Function RasDial Lib "rasapi32.dll" _
(ByRef lprasdialextensions As RASDIALEXTENSIONS, _
ByVal lpcstr As String, ByRef lprasdialparamsa As RASDIALPARAMS,
_
ByVal dword As Integer, ByVal lpvoid As myrasdialfunc, ByRef
lphrasconn As IntPtr) As Long
<StructLayout(LayoutKind.Sequential, Pack:=1,
CharSet:=CharSet.Auto)> _
Private Structure RASDIALEXTENSIONS
Public dwSize As Integer
Public dwfOptions As Integer
Public hwndParent As Integer
Public Reserved As Integer
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure RASDIALPARAMS
Public dwSize As Integer ' 1052
<MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=RAS95_MaxEntryName + 1)> Public szEntryName As String
<MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=RAS_MaxPhoneNumber + 1)> Public szPhoneNumber As String
<MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=RAS_MaxCallbackNumber + 1)> Public szCallbackNumber As
String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=UNLEN + 1)>
Public szUserName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=PWLEN + 1)>
Public szPassword As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DNLEN + 1)>
Public szDomain As String
End Structure
Private Shared Function RasDialFunc(ByVal hrasconn As IntPtr,
ByVal unMsg As Integer, ByVal rasconnstate As Integer, ByVal dwError
As Integer, ByVal dwexterror As Integer) As Integer
Try
Console.WriteLine("Dialling -------- " & rasconnstate)
Console.WriteLine("error -------- " & dwError)
Console.WriteLine("Ext error -------- " & dwexterror)
If rasconnstate <> 0 Then
If rasconnstate = 8192 Then
'Connected. Yipeee!!
End If
End If
Catch exp As Exception
MessageBox.Show(exp.Message)
End Try
End Function
Public Function Dial(ByVal Connection As String, ByVal UserName As
String, ByVal Password As String, ByVal callback As myrasdialfunc) As
IntPtr
Dim rp As New RASDIALPARAMS(), h As New IntPtr(), resp As
Integer
Dim rasext As New RASDIALEXTENSIONS()
With rasext
.hwndParent = 0&
.Reserved = 0
.dwfOptions = RDEOPT_IgnoreModemSpeaker
.dwSize = Marshal.SizeOf(GetType(RASDIALEXTENSIONS))
End With
With rp
.szEntryName = Connection
.szUserName = UserName
.szPassword = Password
.szPhoneNumber = ""
.szCallbackNumber = ""
.szDomain = "*"
.dwSize = Marshal.SizeOf(GetType(RASDIALPARAMS))
End With
If UserName = "" Then
MessageBox.Show("Username/Password empty. Please enter it
in the application settings")
Exit Function
End If
resp = RasDial(rasext, Nothing, rp, 1, callback, h)
'AddressOf RasDialFunc
'error 756 = already being dialled
Console.WriteLine("rasdial - " & resp)
Return h
End Function
End Class