| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1766 人关注过本帖
标题:VBCopyMemory下标越界
取消只看楼主 加入收藏
leziyi
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2016-10-30
结帖率:85.71%
收藏
已结贴  问题点数:20 回复次数:2 
VBCopyMemory下标越界
Private Sub GetTCPDatas()

   

  Dim TcpRow     As MIB_TCPROW

  Dim Buffer()     As Byte

  Dim LngRequired     As Long

  Dim LngStructureSize     As Long

  Dim LngRows     As Long

  Dim LngCounter     As Long

  Dim strTemps     As String

  Dim ListX     As ListItem

   

  LvwTcpTable.ListItems.Clear

  Call GetTcpTable(ByVal 0&, LngRequired, 1)

   

  If LngRequired > 0 Then

          ReDim Buffer(0 To LngRequired - 1) As Byte

          If GetTcpTable(Buffer(0), LngRequired, 1) = ERROR_SUCCESS Then

                  LngStructureSize = LenB(TcpRow)

   

                  '起始的四个字节,是做为表示进入点的数字

                  CopyMemory LngRows, Buffer(0), 4

                  For LngCounter = 1 To LngRows

   

                          '   将上述获得四个字节的相关数据,拷贝到   TcpRow   的结构之中

                          CopyMemory TcpRow, Buffer(4 + (LngCounter - 1) * LngStructureSize), LngStructureSize

                           

                          '   将结果传送到   ListView   之中

                          With TcpRow

                                  Set ListX = LvwTcpTable.ListItems.Add(, , GetInetAddrStr(.dwLocalAddr))
                                 
                                  ListX.SubItems(1) = .dwOwningPid

                                  ListX.SubItems(2) = ntohs(.dwLocalPort)

                                  ListX.SubItems(3) = GetInetAddrStr(.dwRemoteAddr)

                                  ListX.SubItems(4) = ntohs(.dwRemotePort)
                                 
                                  ListX.SubItems(5) = (.dwState)

                                  Select Case .dwState

                                          Case MIB_TCP_STATE_CLOSE_WAIT:         strTemps = "结束等待"

                                          Case MIB_TCP_STATE_CLOSED:                 strTemps = "已结束"

                                          Case MIB_TCP_STATE_CLOSING:               strTemps = "结束中..."

                                          Case MIB_TCP_STATE_DELETE_TCB:         strTemps = "已删除TCB"

                                          Case MIB_TCP_STATE_ESTAB:                   strTemps = "已连接"

                                          Case MIB_TCP_STATE_FIN_WAIT1:           strTemps = "FIN延时处理1"

                                          Case MIB_TCP_STATE_FIN_WAIT2:           strTemps = "FIN延时处理2"

                                          Case MIB_TCP_STATE_LAST_ACK:             strTemps = "上次取得的确认信号"

                                          Case MIB_TCP_STATE_LISTEN:                 strTemps = "监听中..."

                                          Case MIB_TCP_STATE_SYN_SENT:             strTemps = "传送"

                                          Case MIB_TCP_STATE_SYN_RCVD:             strTemps = "数据接收中"

                                          Case MIB_TCP_STATE_TIME_WAIT:           strTemps = "等候中..."

                                  End Select

                                  ListX.SubItems(5) = ListX.SubItems(4) & "(" & strTemps & ")"

                                  strTemps = ""

                          End With

                    

                  Next

            

          End If

  End If

  End Sub
搜索更多相关主题的帖子: Dim Buffer If Case End 
2018-12-13 19:08
leziyi
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2016-10-30
收藏
得分:0 
'   将上述获得四个字节的相关数据,拷贝到   TcpRow   的结构之中

                          CopyMemory TcpRow, Buffer(4 + (LngCounter - 1) * LngStructureSize), LngStructureSize-----------------------------错误行
2018-12-13 19:08
leziyi
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2016-10-30
收藏
得分:0 
那为什么这段代码在别的程序里又能运行
2018-12-14 13:35
快速回复:VBCopyMemory下标越界
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027211 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved