Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

RasEnumConnections (rasapi32)
 
.
Summary
TODO - a short description

C# Signature:

[DllImport("rasapi32.dll", SetLastError = true, CharSet = CharSet.Auto)]

public static extern int RasEnumConnections(
    [In, Out] RASCONN[] rasconn,
    [In, Out] ref int cb,
    [Out] out int connections);

VB Signature:

sTODO

User-Defined Types:

const int RAS_MaxEntryName = 256;
const int RAS_MaxDeviceType = 16;
const int RAS_MaxDeviceName = 128;
const int MAX_PATH = 260;

[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Auto)]
public struct RASCONN
{
    public int dwSize;
    public IntPtr hrasconn;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxEntryName)]
    public string szEntryName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceType)]
    public string szDeviceType;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceName)]
    public string szDeviceName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)]
    public string szPhonebook;
    public int dwSubEntry;
    public Guid guidEntry;
    public int dwFlags;
    public Guid luid;                                                    
}

Notes:

I don't known why SizeConst = RAS_MaxEntryName, not SizeConst = RAS_MaxEntryName + 1 as in ras.h, but this work.

Check my English, please

Sample Code:

This is main concept only:

// create 1 item array.
RAW.RASCONN[] connections = new RAW.RASCONN[1];
connections[0].dwSize = Marshal.SizeOf(typeof(RAW.RASCONN));
//Get entries count
int connectionsCount = 0;
int cb = Marshal.SizeOf(typeof(RAW.RASCONN));
int nRet = RAW.RasEnumConnections(connections, ref cb, out connectionsCount);
if (nRet != RAW.ERROR_SUCCESS && nRet != RAW.ERROR_BUFFER_TOO_SMALL)
    throw new Win32Exception(nRet);
if (connectionsCount == 0)
    return;
// create array with specified entries number
connections = new RAW.RASCONN[connectionsCount];
for (int i = 0; i < connections.Length; i++)
{
    connections[i].dwSize = Marshal.SizeOf(typeof(RAW.RASCONN));
}
nRet = RAW.RasEnumConnections(connections, ref cb, out connectionsCount);
if (nRet != RAW.ERROR_SUCCESS)
    throw new Win32Exception((int)nRet);

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions