The RASEnumDevices function returns a list of all RAS capable devices installed on the computer, giving you their name and their type. The returned names and device types are stored in a RASDEVINFO structure.
typedef struct tagRASDEVINFO {
DWORD dwSize;
TCHAR szDeviceType[ RAS_MaxDeviceType + 1 ];
TCHAR szDeviceName[ RAS_MaxDeviceName + 1 ];
} RASDEVINFO;
Unfortunately the size of this structure is different depending on the windows platform. The constants RAS_MaxDeviceType is equal to 16 for all platforms, while RAS_MaxDeviceName is 128 for 95/98 and NT4 or later, and 32 for earlier versions of NT.
The following sample function returns a long value equal to the number of devices, and populates a dynamic array of VBRASDEVINFO structures with the device name(s), and device type(s) .
You can call on the function like so:
Dim rtn As Long
Dim clsVBRasDevInfo() As VBRASDEVINFO
rtn = VBRasEnumDevices(clsVBRasDevInfo)
For j = 0 To rtn - 1
Debug.Print clsVBRasDevInfo(j).DeviceName
Debug.Print clsVBRasDevInfo(j).DeviceType
Next j
Public Type VBRASDEVINFO
DeviceType As String
DeviceName As String
End Type
Public Declare Function RasEnumDevices _
Lib "rasapi32.dll" Alias "RasEnumDevicesA" ( _
lpRasDevInfo As Any, _
lpCb As Long, _
lpCDevices As Long _
) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
'
Function VBRasEnumDevices(clsVBRasDevInfo() As VBRASDEVINFO) As Long
Dim rtn As Long, i As Long
Dim lpCb As Long, lpCDevices As Long
Dim b() As Byte
Dim dwSize As Long
rtn = RasEnumDevices(ByVal 0&, lpCb, lpCDevices)
If lpCDevices = 0 Then Exit Function
dwSize = lpCb \ lpCDevices
ReDim b(lpCb - 1)
CopyMemory b(0), dwSize, 4
rtn = RasEnumDevices(b(0), lpCb, lpCDevices)
If lpCDevices = 0 Then Exit Function
ReDim clsVBRasDevInfo(lpCDevices - 1)
For i = 0 To lpCDevices - 1
CopyByteToTrimmedString clsVBRasDevInfo(i).DeviceType, _
b((i * dwSize) + 4), 17
CopyByteToTrimmedString clsVBRasDevInfo(i).DeviceName, _
b((i * dwSize) + 21), dwSize - 21
Next i
VBRasEnumDevices = lpCDevices
End Function
Sub CopyByteToTrimmedString(strToCopyTo As String, _
bPos As Byte, lngMaxLen As Long)
Dim strTemp As String, lngLen As Long
strTemp = String(lngMaxLen + 1, 0)
CopyMemory ByVal strTemp, bPos, lngMaxLen
lngLen = InStr(strTemp, Chr$(0)) - 1
strToCopyTo = Left$(strTemp, lngLen)
End Sub
See Also: Contents, Introduction, RasEntry, RasGetEntryProperties, RasSetEntryProperties, RasCountryInfo, RasErrorHandler.