Цитата:
Цитата saavaage
Попробовал так и результат =0 »
|
А что означает результат не 0? :) у меня и с предыдущими примерами результат 0. У меня вообще ругается в функций _WinAPI_GetIfTable.
Да и ещё, я не совсем понял, зачем закрывать Dll'ку когда она ещё используется?
И таймер насколько я понимаю не нужен, если используется AdlibRegister, то можно сразу время запуска указать:
Код:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#Include <ComboConstants.au3>
#Include <GUIComboBox.au3>
#Include <GUIConstantsEx.au3>
#Include <EditConstants.au3>
#Include <StaticConstants.au3>
Global Const $MIB_IF_TYPE_OTHER = 1
Global Const $MIB_IF_TYPE_ETHERNET_CSMACD = 6
Global Const $MIB_IF_TYPE_ISO88025_TOKENRING = 9
Global Const $MIB_IF_TYPE_PPP = 23
Global Const $MIB_IF_TYPE_SOFTWARE_LOOPBACK = 24
Global Const $MIB_IF_TYPE_ATM = 37
Global Const $MIB_IF_TYPE_IEEE80211 = 71
Global Const $MIB_IF_TYPE_TUNNEL = 131
Global Const $MIB_IF_TYPE_IEEE1394 = 144
Global Const $MIB_IF_ADMIN_STATUS_UP = 1
Global Const $MIB_IF_ADMIN_STATUS_DOWN = 2
Global Const $MIB_IF_ADMIN_STATUS_TESTING = 3
Global Const $MIB_IF_OPER_STATUS_NON_OPERATIONAL = 0
Global Const $MIB_IF_OPER_STATUS_UNREACHABLE = 1
Global Const $MIB_IF_OPER_STATUS_DISCONNECTED = 2
Global Const $MIB_IF_OPER_STATUS_CONNECTING = 3
Global Const $MIB_IF_OPER_STATUS_CONNECTED = 4
Global Const $MIB_IF_OPER_STATUS_OPERATIONAL = 5
Global Const $tagMIB_IFROW = 'wchar Name[256];dword Index;dword Type;dword Mtu;dword Speed;dword PhysAddrLen;byte PhysAddr[8];dword AdminStatus;dword OperStatus;dword LastChange;dword InOctets;dword InUcastPkts;dword InNUcastPkts;dword InDiscards;dword InErrors;dword InUnknownProtos;dword OutOctets;dword OutUcastPkts;dword OutNUcastPkts;dword OutDiscards;dword OutErrors;dword OutQLen;dword DescrLen;char Descr[256]'
Global $Dll, $Combo, $Label41, $Label42, $Data, $Index = 0, $Adapter[1][3] = [[0]]
Opt("GUIOnEventMode", 1)
$hMain_GUI = GUICreate("Диагностика и Настройка", 615, 440)
GUISetIcon('setupapi.dll', 1)
GUISetFont(8.5, 400, 0, 'MS Shell Dlg')
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Tab1 = GUICtrlCreateTab(8, 16, 601, 377)
;;;; Network ;;;;
$Network = GUICtrlCreateTabItem("Network")
;; интернет - адаптеры
$Dll = DllOpen(@SystemDir & '\IPHlpApi.dll')
$Data = _WinAPI_GetIfTable($MIB_IF_TYPE_ETHERNET_CSMACD, $Dll)
If Not @error Then
For $i = 1 To $Data[0][0]
$Adapter[0][0] += 1
ReDim $Adapter[$Adapter[0][0] + 1][3]
$Adapter[$Adapter[0][0]][0] = $Data[$i][1 ] ; Interface index
$Adapter[$Adapter[0][0]][2] = $Data[$i][19] ; Description
Next
EndIf
GUICtrlCreateGroup("Интернет-Адаптеры", 16, 288, 585, 97)
GUICtrlCreateLabel("Адаптер:", 32, 309, 49, 17)
$Combo = GUICtrlCreateCombo("", 88, 307,505, 25, $CBS_DROPDOWNLIST)
GUICtrlSetOnEvent($Combo, "_MainGUI_Events")
If $Adapter[0][0] Then
For $i = 1 To $Adapter[0][0]
_GUICtrlComboBox_AddString($Combo, $Adapter[$i][2])
Next
$Index = 1
Else
_GUICtrlComboBox_AddString($Combo, 'None')
GUICtrlSetState(-1, $GUI_DISABLE)
EndIf
_GUICtrlComboBox_SetCurSel($Combo, 0)
GUICtrlCreateGroup("Трансфер (Bytes + MB):", 24, 333, 569, 44)
GUICtrlCreateLabel("Отдача:", 34, 354, 43, 17)
$Label41 = GUICtrlCreateInput("", 87, 353, 81, 17, BitOR($ES_RIGHT, $ES_READONLY))
GUICtrlCreateInput("", 184, 353, 81, 17, BitOR($ES_RIGHT, $ES_READONLY))
GUICtrlCreateLabel("Прием:", 346, 354, 43, 17)
$Label42 = GUICtrlCreateInput("", 399, 353, 85, 17, BitOR($ES_RIGHT, $ES_READONLY))
GUICtrlCreateInput("", 496, 353, 81, 17, BitOR($ES_RIGHT, $ES_READONLY))
GUICtrlCreateTabItem("")
;;;; Common Buttons ;;;;
$nSettings_Button = GUICtrlCreateButton("Опции", 500, 7, 105, 25)
$nExit_Button = GUICtrlCreateButton("Выход", 535, 400, 70, 33)
GUICtrlSetOnEvent($nExit_Button, "_MainGUI_Events")
GUICtrlSetOnEvent($nSettings_Button, "_MainGUI_Events")
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainGUI_Events", $hMain_GUI)
_Combo()
AdlibRegister("_Combo", 1000)
GUISetState(@SW_SHOW, $hMain_GUI)
While 1
Sleep(100)
WEnd
Func CLOSEClicked()
Exit
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FUNCTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _MainGUI_Events()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE, $nExit_Button
Exit
Case $nSettings_Button
_Settings_GUI($hMain_GUI)
case $Combo
$Index = _GUICtrlComboBox_GetCurSel($Combo) + 1
EndSwitch
EndFunc
Func _Settings_GUI($hMain_GUI)
Local $iOpt_GOEM, $hSettings_GUI, $nStngs_Close_Button, $nStngs_Save_Button
$iOpt_GOEM = Opt("GUIOnEventMode", 0)
$hSettings_GUI = GUICreate("Настройки", 400, 250, -1, -1, -1, -1, $hMain_GUI)
$nStngs_Close_Button = GUICtrlCreateButton("Выход", 20, 220, 60, 20)
$nStngs_Save_Button = GUICtrlCreateButton("Сохранить", 90, 220, 60, 20)
GUISetState(@SW_DISABLE, $hMain_GUI)
GUISetState(@SW_SHOW, $hSettings_GUI)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $nStngs_Close_Button
ExitLoop
Case $nStngs_Save_Button
MsgBox(64, 'Сохранение настроек', 'Изменения сохранены!', 0, $hSettings_GUI)
EndSwitch
WEnd
GUISetState(@SW_ENABLE, $hMain_GUI)
GUISetState(@SW_HIDE, $hSettings_GUI)
Opt("GUIOnEventMode", $iOpt_GOEM)
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;; SECTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Network Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; определение текущего АДАПТЕРА и его sent/receive
Func _Combo()
If $Index Then
$Data = _WinAPI_GetIfEntry($Adapter[$Index][0], $Dll)
If Not @error Then
GUICtrlSetData($Label41, _Str($Data[14]) & ' bytes')
GUICtrlSetData($Label42, _Str($Data[8 ]) & ' bytes')
GUICtrlSetData($Label41 + 1, StringFormat('%.2f', $Data[14] / 1024 / 1024) & ' MB')
GUICtrlSetData($Label42 + 1, StringFormat('%.2f', $Data[8 ] / 1024 / 1024) & ' MB')
Else
GUICtrlSetData($Label41, '')
GUICtrlSetData($Label42, '')
EndIf
EndIf
EndFunc
Func _Str($iValue)
Local $Result = '', $Str = String($iValue)
While StringLen($Str)
$Result = '.' & StringRight($Str, 3) & $Result
$Str = StringTrimRight($Str, 3)
WEnd
Return StringTrimLeft($Result, 1)
EndFunc ;==>_Str
Func _WinAPI_GetIfEntry($iIndex, $Dll = -1)
Local $Ret, $Data, $Addr, $Count
Local $tMIB_IFROW
If $Dll < 0 Then
$Dll = 'IPHlpApi.dll'
EndIf
$tMIB_IFROW = DllStructCreate($tagMIB_IFROW)
DllStructSetData($tMIB_IFROW, 2, $iIndex)
$Ret = DLLCall($Dll, 'dword', 'GetIfEntry', 'ptr', DllStructGetPtr($tMIB_IFROW))
If @error Then
Return SetError(1, 0, 0)
EndIf
Dim $Data[20]
$Data[0 ] = DllStructGetData($tMIB_IFROW, 'Name')
$Data[1 ] = $iIndex
$Data[2 ] = DllStructGetData($tMIB_IFROW, 'Type')
$Data[3 ] = DllStructGetData($tMIB_IFROW, 'Mtu')
$Data[4 ] = DllStructGetData($tMIB_IFROW, 'Speed')
$Count = DllStructGetData($tMIB_IFROW, 'PhysAddrLen')
$Addr = ''
For $i = 1 To $Count
$Addr &= Hex(DllStructGetData($tMIB_IFROW, 'PhysAddr', $i), 2) & '-'
Next
$Data[5 ] = StringTrimRight($Addr, 1)
$Data[6 ] = DllStructGetData($tMIB_IFROW, 'AdminStatus')
$Data[7 ] = DllStructGetData($tMIB_IFROW, 'OperStatus')
$Data[8 ] = DllStructGetData($tMIB_IFROW, 'InOctets')
$Data[9 ] = DllStructGetData($tMIB_IFROW, 'InUcastPkts')
$Data[10] = DllStructGetData($tMIB_IFROW, 'InNUcastPkts')
$Data[11] = DllStructGetData($tMIB_IFROW, 'InDiscards')
$Data[12] = DllStructGetData($tMIB_IFROW, 'InErrors')
$Data[13] = DllStructGetData($tMIB_IFROW, 'InUnknownProtos')
$Data[14] = DllStructGetData($tMIB_IFROW, 'OutOctets')
$Data[15] = DllStructGetData($tMIB_IFROW, 'OutUcastPkts')
$Data[16] = DllStructGetData($tMIB_IFROW, 'OutNUcastPkts')
$Data[17] = DllStructGetData($tMIB_IFROW, 'OutDiscards')
$Data[18] = DllStructGetData($tMIB_IFROW, 'OutErrors')
$Data[19] = StringLeft(DllStructGetData($tMIB_IFROW, 'Descr'), DllStructGetData($tMIB_IFROW, 'DescrLen') - 1)
Return $Data
EndFunc ;==>_WinAPI_GetIfEntry
Func _WinAPI_GetIfTable($iType = 0, $Dll = -1)
Local $Ret, $Row, $Type, $Tag, $Tab, $Addr, $Count, $Lenght
Local $tMIB_IFTABLE, $tMIB_IFROW
If $Dll < 0 Then
$Dll = 'IPHlpApi.dll'
EndIf
$tMIB_IFROW = DllStructCreate($tagMIB_IFROW)
$Row = 'byte[' & DllStructGetSize($tMIB_IFROW) & ']'
$Tag = 'dword;'
For $i = 1 To 32
$Tag &= $Row & ';'
Next
$tMIB_IFTABLE = DllStructCreate($Tag)
$Ret = DLLCall($Dll, 'dword', 'GetIfTable', 'ptr', DllStructGetPtr($tMIB_IFTABLE), 'long*', DllStructGetSize($tMIB_IFTABLE), 'int', 1)
If @error Then
Return SetError(1, 0, 0)
EndIf
$Count = DllStructGetData($tMIB_IFTABLE, 1)
Dim $Tab[$Count + 1][20]
$Tab[0][0] = 0
For $i = 1 To $Count
$tMIB_IFROW = DllStructCreate($tagMIB_IFROW, DllStructGetPtr($tMIB_IFTABLE, $i + 1))
$Type = DllStructGetData($tMIB_IFROW, 'Type')
If ($iType = 0) Or ($iType = $Type) Then
$Tab[0][0] += 1
$Tab[$Tab[0][0]][0 ] = DllStructGetData($tMIB_IFROW, 'Name')
$Tab[$Tab[0][0]][1 ] = DllStructGetData($tMIB_IFROW, 'Index')
$Tab[$Tab[0][0]][2 ] = $Type
$Tab[$Tab[0][0]][3 ] = DllStructGetData($tMIB_IFROW, 'Mtu')
$Tab[$Tab[0][0]][4 ] = DllStructGetData($tMIB_IFROW, 'Speed')
$Lenght = DllStructGetData($tMIB_IFROW, 'PhysAddrLen')
$Addr = ''
For $j = 1 To $Lenght
$Addr &= Hex(DllStructGetData($tMIB_IFROW, 'PhysAddr', $j), 2) & '-'
Next
$Tab[$Tab[0][0]][5 ] = StringTrimRight($Addr, 1)
$Tab[$Tab[0][0]][6 ] = DllStructGetData($tMIB_IFROW, 'AdminStatus')
$Tab[$Tab[0][0]][7 ] = DllStructGetData($tMIB_IFROW, 'OperStatus')
$Tab[$Tab[0][0]][8 ] = DllStructGetData($tMIB_IFROW, 'InOctets')
$Tab[$Tab[0][0]][9 ] = DllStructGetData($tMIB_IFROW, 'InUcastPkts')
$Tab[$Tab[0][0]][10] = DllStructGetData($tMIB_IFROW, 'InNUcastPkts')
$Tab[$Tab[0][0]][11] = DllStructGetData($tMIB_IFROW, 'InDiscards')
$Tab[$Tab[0][0]][12] = DllStructGetData($tMIB_IFROW, 'InErrors')
$Tab[$Tab[0][0]][13] = DllStructGetData($tMIB_IFROW, 'InUnknownProtos')
$Tab[$Tab[0][0]][14] = DllStructGetData($tMIB_IFROW, 'OutOctets')
$Tab[$Tab[0][0]][15] = DllStructGetData($tMIB_IFROW, 'OutUcastPkts')
$Tab[$Tab[0][0]][16] = DllStructGetData($tMIB_IFROW, 'OutNUcastPkts')
$Tab[$Tab[0][0]][17] = DllStructGetData($tMIB_IFROW, 'OutDiscards')
$Tab[$Tab[0][0]][18] = DllStructGetData($tMIB_IFROW, 'OutErrors')
$Tab[$Tab[0][0]][19] = StringLeft(DllStructGetData($tMIB_IFROW, 'Descr'), DllStructGetData($tMIB_IFROW, 'DescrLen') - 1)
EndIf
Next
If $Tab[0][0] < $Count Then
ReDim $Tab[$Tab[0][0] + 1][20]
EndIf
Return $Tab
EndFunc ;==>_WinAPI_GetIfTable
;; конец определение текущего адаптера и его sent/receive
;; End Network Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|