Dim TcpRow As MIB_TCPROW
Dim buff() As Byte
Dim cbRequired As Long
Dim nStructSize As Long
Dim nRows As Long
Dim cnt As Long
Dim tmp As String
Dim itmx As ListItem
Call GetTcpTable(ByVal 0&, cbRequired, 1) *(請問高手,第一個引數應是一個table型結構,為什么是Byal 0&)
If cbRequired > 0 Then
ReDim buff(0 To cbRequired - 1) As Byte
If GetTcpTable(buff(0), cbRequired, 1) = ERROR_SUCCESS Then
'用下面的CopyMemory呼叫中的Lenb來保存資料
nStructSize = LenB(TcpRow)
'前4個位元組是一個長整形,指明了表的入口
CopyMemory nRows, buff(0), 4
For cnt = 1 To nRows
'移動到前面的4個位元組之后,提取相應資料,
'并將其轉換為TcpRow型別
CopyMemory TcpRow, buff(4 + (cnt - 1) * nStructSize), nStructSize* (這句沒看明白請高手指點)
'將結果填寫到串列視
With TcpRow
Set itmx = LvwTcpTable.ListItems.Add(, , GetInetStrFromPtr(.dwLocalAddr))
itmx.SubItems(1) = ntohs(.dwLocalPort)
itmx.SubItems(2) = GetInetStrFromPtr(.dwRemoteAddr)
itmx.SubItems(3) = ntohs(.dwRemotePort)
itmx.SubItems(4) = (.dwState)
'對于MIB_TCP_STATE_DELETE_TCB中的成員,
'MSDN只有一些說明性的定義
Select Case .dwState
Case MIB_TCP_STATE_CLOSED: tmp = "關閉"
Case MIB_TCP_STATE_LISTEN: tmp = "監聽"
Case MIB_TCP_STATE_SYN_SENT: tmp = "發送"
Case MIB_TCP_STATE_SYN_RCVD: tmp = "接受"
Case MIB_TCP_STATE_ESTAB: tmp = "建立連接"
Case MIB_TCP_STATE_FIN_WAIT1: tmp = "等待fin 1"
Case MIB_TCP_STATE_FIN_WAIT2: tmp = "等待fin 2"
Case MIB_TCP_STATE_CLOSE_WAIT: tmp = "關閉等待"
Case MIB_TCP_STATE_CLOSING: tmp = "正在關閉"
Case MIB_TCP_STATE_LAST_ACK: tmp = "最近的ack"
Case MIB_TCP_STATE_TIME_WAIT: tmp = "限時等待"
Case MIB_TCP_STATE_DELETE_TCB: tmp = "TCB被洗掉"
End Select
itmx.SubItems(5) = tmp
tmp = ""
End With
Next
End If
End If
End Sub
uj5u.com熱心網友回復:
GetTcpTable(buff(0), cbRequired, 1) = ERROR_SUCCESS 第一個引數為什么用buff(0)轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/102499.html
標籤:VB基礎類
