473,602 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 RASGetEntryProp erties
API
Getting the Dial Parameters using the RasGetEntryDial Params 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("Ras Api32.dll", CharSet:=CharSe t.Auto)> _
Public Function RasDial( _
ByRef lprasDialExtens ions As RASDIALEXTENSIO NS, _
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(L ayoutKind.Seque ntial, CharSet:=CharSe t.Auto)> _
Public Structure RASDIALPARAMS
Public dwSize As Integer
<MarshalAs(Unma nagedType.ByVal TStr,
sizeconst:=CInt (RASFieldSizeCo nstants.RAS_Max EntryName + 1))> _
Public szEntryName As String
<MarshalAs(Unma nagedType.ByVal TStr,
sizeconst:=CInt (RASFieldSizeCo nstants.RAS_Max PhoneNumber + 1))> _
Public szPhoneNumber As String
<MarshalAs(Unma nagedType.ByVal TStr,
sizeconst:=CInt (RASFieldSizeCo nstants.RAS_Max CallbackNumber + 1))> _
Public szCallBackNumbe r As String
<MarshalAs(Unma nagedType.ByVal TStr,
sizeconst:=CInt (RASFieldSizeCo nstants.UNLEN + 1))> _
Public szUsername As String
<MarshalAs(Unma nagedType.ByVal TStr,
sizeconst:=CInt (RASFieldSizeCo nstants.PWLEN + 1))> _
Public szPassword As String
<MarshalAs(Unma nagedType.ByVal TStr,
sizeconst:=CInt (RASFieldSizeCo nstants.DNLEN + 1))> _
Public szDomain As String
#If OSVER > 4 Then
Public dwSubEntry As Integer
Public dwCallBackID As Integer
#End If

'RASDIALEXTENSI ONS
<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Auto)> _
Public Structure RASDIALEXTENSIO NS
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(L ayoutKind.Seque ntial, charset:=CharSe t.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(RASDIAL PARAMS))
.szEntryName = mEntryName
End With

x = RasGetEntryDial Params(mPhonebo ok, mParams, bln)
hconn = Nothing

x = RasDial(Nothing , Nothing, mParams, Nothing, Nothing, hconn)
End Function



Nov 20 '05 #1
8 18329
Hi Brian.

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

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

Enum RASFieldSizeCon stants
RAS_MaxEntryNam e = 256
RAS_MaxPhoneNum ber = 128
RAS_MaxCallback Number = 128
UNLEN = 256
PWLEN = 256
DNLEN = 12
End Enum

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

Dim A1 As RasDial.RASEAPI NFO
Dim A2 As RasDial.RASDIAL EXTENSIONS
Dim A3 As RasDial.RASDIAL PARAMS
Dim S As String = Marshal.SizeOf (A1) & ", " _
& Marshal.SizeOf (A2) & ", " _
& Marshal.SizeOf (A3)

RASEAPINFO 8
RASDIALEXTENSIO NS 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(L ayoutKind.Seque ntial, CharSet:=CharSe t.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_s tr.asp

RASGetDIALEntry Params API>
http://msdn.microsoft.com/library/de.../en-us/rras/rr
as/rasgetentrydial params.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(RASDIA LPARMS))" 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&scor ing=d&selm=ba47 440d.0305151934 .6d9d8ed8%40pos ting.googl
e.com&rnum=5htt p://groups.google.c om/groups?selm=An8 7uzi%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*****@briste conline.net> wrote in message news:<#5******* *******@TK2MSFT NGP09.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&scor ing=d&selm=ba47 440d.0305151934 .6d9d8ed8%40pos ting.googl
e.com&rnum=5htt p://groups.google.c om/groups?selm=An8 7uzi%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
2722
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 structures. Trying to comprehend this is harder than I thought it was going to be. I should of just skipped this chapter and went right into pointers since they seem to be easier to use. But anyways here i smy question: you define a structure...
1
691
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 code that sucessfully does this?
6
4480
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 systems over the years. I have developed code in more than 30 distinct programming languages for a wide cariety of industries. But this issue of structures in C# is beginning to annoy me. I should also make it clear that I am not a big supporter...
0
1612
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 error 668 (ERROR_NO_CONNECTION - the connection dropped)... I do make sure that I call RASHangUp between RASDial calls (in fact RASHangUp also returns error 668).. Is there something else I need to do between each call (wait for some timeout /...
6
6402
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 If I dial using RasDial(Nothing, Nothing, cRasDialParams, 0, AddressOf RasDialFunc, handle) all will be well, but when this is used, it seems that the modem does not dial at all, although a sucessful connection message is returned.
2
2399
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 the change. I know that Structures are value types, sit on the stack, and are generally more efficient to manipulate than reference types (i.e. Classes). Structures cannot use inheritance, the finalize method or default constructors. Can anyone...
0
1268
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 if a user saves the credentials or when i fill the RASDIALPARAMS with Username and Password manually. The matter is, that i need to use RasDial() with an L2TP connection which uses a certificate. It seems that i need to call a function called...
4
3782
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 calling program, i can console.writeline the state successfully. but as soon as i replace that line with updating the UI, the program freezes, and execution halts. no exceptions are thrown or anything (i've got the line in a try...catch block, but...
18
6512
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 application on a 32-bit machine. Any clue?
0
7920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8268
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5867
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.