473,404 Members | 2,187 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,404 software developers and data experts.

RasEnumConnections

Hi!
I need really urgent help:
How to make RasEnumConnections work???
There were a few discusion about this function and RAS in general on this
forum so I'm sure you know the solvation...
On my computer this function returns 632
and I have no idea why...
It's really very important for me, help if you can...

My code looks like this:
Imports System.Runtime.InteropServices

Module rass

Private Const RAS_MaxEntryName As Integer = 256

Private Const RAS_MaxDeviceType As Integer = 16

Private Const RAS_MaxDeviceName As Integer = 128

Public Structure RASCONN

Public dwSize As Integer

Public hRasCon As IntPtr

<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxEntryName + 1)> Public
szEntryname As String

<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxDeviceType + 1)>
Public szDeviceType As String

<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxDeviceName + 1)>
Public szDeviceName As String

End Structure

Private Declare Auto Function RasEnumConnections Lib "rasapi32.dll" (ByVal
lpRasCon As IntPtr, ByVal lpcb As Integer, ByVal ByReflpcConnections As
Integer) As Integer

Public Sub Main()

Dim structtype As Type = GetType(RASCONN)

Dim structsize As Integer = Marshal.SizeOf(GetType(RASCONN))

Dim bufsize As Integer = structsize

Dim entrycount As Integer

Dim entries() As RASCONN

Dim bufptr As IntPtr = Marshal.AllocHGlobal(structsize)

Marshal.WriteInt32(bufptr, structsize)

Dim retcode As Integer = RasEnumConnections(bufptr, bufsize, entrycount)

End Sub

End Module
Nov 20 '05 #1
4 3768
Private Declare Auto Function RasEnumConnections Lib "rasapi32.dll" (ByVal
lpRasCon As IntPtr, ByVal lpcb As Integer, ByVal ByReflpcConnections As
Integer) As Integer


The last two parameters should be passed ByRef.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #2
Hi!
I've changed it - but still I get the retcode = 632 (should return 0 if
everything is right)
I've got no idea how to solve this problem...
Once again - help!

Now the code looks like this:
Imports System.Runtime.InteropServices

Module rasse

Private Const RAS_MaxEntryName As Integer = 256

Private Const RAS_MaxDeviceType As Integer = 16

Private Const RAS_MaxDeviceName As Integer = 128

Public Structure RASCONN

Public dwSize As Integer

Public hRasCon As IntPtr

<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxEntryName + 1)> _

Public szEntryname As String

<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxDeviceType + 1)> _

Public szDeviceType As String

<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxDeviceName + 1)> _

Public szDeviceName As String

End Structure

Private Declare Auto Function RasEnumConnections Lib "rasapi32.dll" (ByVal _

lpRasCon As IntPtr, ByRef lpcb As Integer, ByRef ByReflpcConnections As _

Integer) As Integer

Public Sub Main()

Dim structtype As Type = GetType(RASCONN)

Dim structsize As Integer = Marshal.SizeOf(GetType(RASCONN))

Dim bufsize As Integer = structsize

Dim entrycount As Integer

Dim entries() As RASCONN

Dim bufptr As IntPtr = Marshal.AllocHGlobal(structsize)

Marshal.WriteInt32(bufptr, structsize)

Dim retcode As Integer = RasEnumConnections(bufptr, bufsize, entrycount)

End Sub

End Module
Nov 20 '05 #3
"zurg" <zu**@wp.pl> schrieb
Hi!
I've changed it - but still I get the retcode = 632 (should return 0
if everything is right)
I've got no idea how to solve this problem...
Once again - help!

Now the code looks like this:
Imports System.Runtime.InteropServices

Module rasse
Private Const RAS_MaxEntryName As Integer = 256
Private Const RAS_MaxDeviceType As Integer = 16
Private Const RAS_MaxDeviceName As Integer = 128
Public Structure RASCONN
Public dwSize As Integer
Public hRasCon As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxEntryName + 1)>
_
Public szEntryname As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxDeviceType +
1)> _

Public szDeviceType As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxDeviceName +
1)> _

Public szDeviceName As String
End Structure

Private Declare Auto Function RasEnumConnections Lib "rasapi32.dll"
(ByVal _
lpRasCon As IntPtr, ByRef lpcb As Integer, ByRef ByReflpcConnections
As _
Integer) As Integer

Public Sub Main()
Dim structtype As Type = GetType(RASCONN)
Dim structsize As Integer = Marshal.SizeOf(GetType(RASCONN))
Dim bufsize As Integer = structsize
Dim entrycount As Integer
Dim entries() As RASCONN
Dim bufptr As IntPtr = Marshal.AllocHGlobal(structsize)
Marshal.WriteInt32(bufptr, structsize)
Dim retcode As Integer = RasEnumConnections(bufptr, bufsize,
entrycount)
End Sub
End Module

- Attach the structlayout attribute to structure rasconn
- Why do you use Marshal.AllocHGlobal instead of declare a variable of type
Rasconn and passing it BYREF to RasEnumConnections? (don't forget to set
dwsize)

Don't know if that's all, but have a try.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
I've got no idea how to solve this problem...


Try adding this attribute to the RASCONN struct

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

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #5

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

Similar topics

14
by: Mickel Grönroos | last post by:
Hi all, I have a silly question. Is there are simple way to check if the computer is connected to the Internet? It seems this should be a pretty straight-forward thing to do, but as I am totally...
5
by: hzgt9b | last post by:
My team has developed an application that uses the .NET "FtpOpenFile" command. How can I find out if this FTP comamnd is secure... Well, I guess in general does .NET support secure FTPs - if so,...
9
by: Suzie | last post by:
Hi, I've inherited some code from a developer who has moved onto other things. The code makes up a rather simple application: a text editor. The problem is, I'm still a novice programmer and...
4
by: Mark | last post by:
In the Visual C++ 7.1 compiler is there a legacy code mode? This is for non-GUI code. Its easy enough to bring the project in but of course I get a lot of clashes with ISO std C++ conventions. ...
2
by: zurg | last post by:
Hi! I translated code from VB6 (worked there) to VB.Net and not it doesn't work... It has problems with RasEnumConnections function... Probably I have to add initialize but how should it look...
2
by: Black Ninja | last post by:
''''''''''''''The class needs to be called clsRAS, paste the following Imports System.Runtime.InteropServices Public Class ras Private Const RAS_MaxEntryName As Integer = 256 Private Const...
0
by: yom | last post by:
Hi all. I am having some troubles with an application that has to open a dialup up connection. I am using the Ras API RasDial to call the remote modem an all works properly. I am also able to...
13
by: Javad | last post by:
Hello I know that I should get the information of windows internet connections by using "rasapi32.dll" library, and I also have some sample codes, but I can't make them work. My exact need is to...
0
by: =?Utf-8?B?U3RlZmFub0I=?= | last post by:
Hi to all, i'm trying to use RasEnumConnections API to get the list of all remote RAS/Dialup connections that i've locally created in my PC (Windows XP Professional SP2). I can't understand why...
2
by: ketty_ng81 | last post by:
No matter how many dial up networking entries I have, the RASWrapper.RasEnumEntries(null , null , entryNames, ref cb, out entries); always returns the right number of elelments in entryNames but...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.