I'm am trying to write a RAS Component that lists the Available RAS
Connections on the current machine, I have got as far as
getting the Connections using the RasEnumEntry API
Getting the Entry Properties for Each entry using RASGetEntryProperties
API
Getting the Dial Parameters using the RasGetEntryDialParams API
I am Getting unstuck when it comes to actually dial the Ras Connection. When
I actually Call the RASDIAL API I always Get Error 632 (Structure Size
Invalid) any Pointers that may be helpful to me would be appreciated.
Here is what I have :
*Ras Dial API Call*
<DllImport("RasApi32.dll", CharSet:=CharSet.Auto)> _
Public Function RasDial( _
ByRef lprasDialExtensions As RASDIALEXTENSIONS, _
ByVal lpszPhoneBook As String, _
ByRef lpRasDialParams As RASDIALPARAMS, _
ByVal dwNotifierType As Int32, _
ByVal hwndNotifier As System.Delegate, _
ByRef lphRasConn As IntPtr) As Int32
End Function
The threeStructures are Below:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure RASDIALPARAMS
Public dwSize As Integer
<MarshalAs(UnmanagedType.ByValTStr,
sizeconst:=CInt(RASFieldSizeConstants.RAS_MaxEntry Name + 1))> _
Public szEntryName As String
<MarshalAs(UnmanagedType.ByValTStr,
sizeconst:=CInt(RASFieldSizeConstants.RAS_MaxPhone Number + 1))> _
Public szPhoneNumber As String
<MarshalAs(UnmanagedType.ByValTStr,
sizeconst:=CInt(RASFieldSizeConstants.RAS_MaxCallb ackNumber + 1))> _
Public szCallBackNumber As String
<MarshalAs(UnmanagedType.ByValTStr,
sizeconst:=CInt(RASFieldSizeConstants.UNLEN + 1))> _
Public szUsername As String
<MarshalAs(UnmanagedType.ByValTStr,
sizeconst:=CInt(RASFieldSizeConstants.PWLEN + 1))> _
Public szPassword As String
<MarshalAs(UnmanagedType.ByValTStr,
sizeconst:=CInt(RASFieldSizeConstants.DNLEN + 1))> _
Public szDomain As String
#If OSVER > 4 Then
Public dwSubEntry As Integer
Public dwCallBackID As Integer
#End If
'RASDIALEXTENSIONS
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure RASDIALEXTENSIONS
Public dwSize As Integer
Public dwfOptions As Integer
Public hwndParent As Integer
Public Reserved As Integer
Public Reserved1 As Integer
Public RasEapINfo As RasEapINfo
End Structure
'RASEAPINFO
<StructLayout(LayoutKind.Sequential, charset:=CharSet.Auto)> _
Public Structure RASEAPINFO
Public dwSizeofEAPInfo As Int32
Public pbEapInfo As Int32
End Structure
Here is the Code so far >
Public Function Connect() As Boolean
Dim x As Integer 'Return from API Calls
Dim hconn As IntPtr 'Connection Handle
Dim bln As Boolean 'Password Stored
mParams = New RASDIALPARAMS
With mParams
.dwSize = Marshal.SizeOf(GetType(RASDIALPARAMS))
.szEntryName = mEntryName
End With
x = RasGetEntryDialParams(mPhonebook, mParams, bln)
hconn = Nothing
x = RasDial(Nothing, Nothing, mParams, Nothing, Nothing, hconn)
End Function