飘云 发表于 2011-5-1 16:10:50

关于函数GetIfTable的使用[已解决]

本帖最后由 飘云 于 2011-5-1 17:46 编辑

在vb中只要
Private Type MIB_IFTABLE
    dwNumEntries As Long
    MIB_Table(9) As MIB_IFROW
End Type
这样就定义了MIB_IFTABLE数据结构,然后
Dim ifT As MIB_IFTABLE
LenIfT = Len(ifT)
RValue = GetIfTable(ifT, LenIfT, True)
之后,ifT.dwNumEntries就有结果了,在au3中该怎么写以便获取dwNumEntries的值呢?
试着写了下
$MIB_IFROW = DllStructCreate("wchar wszName;dword dwIndex;dword dwType;dword dwMtu;dword dwSpeed;dword dwPhysAddrLen;char bPhysAddr;dword dwAdminStatus;dword dwOperStatus;dword dwLastChange;dword dwInOctets;dword dwInUcastPkts;dword dwInNUcastPkts;dword dwInDiscards;dword dwInErrors;dword dwInUnknownProtos;dword dwOutOctets;dword dwOutUcastPkts;dword dwOutNUcastPkts;dword dwOutDiscards;dword dwOutErrors;dword dwOutQLen;dword dwDescrLen;char bDescr")
$MIB_IFTABLE = DllStructCreate("dword;ptr")
DllStructSetData($MIB_IFTABLE,2,DllStructGetPtr($MIB_IFROW))
DllCall("iphlpapi.dll","dword","GetIfTable","ptr",DllStructGetPtr($MIB_IFTABLE),"dword",DllStructGetSize($MIB_IFTABLE),"BOOL",1)
MsgBox(0,"",DllStructGetData($MIB_IFTABLE,1))
但是以上代码一运行编译器就报错

ceoguang 发表于 2011-5-1 17:10:47

$size = DllCall("iphlpapi.dll", "dword", "GetIfTable", "ptr", 0, "ulong*", 0, "bool", 1)
$size = $size
$tBuffer = DllStructCreate("ubyte[" & $size & "]")

$ret = DllCall("iphlpapi.dll", "dword", "GetIfTable", "ptr", DllStructGetPtr($tBuffer), "ulong*", DllStructGetSize($tBuffer), "bool", 1)
MsgBox(0,0,DllStructGetData(DllStructCreate("dword", DllStructGetPtr($tBuffer)), 1))

飘云 发表于 2011-5-1 17:37:50

回复 2# ceoguang


    不愧是版主,原来如此,原来是先调用获得返回值,然后再创建结构啊,汗
页: [1]
查看完整版本: 关于函数GetIfTable的使用[已解决]