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

RasEnumDevices (rasapi32)
 
.
Summary
TODO - a short description

C# Signature:

        [DllImport("rasapi32.dll", SetLastError=true,CharSet=CharSet.Auto)]
        static extern int RasEnumDevices(
            IntPtr lpRasDevInfo,
            ref int lpcb,
            ref int lpcDevices);

Tips & Tricks:

This structure needs to be defined.

    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
    public class RASDEVINFO
    {
        public const int RAS_MAXDEVICETYPE = 16;
        public const int RAS_MAXDEVICENAME  = 128;
:(

VB Signature:

This Signature is needed.

Private Declare Auto Function RasEnumDevices Lib "rasapi32.dll" (ByVal lpRasDevInfo As IntPtr, ByRef lpcb As Integer, ByRef lpcDevices As Integer) As Integer

User-Defined Types:

This Structure Is Needed.

Alternative Managed API:

Do you know one? Please contribute it!

        public int dwSize;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MAXDEVICETYPE + 1)]
        public string szDeviceType ;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MAXDEVICENAME + 1)]
        public string szDeviceName ;
    }

Sample Code:

        private RASDEVINFO[] getDevices()
        {
            RASDEVINFO[] rdiRets = new RASDEVINFO[1];

Notes:

None.

            int intRet=0;
            int lpcb = 0;
            int  lpcDevices = 0;
            IntPtr devinfo = IntPtr.Zero;

            intRet = RasEnumDevices(IntPtr.Zero,ref lpcb,ref lpcDevices);

Tips & Tricks:

This structure needs to be defined.

            devinfo = Marshal.AllocHGlobal(lpcb);

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

    Public Class CRasDevInfo
        Public Const RAS_MAXDEVICETYPE As Integer = 16
        Public Const RAS_MAXDEVICENAME As Integer = 128
        Public dwSize As Integer
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MAXDEVICETYPE + 1)> _
        Public szDeviceType As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MAXDEVICENAME + 1)> _
        Public szDeviceName As String
    End Class

            rdiRets[0] = new RASDEVINFO();
            rdiRets[0].dwSize = Marshal.SizeOf(typeof(RASDEVINFO));
            Marshal.WriteInt32(devinfo, Marshal.SizeOf(rdiRets[0]));

Sample Code:

            intRet = RasEnumDevices(devinfo,ref  lpcb,ref lpcDevices);
            if( intRet == 0)
            {
                rdiRets = new RASDEVINFO[lpcDevices];
                for(int i=0;i<lpcDevices;i++)            
                {
                    rdiRets[i] = new RASDEVINFO();

Public Shared Function GetDevices() As CRasDevInfo()

        Dim intRet As Integer
        Dim lpcb As Integer
        Dim lpcDevices As Integer
        Dim devinfo As IntPtr
        Dim rdiRet As CRasDevInfo()
        Dim i As Integer
        RasEnumDevices(IntPtr.Zero, lpcb, lpcDevices)
        devinfo = Marshal.AllocHGlobal(lpcb)
        ReDim rdiRet(0)
        rdiRet(0) = New CRasDevInfo()
        Marshal.WriteInt32(devinfo, Marshal.SizeOf(rdiRet(0)))
        intRet = RasEnumDevices(devinfo, lpcb, lpcDevices)
        If intRet = 0 Then
        ReDim rdiRet(lpcDevices - 1)
        For i = 0 To lpcDevices - 1
            rdiRet(i) = New CRasDevInfo()
            Marshal.PtrToStructure(devinfo, rdiRet(i))
            devinfo = IntPtr.op_Explicit(devinfo.ToInt32() + Marshal.SizeOf(rdiRet(i)))
        Next
        Marshal.FreeHGlobal(devinfo)
        Return rdiRet
        Else
        Return Nothing
        End If
    End Function

                    Marshal.PtrToStructure(devinfo, rdiRets[i]);
                    devinfo = ( IntPtr )(devinfo.ToInt32()+ Marshal.SizeOf(rdiRets[i]));
                }                
            }
            return rdiRets;
        }    


VB Signature:

This Signature is needed.

Private Declare Auto Function RasEnumDevices Lib "rasapi32.dll" (ByVal lpRasDevInfo As IntPtr, ByRef lpcb As Integer, ByRef lpcDevices As Integer) As Integer

User-Defined Types:

This Structure Is Needed.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

This structure needs to be defined.

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

    Public Class CRasDevInfo
        Public Const RAS_MAXDEVICETYPE As Integer = 16
        Public Const RAS_MAXDEVICENAME As Integer = 128
        Public dwSize As Integer
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MAXDEVICETYPE + 1)> _
        Public szDeviceType As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=RAS_MAXDEVICENAME + 1)> _
        Public szDeviceName As String
    End Class

Sample Code:

Public Shared Function GetDevices() As CRasDevInfo()

        Dim intRet As Integer
        Dim lpcb As Integer
        Dim lpcDevices As Integer
        Dim devinfo As IntPtr
        Dim rdiRet As CRasDevInfo()
        Dim i As Integer
        RasEnumDevices(IntPtr.Zero, lpcb, lpcDevices)
        devinfo = Marshal.AllocHGlobal(lpcb)
        ReDim rdiRet(0)
        rdiRet(0) = New CRasDevInfo()
        Marshal.WriteInt32(devinfo, Marshal.SizeOf(rdiRet(0)))
        intRet = RasEnumDevices(devinfo, lpcb, lpcDevices)
        If intRet = 0 Then
        ReDim rdiRet(lpcDevices - 1)
        For i = 0 To lpcDevices - 1
            rdiRet(i) = New CRasDevInfo()
            Marshal.PtrToStructure(devinfo, rdiRet(i))
            devinfo = IntPtr.op_Explicit(devinfo.ToInt32() + Marshal.SizeOf(rdiRet(i)))
        Next
        Marshal.FreeHGlobal(devinfo)
        Return rdiRet
        Else
        Return Nothing
        End If
    End Function

Alternative Managed API:

http://www.codeplex.com/DotRas

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
Edit This Page
Find References
Show Printable Version
Revisions