帮助将函数从C#转换为VB.net [英] Help Converting function from C# to VB.net
问题描述
我正在尝试从文章使用GetExtendedTcpTable函数获取活动的TCP/UDP连接中转换代码从C#到VB.net,到目前为止,除了将包含IP和PORT编号的二进制数据转换为可在VB.net中返回无效值的二进制数据的部分外,我已经完成了所有工作
它所做的只是读取包含IP的4个字节的信息和包含PORT的4个字节并创建IPEndPoint对象,但是在VB.net中它返回的无效值.
到目前为止,这就是我所得到的,有人可以帮助我确定代码的哪一部分不好吗?
Im trying to convert code from the article Getting the active TCP/UDP connections using the GetExtendedTcpTable function from C# to VB.net and so far i have everything worked out except for the part that converts the binary data containing the IP and PORT numbers which returns invalid values in VB.net
What it does it just read 4 bytes of information that contains the IP and the 4 bytes that contain the PORT and create a IPEndPoint Object, but in VB.net its returning invalid values.
So far, this is what i got, can someone help me and figure out which part of the code is bad?
public static IPEndPoint BufferToIPEndPoint(byte[] buffer, ref int nOffset, bool IsRemote)
{
//address
Int64 m_Address = ((((buffer[nOffset + 3] << 0x18) | (buffer[nOffset + 2] << 0x10)) | (buffer[nOffset + 1] << 8)) | buffer[nOffset]) & ((long)0xffffffff);
nOffset += 4;
int m_Port = 0;
m_Port = (IsRemote && (m_Address == 0))? 0 :
(((int)buffer[nOffset]) << 8) + (((int)buffer[nOffset + 1])) + (((int)buffer[nOffset + 2]) << 24) + (((int)buffer[nOffset + 3]) << 16);
nOffset += 4;
// store the remote endpoint
IPEndPoint temp = new IPEndPoint(m_Address, m_Port);
return temp;
}
Public Shared Function BufferToIPEndPoint(buffer As Byte(), ByRef nOffset As Integer, IsRemote As Boolean) As IPEndPoint
'address
Dim m_Address As Int64 = ((((buffer(nOffset + 3) << &H18) Or (buffer(nOffset + 2) << &H10)) Or (buffer(nOffset + 1) << 8)) Or buffer(nOffset)) And CLng(&HffffffffUI)
nOffset += 4
Dim m_Port As Integer = 0
m_Port = If((IsRemote AndAlso (m_Address = 0)), 0, (CInt(buffer(nOffset)) << 8) + CInt(buffer(nOffset + 1)) + (CInt(buffer(nOffset + 2)) << 24) + (CInt(buffer(nOffset + 3)) << 16))
nOffset += 4
' store the remote endpoint
Dim temp As New IPEndPoint(m_Address, m_Port)
Return temp
End Function
推荐答案
希望 GBVB-将VB.NET代码转换为C# [此 [^ ]会给您一个想法.
通过此操作,您可以根据需要进行更改.
Hope GBVB - Converting VB.NET code to C#[^] and this[^] will give you an idea.
From this you can change it as you like.
这篇关于帮助将函数从C#转换为VB.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!