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);
}
}
}