Quick Vb6 To Vb.Net Conversion

J

Jm

Hi All

Ive asked this question in ms.public.dotnet.framework.interop but havent got
a reply so im hoping someone may be able to help here. I am a bit of a
newbie to vbnet and am having trouble using some code from
vb6 in vb.net. Im sure its pretty easy to convert but im just unsure of what
to do. This is the original code i would use

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(100) As MIB_TCPROW
End Type

Public MIB_TCPTABLE As MIB_TCPTABLE

Public Declare Function GetTcpTable Lib "iphlpapi.dll" (ByRef pTcpTable As
MIB_TCPTABLE, ByRef pdwSize As Long, ByVal bOrder As Long) As Long
Public Declare Function SetTcpEntry Lib "IPhlpAPI" (pTcpRow As MIB_TCPROW)
As Long
Public Declare Function ntohs Lib "WSOCK32.DLL" (ByVal netshort As Long) As
Long


Public Sub BlockPort(Port As String)


' Port Blocking Function


Dim LTmp As Long
Dim x As Integer, i As Integer, n As Integer
Dim RemP As String
Dim tcpt As MIB_TCPTABLE

LTmp = Len(MIB_TCPTABLE)
GetTcpTable tcpt, LTmp, 0
x = tcpt.dwNumEntries

For i = 0 To tcpt.dwNumEntries - 1

RemP = ntohs(tcpt.table(i).dwRemotePort)

If RemP = Port And tcpt.table(i).dwState <> 2 Then
tcpt.table(i).dwState = 12
SetTcpEntry tcpt.table(i)
End If

Next i

End Sub


From what ive learned so far types arent allowed as they were in vb6 and i
should be using structures now. But im unsure if i need to change anything
else. The code under vb6 was used on a timer to block tcp traffic on a
specified port. Is it possible to convert this code to be used in vb.net ?
Any help is greatly appreciated

Thanks
 
C

Cor Ligthert

Jm,

Mostly it is only that in VB6 what was long is now Integer in VBNet

Looking quick at your code did I not see anything else.

I hope this helps?

Cor
 
G

Guest

I don't know how to fix it, but it sound like a problem with the way .Net
stores arrays.

The problem is that in C, arrays are stored "in line", meaning that if you
declare an array of 10 items in a structure, then the structure has room for
10 copies of that item. VB.Net stores "references" in the array. The
difference is that the reference is only ONE item that points to where the
array is actually stored. What you need to be looking for is a way to
directly store the array elements in the array, rather than store pointers to
the elements.
 
K

Ken Tucker [MVP]

Hi,

Couple of quick things.

1) Windows firewall api if you are using xp service pack 2
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ics/ics/using_windows_firewall.asp

2)

Public structure MIB_TCPTABLE
dwNumEntries As Long
table() As MIB_TCPROW
End structure

Dim m as mib_tcptable

redim m.table(100)

Ken
--------------------
You fix Problem ?

I Need implement too this function.
Any can help me ?

From
http://developmentnow.com/g/38_2004_12_0_0_23025/Quick-Vb6-To-Vb-Net-Conversion.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
 
G

Guest

Hi,

Sorry should be.

Public structure MIB_TCPTABLE
dim dwNumEntries As integer
dim table() As MIB_TCPROW
End structure

Ken
 

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