The RasGetProjectionInfo can be used to get various projection info structures for a given connection, such as IP addresses etc. The function looks like this:
Declare Function RasGetProjectionInfo _
Lib "rasapi32.dll" Alias "RasGetProjectionInfoA" _
(ByVal hRasConn As Long, _
ByVal rasProjectionType As Long, _
lpProjection As Any, _
lpcb As Long) As Long
Because the lpProjection parameter can be one of six very different types of structures, it's propably easier in VB to make six different wrapper functions, one for each protocol or projection type.
The following samples all require the handle to a connection. You can get the connection's handle using RasDial or RasEnumConnections.
You will also need the Declares Section from the end of this page.
Each function returns a long value that is zero on success. If the function fails (non-zero return value) then you can use the VBRasErrorHandler function to get a descriptive string.
The RASAMB projection info describes the result of a RAS AMB (Authentication Message Block) projection. This protocol is used with NT 3.1 and OS/2 1.3 downlevel RAS servers.
'VB "friendly" RASAMB structure.
Type VBRASAMB
dwError As Long
sNetBiosError As String
bLana As Byte
End Type
'___________________________________________________________
Function VBRasGetRASAMB(hRasConn As Long, _
udtVBRASAMB As VBRASAMB) As Long
Dim b() As Byte, rtn As Long, lpcb As Long
lpcb = 28&
ReDim b(lpcb - 1)
CopyMemory b(0), lpcb, 4
rtn = RasGetProjectionInfo(hRasConn, &H10000&, b(0), lpcb)
VBRasGetRASAMB = rtn
If rtn <> 0 Then Exit Function
With udtVBRASAMB
CopyMemory .dwError, b(4), 4
CopyByteToTrimmedString .sNetBiosError, b(8), 17
CopyMemory .bLana, b(25), 1
End With
End Function
The RASPPPNBF projection info describes the result of a PPP NBF (NetBEUI) projection.
'VB "friendly" RASPPPNBF structure.
Type RASPPPNBF
dwError As Long
dwNetBiosError As Long
szNetBiosError As String
szWorkstationName As String
bLana As Byte
End Type
'___________________________________________________________
Function VBRasGetRASPPPNBF(hRasConn As Long, _
udtVBRASPPPNBF As VBRASPPPNBF) As Long
Dim b() As Byte, rtn As Long, lpcb As Long
lpcb = 48&
ReDim b(lpcb - 1)
CopyMemory b(0), lpcb, 4
rtn = RasGetProjectionInfo(hRasConn, &H803F&, b(0), lpcb)
VBRasGetRASPPPNBF = rtn
If rtn <> 0 Then Exit Function
With udtVBRASPPPNBF
CopyMemory .dwError, b(4), 4
CopyMemory .dwNetBiosError, b(8), 4
CopyByteToTrimmedString .szNetBiosError, b(12), 17
CopyByteToTrimmedString .szWorkstationName, b(29), 17
CopyMemory .bLana, b(46), 1
End With
End Function
The RASPPPIPX projection info describes the results of a PPP IPX (Internetwork Packet Exchange) projection.
'VB "friendly" RASPPPIPX structure.
Type VBRASPPPIPX
dwError As Long
szIpxAddress As String
End Type
'___________________________________________________________
Function VBRasGetRASPPPIPX(hRasConn As Long, _
udtVBRASPPPIPX As VBRASPPPIPX) As Long
Dim b() As Byte, rtn As Long, lpcb As Long
lpcb = 24&
ReDim b(lpcb - 1)
CopyMemory b(0), lpcb, 4
rtn = RasGetProjectionInfo(hRasConn, &H802B&, b(0), lpcb)
VBRasGetRASPPPIPX = rtn
If rtn <> 0 Then Exit Function
With udtVBRASPPPIPX
CopyMemory .dwError, b(4), 4
CopyByteToTrimmedString .szIpxAddress, b(8), 16
End With
End Function
The RASPPPIP projection info describes the results of a PPP IP (Internet) projection.
'VB "friendly" RASPPPIP structure.
Type VBRASPPPIP
dwError As Long
szIpAddress As String
szServerIpAddress As String
End Type
'___________________________________________________________
Function VBRasGetRASPPPIP(hRasConn As Long, _
udtVBRASPPPIP As VBRASPPPIP) As Long
Dim b() As Byte, rtn As Long, lpcb As Long
lpcb = 40&
ReDim b(lpcb - 1)
CopyMemory b(0), lpcb, 4
rtn = RasGetProjectionInfo(hRasConn, &H8021&, b(0), lpcb)
VBRasGetRASPPPIP = rtn
If rtn <> 0 Then Exit Function
With udtVBRASPPPIP
CopyMemory .dwError, b(4), 4
CopyByteToTrimmedString .szIpAddress, b(8), 16
CopyByteToTrimmedString .szServerIpAddress, b(24), 16
End With
End Function
The RASAMB projection info describes the results of a SLIP (Serial Line IP) projection
'VB "friendly" RASSLIP structure.
Type VBRASSLIP
dwError As Long
szIpAddress As String
End Type
'___________________________________________________________
Function VBRasGetRASSLIP(hRasConn As Long, _
udtVBRASSLIP As VBRASSLIP) As Long
Dim b() As Byte, rtn As Long, lpcb As Long
lpcb = 24&
ReDim b(lpcb - 1)
CopyMemory b(0), lpcb, 4
rtn = RasGetProjectionInfo(hRasConn, &H20000&, b(0), lpcb)
VBRasGetRASSLIP = rtn
If rtn <> 0 Then Exit Function
With udtVBRASSLIP
CopyMemory .dwError, b(4), 4
CopyByteToTrimmedString .szIpAddress, b(8), 16
End With
End Function
Declare Function RasGetProjectionInfo _
Lib "rasapi32.dll" Alias "RasGetProjectionInfoA" _
(ByVal hRasConn As Long, _
ByVal rasProjectionType As Long, _
lpProjection As Any, _
lpcb As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
' helper 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, RasDial, RasEnumConnections, VBRasErrorHandler.