RAS (DIAL UP) - GPRS from vb.net code - HELP

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
 
A

Alex Yakhnin [MVP]

P/Invoke Marshaller in CF is not capable in marshalling
structures with arrays in it. Possible solution is to
convert the RASDIALPARAMS to a byte array and pass it to
the RasDial call. You can take a look at my article here:

http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dnnetcomp/html/ProcessManager.asp?
frame=true

You can also use a ready to use solution:

http://www.intelliprog.com/netcf/ras.html

--
Alex Yakhnin, .NET CF MVP
ItelliProg, Inc.
http://www.intelliprog.com
http://www.opennetcf.org
blog: http://blog.opennetcf.org/yakhnin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top