469,638 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,638 developers. It's quick & easy.

Quick Vb6 To Vb.Net Conversion

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

Nov 21 '05 #1
8 3587
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
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

Nov 21 '05 #2
Jm
Hi Cor

If i change all values referring to long to integer it leaves one problem
with the line

Public table(100) As MIB_TCPROW

Which is inside the MIB_TCPTABLE structure, which says ' Arrays declared as
structure members cannot be declared with an initial size'. I tried removing
the 100 and the code runs but it does not block the traffic, so im guessing
i need to put somewhere in the code the size that the table should be ?
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ul**************@TK2MSFTNGP12.phx.gbl...
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
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


Nov 21 '05 #3
JM,

Not my stuff, however I assume that this answer from Mattias helps you
directly.
http://groups-beta.google.com/group/...d7fa71006e4603

I hope this helps,

Cor
"Jm" <ja*****@ihug.com.au> schreef in bericht
news:cp**********@lust.ihug.co.nz...
Hi Cor

If i change all values referring to long to integer it leaves one problem
with the line

Public table(100) As MIB_TCPROW

Which is inside the MIB_TCPTABLE structure, which says ' Arrays declared
as
structure members cannot be declared with an initial size'. I tried
removing
the 100 and the code runs but it does not block the traffic, so im
guessing
i need to put somewhere in the code the size that the table should be ?
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ul**************@TK2MSFTNGP12.phx.gbl...
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
> 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
>
>
>



Nov 21 '05 #4
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.

"Jm" wrote:
Hi Cor

If i change all values referring to long to integer it leaves one problem
with the line

Public table(100) As MIB_TCPROW

Which is inside the MIB_TCPTABLE structure, which says ' Arrays declared as
structure members cannot be declared with an initial size'. I tried removing
the 100 and the code runs but it does not block the traffic, so im guessing
i need to put somewhere in the code the size that the table should be ?
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ul**************@TK2MSFTNGP12.phx.gbl...
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
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



Nov 21 '05 #5
Also, check out this site:

www.pinvoke.net.

They're all about calling API functions from .Net

"Jm" wrote:
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

Nov 21 '05 #6
You fix Problem ?

I Need implement too this function.
Any can help me

From http://developmentnow.com/g/38_2004_...-Conversion.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
Nov 21 '05 #7
Hi,

Couple of quick things.

1) Windows firewall api if you are using xp service pack 2
http://msdn.microsoft.com/library/de...s_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
--------------------
"Vitoto" <vi****@hotmail.com> wrote in message
news:97**********************************@msnews.m icrosoft.com...
You fix Problem ?

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

From
http://developmentnow.com/g/38_2004_...Conversion.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Nov 21 '05 #8
Hi,

Sorry should be.

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

Ken
-------------------

"Ken Tucker [MVP]" wrote:
Hi,

Couple of quick things.

1) Windows firewall api if you are using xp service pack 2
http://msdn.microsoft.com/library/de...s_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
--------------------
"Vitoto" <vi****@hotmail.com> wrote in message
news:97**********************************@msnews.m icrosoft.com...
You fix Problem ?

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

From
http://developmentnow.com/g/38_2004_...Conversion.htm

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

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.