RasEnumEntries (rasapi32)
Last changed: -78.154.48.2

.
Summary

C# Signature:

[DllImport("rasapi32.dll", SetLastError=true)]
static extern uint RasEnumEntries(IntPtr reserved,IntPtr lpszPhonebook,[In,Out] RASENTRYNAME[] lprasentryname,ref int lpcb, ref int lpcEntries);

VB Signature:

<DllImport("rasapi32.dll", EntryPoint:="RasEnumEntries", CharSet:=CharSet.Auto)> _
Private Shared Function RasEnumEntries( _
     ByVal reserved As String, _
     ByVal lpszPhoneBook As String, _
     ByVal lpRasEntryName As IntPtr, _
     ByRef lpc As Int32, _
     ByRef lpcEntries As Int32) As ReturnCodes
End Function

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

    const int MAX_PATH = 260;
    const int RAS_MaxEntryName = 256;

[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]

        struct RASENTRYNAME {
            public int     dwSize;
            [MarshalAs(UnmanagedType.ByValTStr,SizeConst=RAS_MaxEntryName+1)]
            public string    szEntryName;
            [MarshalAs(UnmanagedType.ByValTStr,SizeConst=MAX_PATH)]
            public string    szPhonebook;
            public int      dwSubEntry;
        }

Sample Code:

  int cb=Marshal.SizeOf(typeof(RASENTRYNAME)),entries=0;
  RASENTRYNAME[] entryNames=new RASENTRYNAME[1];
  entryNames[0].dwSize=Marshal.SizeOf(typeof(RASENTRYNAME));
  //Get entry number
  uint nRet=RasEnumEntries(IntPtr.Zero,IntPtr.Zero,entryNames,ref cb,ref entries);
  if(entries==0) return;
  _EntryNames=new string[entries];
  entryNames=new RASENTRYNAME[entries];
  for(int i=0;i<entries;i++)
  {
    entryNames[i].dwSize=Marshal.SizeOf(typeof(RASENTRYNAME));
  }

  nRet=RasEnumEntries(IntPtr.Zero,IntPtr.Zero,entryNames,ref cb,ref entries);
  for(int i=0;i<entries;i++)
  {
    _EntryNames[i]=entryNames[i].szEntryName;            
  }        

Alternative Managed API:

Do you know one? Please contribute it!

Documentation