Problem using API function GetExtendedTcpTable

M

Michael M.

Hi All I am trying to use the function GetExtendedTcpTable, I looked on the
MSDN found the C++ definition and tried to convert it but it does not seem
to be working, it returns 87 which is = ERROR_INVALID_PARAMETER

I have checked the parameters it looks correct to me.

Any IDEAS?

Imports System.Runtime.InteropServices

'* C++ Conversions Aliases.

Imports DWORD = System.UInt32

Imports BOOL = System.Boolean

Imports PDWORD = System.IntPtr

Imports CLONG = System.UInt32

Imports Pointer = System.IntPtr

Public Function GetTCPdata()

Dim MIB_TCPROW As New MIB_TCPROW_OWNER_PID

Dim AF_INET As Integer = 2 ' = IP version 4

Dim IptrToTableSize As IntPtr =
Marshal.AllocHGlobal(Marshal.SizeOf(GetType(System.UInt32)))

Dim RetVal As DWORD

'Get the Size of the TCP TABLE

RetVal = GetExtendedTcpTable(IntPtr.Zero, IptrToTableSize, 0, AF_INET, 5, 0)

Dim iptrToTcpTableArray As IntPtr

'Allocate space in the pointer

iptrToTcpTableArray = Marshal.AllocHGlobal(Marshal.SizeOf(IptrToTableSize))

' Trying to get a Pointer to the TCP table

RetVal = GetExtendedTcpTable(iptrToTcpTableArray, IptrToTableSize, 0,
AF_INET, 5, 0)

MessageBox.Show(RetVal.ToString & ", TCP Table Size " &
IptrToTableSize.ToString)

Marshal.FreeHGlobal(iptrToTcpTableArray)

Return 0

End Function

'*** API DECLARE ****

'C++ Original

'DWORD GetExtendedTcpTable(

' PVOID pTcpTable,

' PDWORD pdwSize,

' BOOL bOrder,

' ULONG ulAf,

' TCP_TABLE_CLASS TableClass,

' ULONG Reserved

');



'VB.net Conversion ?

Public Declare Unicode Function GetExtendedTcpTable Lib _

"IPHLPAPI.DLL" _

( _

ByVal pTcpTable As IntPtr, _

ByVal pDwSize As Integer, _

ByVal bOrder As BOOL, _

ByVal ulAf As Integer, _

ByVal TCP_TABLE_CLASS As Integer, _

ByVal Reserved As Integer) As Integer
 
M

Mattias Sjögren

'VB.net Conversion ?
Public Declare Unicode Function GetExtendedTcpTable Lib _

"IPHLPAPI.DLL" _

( _

ByVal pTcpTable As IntPtr, _

ByVal pDwSize As Integer, _

ByVal bOrder As BOOL, _

ByVal ulAf As Integer, _

ByVal TCP_TABLE_CLASS As Integer, _

ByVal Reserved As Integer) As Integer


pDwSize should be ByRef.


Mattias
 

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