473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3772
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.