473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

VB.NET, RAS, RASDIAL AND STRUCTURES

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



Nov 20 '05 #1
8 18296
Hi Brian.

I know nothing about RAS but that didn't stop me investigating. :-)

You left out the RASFieldSizeConstants so I got some values off the Net:

Enum RASFieldSizeConstants
RAS_MaxEntryName = 256
RAS_MaxPhoneNumber = 128
RAS_MaxCallbackNumber = 128
UNLEN = 256
PWLEN = 256
DNLEN = 12
End Enum

With those values and your structures, I obtained the following sizes,

Dim A1 As RasDial.RASEAPINFO
Dim A2 As RasDial.RASDIALEXTENSIONS
Dim A3 As RasDial.RASDIALPARAMS
Dim S As String = Marshal.SizeOf (A1) & ", " _
& Marshal.SizeOf (A2) & ", " _
& Marshal.SizeOf (A3)

RASEAPINFO 8
RASDIALEXTENSIONS 28
RASDIALPARAMS 2088

Also off the Net I got this (VB6):

Private Type RASDIALPARAMS
dwSize As Long ' 1052

Now this may or may not be the same version as your RASDIALPARAMS but
there is a big discrepancy. And I tracked that down to your Struct attribute.

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _

Having CharSet.Auto leaves it up to the compiler. It's choosing Unicode
instead of Ansi. Changing it to CharSet.Ansi brings the size to 1040 but this
is still short.

I tried intellisense with A3 to see what fields it had and dwEntry and
dwCallBackID were missing. I'm on Win2000. Maybe OSVER isn't the correct name
to use. I don't know.

Anyway, I commented out the #If and the size came up to 1048. I noticed in
the code that dwSize was being set to the size of the structure plus 6. Which
brings us to 1052.

I've no idea what the correct value should be. I was looking at:
http://pub13.ezboard.com/fvisualbasi...topicID=355.to
pic
and
http://users.chariot.net.au/~akia/ra...dialparams.htm

It'll probably make more sense to you.

The reason I've spelled out my labours is partly to keep track as I've
been doing it on and off for a while. The other part is to give you a flavour
of the sort of hunting around type things that you can use when solving
problems of this nature. Things to put in your toolkit as it were. :-)

One final note. If you don't get any joy and it <still> complains about
the size, add an array of bytes to the end of your structure (to prevent
memory overwrites). Then create a loop with error trapping that will simply
try a whole range of sizes until it comes back without an error. At least then
you'll know what size you're aiming for.

Best of luck,
Fergus
Nov 20 '05 #2
Cor
Hi Fergus,
I know nothing and than an explanation about RAS if you are the natural born
hacker.
:-)
Cor
Nov 20 '05 #3


Fergus, Firstly thanks for your reply. It has shed some light on some of
the problems that i have had.

I am still unable to get the correct structure size to pass into the
RasDial API. I have been using the Structure Information from the
Platform SDK on MS Web site

RASDIALPARAMS >
http://msdn.microsoft.com/library/de.../en-us/rras/rr
as/rasdialparams_str.asp

RASGetDIALEntryParams API>
http://msdn.microsoft.com/library/de.../en-us/rras/rr
as/rasgetentrydialparams.asp

RASDIAL API
http://msdn.microsoft.com/library/de.../en-us/rras/rr
as/rasdial.asp

It says in the RASDIAL API Spec that to get the RASDIALPARAMS Structure
correctly - set the dwsize property to
"MARSHAL.SIZEOF(GETTYPE(RASDIALPARMS))" well thats how I interpreted it
;) and then pass this into the RASDIAL API. Which in theory should make
the structure the correct size. it doesn't. I had a similar problem with
another part of the APP which was RASENUMENTRYS and I was getting the
632 error then also - but as it turned out the structure size was being
affected by the incorrect (BYREF/BYVAL) declaration. I am at a loss as
to what is wrong. I have a working example of this in c# and when I step
through the code making notes of the sizes and values it is !exactly!
the same as in my VB.NET Implementation of the code. The only thing I
think it could be is the API and Structure Declarations themselves.
Don't know.

Brian Corbett

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4
Hi Brian,

I am a bit confused. You say the C# sizes and values match the VB ones exactly. This is <after> having changed CharSet.Auto to
Ansi? And what sizes/values are these?

Could you post the C# and your latest VB? Preferably in the form of classes/modules (zipped) that I can plug into a project. If
it's not too big, an entire project would be handy.

Did you check out the references that I gave? These show VB code that omits the '+ 1's that the MSDN doc shows, yet I believe
they show working code.

How did you get on with the idea of trying a range of sizes until it stops complaining?

Regards,
Fergus

Nov 20 '05 #5

Fergus, Thanks very much for your help. Fortunately I have found an
example that show me what I need to do in VB.NET so I can see where I am
going wrong - and I'm a long way off ;) - I have posted two links below
one is the c# example that I was using - and 1 to the vb.net example -
These may be of use to you sometime.

c#
http://www.codeproject.com/useritems...asp?target=ras

vb.net
http://groups.google.com/groups?q=ra...ie=utf-8&oe=ut
f-8&safe=off&scoring=d&selm=ba47440d.0305151934.6d9d 8ed8%40posting.googl
e.com&rnum=5http://groups.google.com/groups?selm=An87uzi%23BHA.1532%40cp
msftngxa08

Thanks again for you time and help
Brian Corbett

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #6
Hi Brian,

Thanks for the links. That's a lot of Marshally code there, shudder. Glad someone else has done it.:-)

Good luck with your App.

Regards,
Fergus
Nov 20 '05 #7
I never finished this software due to time limitaitons. But when you
enumerate entries and stuff, pass a array of structures by reference
and the class function will fill it in. Then you can do For Each
statement to go through the array and know which entries you want to
work with,etc.

Let me know if you need help. Like I said, time permitting I will
actually make this thing a little more understandable than it is now.

I have implemented most of the features I needed using VB6. One day, I
will use the .NET stuff since it is better. It just doesnt have enough
documentation.

Brian <br*****@bristeconline.net> wrote in message news:<#5**************@TK2MSFTNGP09.phx.gbl>...
Fergus, Thanks very much for your help. Fortunately I have found an
example that show me what I need to do in VB.NET so I can see where I am
going wrong - and I'm a long way off ;) - I have posted two links below
one is the c# example that I was using - and 1 to the vb.net example -
These may be of use to you sometime.

c#
http://www.codeproject.com/useritems...asp?target=ras

vb.net
http://groups.google.com/groups?q=ra...ie=utf-8&oe=ut
f-8&safe=off&scoring=d&selm=ba47440d.0305151934.6d9d 8ed8%40posting.googl
e.com&rnum=5http://groups.google.com/groups?selm=An87uzi%23BHA.1532%40cp
msftngxa08

Thanks again for you time and help
Brian Corbett

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #8
There is a RAS wrapper for the .NET framework that can be found at
http://www.gotdotnet.com/Workspaces/...3-e5fdb0895b8e
which is free.

Just please, make sure you report any bugs so they can be addressed.
Thanks

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
1
by: Lee | last post by:
I have been working for hours trying to get the RasDial API function working in VB.NET with no success. All i ever get back from the API is error 87, Invalid Parameter. Does anyone have any .NET...
6
by: Ken Allen | last post by:
OK, I admit that I have been programming since before C++ was invented, and I have developed more than my share of assembly language systems, and even contributed to operating system and compiler...
0
by: Ken Hughes | last post by:
Hi I'm using RASDial API call from VB.Net - it works ok and connects.. The problem is if it fails the first time (line busy etc) I have it retry a couple of times. Every subsequent try fails with...
6
by: Les Hughes | last post by:
Im working on some RAS stuff, and am after callbacks for when the connection is disconnected. According to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rras/rras/rasdial.asp...
2
by: thomasfarrow | last post by:
At work, our development team has a development standards document that insists Structures should never be used. I'm looking to change this standard but need a suitable argument in order to make...
0
by: Andreas Hecker | last post by:
Hello Group, accidentially i posted this to the vb6 group. They told me, that this group should be the right place. I successfully managed to dial a ras connection using RasDial() API. It works...
4
by: bhc | last post by:
all- up until just recently, i was fairly sure i'd implemented a RasDial class in VB.NET complete with a callback to get updated status. from this wrapper, when i throw an event back to the...
18
by: hq4000 | last post by:
I have a 32-bit application installed on x64 (AMD64) Vista and Windows XP. The rasdial returns 632 - ERROR_INVALID_SIZE on x64 machine; but the rasdial behaves properly installing the same 32-bit...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.