Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than rasapi32, prefix the name with the module name and a period.
RasEnumDevices (rasapi32)
.
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;
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]));
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
Private Declare Auto Function RasEnumDevices Lib "rasapi32.dll" (ByVal lpRasDevInfo As IntPtr, ByRef lpcb As Integer, ByRef lpcDevices As Integer) As Integer
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
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
ByRef is a VB keyword that specifies a variable to be passed as a parameter BY REFERENCE. In other words, the pointer to the variable is passed and any change to its value made within the function or sub will change its value outside the function/sub.
4/25/2007 3:19:29 AM - anonymous
ByRef is a VB keyword that specifies a variable to be passed as a parameter BY REFERENCE. In other words, the pointer to the variable is passed and any change to its value made within the function or sub will change its value outside the function/sub.
4/25/2007 3:19:29 AM - anonymous
TODO - a short description
3/16/2007 8:17:31 AM - -63.69.129.2
Click to read this page
4/6/2008 7:23:14 AM - anonymous
TODO - a short description
3/11/2009 2:08:10 PM - -195.137.200.48
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
ByRef is a VB keyword that specifies a variable to be passed as a parameter BY REFERENCE. In other words, the pointer to the variable is passed and any change to its value made within the function or sub will change its value outside the function/sub.
4/25/2007 3:19:29 AM - anonymous
ByRef is a VB keyword that specifies a variable to be passed as a parameter BY REFERENCE. In other words, the pointer to the variable is passed and any change to its value made within the function or sub will change its value outside the function/sub.
4/25/2007 3:19:29 AM - anonymous
TODO - a short description
3/16/2007 8:17:31 AM - -63.69.129.2
Click to read this page
4/6/2008 7:23:14 AM - anonymous
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).