none
GetTcpTable 問題 RRS feed

  • 問題

  • Option Explicit
    Private Type MIB_TCPROW ' TCP連接表中一行的結構
    dwState As Long ' 狀態
    dwLocalAddr As Long ' Local IP
    dwLocalPort As Long ' Local port
    dwRemoteAddr As Long ' Remote IP
    dwRemotePort As Long ' Remote port
    End Type
    Private Type MIB_TCPTABLE
    dwNum_Of_Entries As Long ' 當前 TCP連接的總數
    TCP_Table(120) As MIB_TCPROW ' 預留了120行的緩衝區
    End Type
    Private Declare Function GetTcpTable Lib "iphlpapi.dll" (ByRef pTcpTable _
    As MIB_TCPTABLE, ByRef pdwSize As Long, ByVal bOrder As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef _
    pDest As Any, ByRef pSource As Any, ByVal Length As Long)
    Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Private Declare Function GetWindowsDirectory Lib "kernel32" Alias _
    "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    Private Declare Function SetTcpEntry Lib "iphlpapi.dll" (ByRef pTcpTable _
    As MIB_TCPROW) As Long
    Dim Last_Num_Of_Entries As Long
    Dim TCPt As MIB_TCPTABLE

    Private Sub Command1_Click()
    Dim o
    o = GetTcpTable(TCPt, Len(TCPt), 1)
    MsgBox o
    MsgBox TCPt.dwNum_Of_Entries

    End Sub


    要取得TCP連接的總數 在XP中都正常 在WIN2003中 有一台正常有一台卻取不到
    o = GetTcpTable(TCPt, Len(TCPt), 1) 返回122
    TCPt.dwNum_Of_Entries 返回0
    不知問題出在哪裡
    A win2003 沒有使用分享器
    B win2003 有使用分享器
    2003版本都一樣 都有灌NOD32 與 Outpost PRO

    會是因該分享器的關係嗎 如果是有辦法解決嗎

    2009年10月16日 下午 04:28

解答

  • 非零值表示有錯誤,122 是 0x00000007a,它的意思是:

    ERROR_INSUFFICIENT_BUFFER(傳遞給系統的緩衝區大小不足)

    The buffer pointed to by the pTcpTable parameter is not large enough. The required size is returned in the DWORD variable pointed to by the pdwSize parameter.

    This error is also returned if the pTcpTable parameter is NULL.


    初學不是問題,但用不正確的態度來問問題,那就是很大的問題。
    如果只會用 "看" 的學程式,那不如早點改行,以免誤己一生...
    若不想快點得到解答,可以儘量把問題寫模糊一點,愈模糊愈不會得到解答。
    • 已標示為解答 chken 2009年10月17日 上午 07:43
    2009年10月17日 上午 12:49
    版主