Probles with GetTcpTable, and structs with arrays members!

  • Thread starter Thread starter hateeee
  • Start date Start date
H

hateeee

Well.. i am really not understing almost nothing about apis in.net
first
i'd like to use GetTcpTable to get all active connections but it
didn't work by the way i used to code.
I found a sample which works, but it modify the structure, and do not
use MIB_TCPTABLE structure, but just MIB_TCPROW
its definitios are showed below:

Public Type MIB_TCPROW
dwState As Long
dwLocalAddr As Long
dwLocalPort As Long
dwRemoteAddr As Long
dwRemotePort As Long
End Type

Public Type MIB_TCPTABLE
dwNumEntries As Long
table(1600) As MIB_TCPROW
End Type

My questions: How to work with structures which have array members?
and i have other question:
How to declare a array, allocate memory for it, and assing this memory
to my array, for example, i was trying to do that:

Dim T () as integer
Dim Ptr as IntPtr=Marsal.AllocHGlobal(12) '3 elements
t=Ctype( marshal.PtrToStructure(Ptr, gettype(Array)), Array)

t(0)=123
t(1)=321
t(2)=222

but it actually doesn't work

PLEASEE I NEED MANY HELPPPP!!!!!

I wanna know how to use GetTcpTable and SetTcpEntry, i wanna know how
to allocate memomry for a array,...
 
My questions: How to work with structures which have array members?

Here are some general tips

http://www.dotnetinterop.com/faq/?q=StructWithStructArray

and i have other question:
How to declare a array, allocate memory for it, and assing this memory
to my array, for example, i was trying to do that:

Dim T () as integer
Dim Ptr as IntPtr=Marsal.AllocHGlobal(12) '3 elements
t=Ctype( marshal.PtrToStructure(Ptr, gettype(Array)), Array)

t(0)=123
t(1)=321
t(2)=222

You can't really do that, arrays are always allocated from the managed
heap. But you can copy the data to the unmanaged heap doing something
like this

Dim t(2) as integer
t(0)=123
t(1)=321
t(2)=222
Dim Ptr as IntPtr=Marsal.AllocHGlobal(12) '3 elements
Marshal.Copy(t, 0, Ptr, 3)



Mattias
 
Back
Top