473,385 Members | 1,798 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,385 software developers and data experts.

RasEnumConnections

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 the returned list is ever empty, I
mean that
"lpcConnections" is 0
where the declaration is:
RasEnumConnections(ref RASCONN lprasconn,ref int lpcb, ref int
lpcConnections).

Can anyone help me please ?
Follows the code i wrote (C#, Visual Studio 2005), where the entry point is
"button1_Click" of a Win form application
Thanks in advance, Stefano.
****************************************

using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace test
{
internal enum RasFieldSizeConstants
{
RAS_MaxDeviceType = 16,
RAS_MaxEntryName = 20,
RAS_MaxDeviceName = 32
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct GUID
{
public uint Data1;
public ushort Data2;
public ushort Data3;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] Data4;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct RASCONN
{
public int dwSize;
public IntPtr hrasconn;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst =
(int)RasFieldSizeConstants.RAS_MaxEntryName + 1)]
public string szEntryName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst =
(int)RasFieldSizeConstants.RAS_MaxDeviceType + 1)]
public string szDeviceType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst =
(int)RasFieldSizeConstants.RAS_MaxDeviceName + 1)]
public string szDeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]//MAX_PAPTH=260
public string szPhonebook;
public int dwSubEntry;
public GUID guidEntry;
}

public class RAS
{
[DllImport("Rasapi32.dll", EntryPoint = "RasEnumConnectionsA",
SetLastError = true)]
internal static extern int RasEnumConnections
(
ref RASCONN lprasconn, // buffer to receive connections data
ref int lpcb, // size in bytes of buffer
ref int lpcConnections // number of connections written to
buffer
);
private RAS()
{}
}

public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
RASCONN lprasConn = new RASCONN();

lprasConn.dwSize = Marshal.SizeOf(typeof(RASCONN));
lprasConn.hrasconn = IntPtr.Zero;

int lpcb = 0;
int lpcConnections = 0;
int nRet = 0;

lpcb = Marshal.SizeOf(typeof(RASCONN));
nRet = RAS.RasEnumConnections(ref lprasConn, ref lpcb, ref
lpcConnections);

}
}
}

Jul 31 '07 #1
0 1337

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

Similar topics

2
by: Blind | last post by:
I have problem with RasEnumConnections() Api function, it backs me errors: this error: ------------------------------------------------------------- ViewAdapterInfo error LNK2019: unresolved...
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...
4
by: zurg | last post by:
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...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.