Translating code from VB6

Z

zurg

Hi!
I translated code from VB6 (worked there) to VB.Net and not it doesn't
work...
It has problems with RasEnumConnections function...
Probably I have to add initialize but how should it look like?
I tried

tInfo.Initialize

but still not working....


Please help!!!

That's code from VB6:
-----------------------------------
Option Explicit

Public Declare Function RasEnumConnections Lib "rasapi32.dll" Alias
"RasEnumConnectionsA" (ByRef lpRasCon As RASCONN, ByRef lpcb As Long, ByRef
lpNumConnections As Long) As Long
Public Declare Function RasHangUp Lib "rasapi32.dll" Alias "RasHangUpA"
(ByVal hRasConn As Long) As Long

Public Type RASCONN
dwSize As Long
hRasConn As Long
szEntryName(256) As Byte
szDeviceType(16) As Byte
szDeviceName(129) As Byte
End Type

Sub Main()
Dim tInfo(10) As RASCONN
Dim lSize As Long
Dim lTotal As Long

tInfo(0).dwSize = Len(tInfo(0))
lSize = tInfo(0).dwSize * 10

If RasEnumConnections(tInfo(0), lSize, lTotal) <> 0 Then
MsgBox ("Error during enumeration atempt")
Else
Dim iCurrent As Long
MsgBox (Str(lTotal) + " active RAS connections were found")

For iCurrent = 0 To lTotal - 1
If RasHangUp(tInfo(iCurrent).hRasConn) Then
MsgBox ("Failed to diconnect one of the Ras connections")
Else
MsgBox ("One of the RAS connection was disconnected")
End If
Next
End If
End Sub
--------------------------
And after translation to VB.Net

Option Strict Off

Option Explicit On

Module Module1


'UPGRADE_WARNING: Structure RASCONN may require marshalling attributes to be
passed as an argument in this Declare statement. Click for more:
'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1050"'

Public Declare Function RasEnumConnections Lib "rasapi32.dll" Alias
"RasEnumConnectionsA"(ByRef lpRasCon As RASCONN, ByRef lpcb As Integer,
ByRef lpNumConnections As Integer) As Integer

Public Declare Function RasHangUp Lib "rasapi32.dll" Alias
"RasHangUpA"(ByVal hRasConn As Integer) As Integer


Public Structure RASCONN

Dim dwSize As Integer

Dim hRasConn As Integer

<VBFixedArray(256)> Dim szEntryName() As Byte

<VBFixedArray(16)> Dim szDeviceType() As Byte

<VBFixedArray(129)> Dim szDeviceName() As Byte


'UPGRADE_TODO: "Initialize" must be called to initialize instances of this
structure. Click for more:
'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1026"'

Public Sub Initialize()

ReDim szEntryName(256)

ReDim szDeviceType(16)

ReDim szDeviceName(129)

End Sub

End Structure


Public Sub Main()

'UPGRADE_WARNING: Array tInfo may need to have individual elements
initialized. Click for more:
'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1042"'

Dim tInfo(10) As RASCONN

Dim lSize As Integer

Dim lTotal As Integer

Dim iCurrent As Integer


tInfo(0).dwSize = Len(tInfo(0))

lSize = tInfo(0).dwSize * 10


If RasEnumConnections(tInfo(0), lSize, lTotal) <> 0 Then

MsgBox("Error during enumeration atempt")

Else

MsgBox (Str(lTotal) + " active RAS connections were found")
For iCurrent = 0 To lTotal - 1

If RasHangUp(tInfo(iCurrent).hRasConn) Then

MsgBox ("Failed to diconnect one of the
Ras connections")
Else

MsgBox ("One of the RAS connection was
disconnected")
End If

Next

End If

End Sub

End Module
 
K

Ken Tucker [MVP]

Hi,

How to initialize tInfo.
Dim x As Integer

For x = 0 To 10

tInfo(x).Initialize()

Next

Ken

--------------------------------
 
Z

zurg

Thanks, that helped...

But I get an error when it has to run RasEnumConnections function:
An unhandled exception of type 'System.TypeLoadException' occurred in
RASGuard.exe

Additional information: Can not marshal field szEntryName of type RASCONN:
This type can not be marshaled as a structure field.

I have no idea what to do...
Once again - help!
zurg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top