Marshal vs2005 problem please help
-
Cannot marshal field 'table' of type 'MIB_TCPTABLE': Invalid managed/unmanaged type combination (Arrays fields must be paired with ByValArray or SafeArray). i got this error when trying to call function GetTcpTable.. see the following code.. [module declaration] Structure MIB_TCPROW Dim dwState As Long Dim dwLocalAddr As Long Dim dwLocalPort As Long Dim dwRemoteAddr As Long Dim dwRemotePort As Long End Structure Structure MIB_TCPTABLE Dim table() As MIB_TCPROW Dim dwNumEntries As Long End Structure Public v_MIB_TCPTABLE As MIB_TCPTABLE Declare Function GetTcpTable Lib "IPhlpAPI.dll" (ByVal pTcpTable As MIB_TCPTABLE, ByVal pdwSize As Long, ByVal bOrder As Long) As Long [form code] Dim tcpt As MIB_TCPTABLE Dim l As Long Dim x As Integer Dim i As Integer Dim RemA As String Dim LocP As String Dim RemP As String Dim state As Integer l = Len(v_MIB_TCPTABLE) GetTcpTable(tcpt, l, 0) x = tcpt.dwNumEntries after calling GetTcpTable function i got exeption as mention above please help
-
Cannot marshal field 'table' of type 'MIB_TCPTABLE': Invalid managed/unmanaged type combination (Arrays fields must be paired with ByValArray or SafeArray). i got this error when trying to call function GetTcpTable.. see the following code.. [module declaration] Structure MIB_TCPROW Dim dwState As Long Dim dwLocalAddr As Long Dim dwLocalPort As Long Dim dwRemoteAddr As Long Dim dwRemotePort As Long End Structure Structure MIB_TCPTABLE Dim table() As MIB_TCPROW Dim dwNumEntries As Long End Structure Public v_MIB_TCPTABLE As MIB_TCPTABLE Declare Function GetTcpTable Lib "IPhlpAPI.dll" (ByVal pTcpTable As MIB_TCPTABLE, ByVal pdwSize As Long, ByVal bOrder As Long) As Long [form code] Dim tcpt As MIB_TCPTABLE Dim l As Long Dim x As Integer Dim i As Integer Dim RemA As String Dim LocP As String Dim RemP As String Dim state As Integer l = Len(v_MIB_TCPTABLE) GetTcpTable(tcpt, l, 0) x = tcpt.dwNumEntries after calling GetTcpTable function i got exeption as mention above please help
It looks like you've found and are using an old VB6 definition of the structures, not compatibile with VB.NET. A 32-bit integer is called Integer in VB.NET, not Long. That was the old VB6 name for it. Long under VB.NET is a 64-bit integer. If you don't get this correct, you can imbalence the call stack. The function declaration should be this:
Declare Function Auto GetTcpTable Lib "IPhlpAPI.dll" ( _
ByVal pTcpTable As MIB_TCPTABLE, _
ByVal pdwSize As Integer, _
ByVal bOrder As Boolean) As IntegerDave Kreskowiak Microsoft MVP - Visual Basic