Zwei Arrays vergleichen von UDF

  • Hi Leute,

    brauche bitte Hilfe, bekomme es einfach nicht hin.

    Möchte zwei ArrayVariablen aus dieser UDF vergleichen .

    Quelle

    Für eventuelle Hilfe Merci im voraus.

    ;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    ; Vergleiche $arr & $arr1 ob Änderung eingetreten ist, die Werte werden nicht benötigt, sondern nur ob eine Änderung eingetreten ist,deshalb wird ArrayDisplay nicht benötigt---> Siehe Spoiler

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    Spoiler anzeigen
    [autoit]


    #include <WinAPi.au3>
    #include <array.au3>
    Global Const $TH32CS_SNAPTHREAD = 0x00000004
    Global Const $THREADENTRY32 = "dword dwSize;dword cntUsage;dword th32ThreadId;dword th32OwnerProcessID;long tpBasePri;long tpDeltaPri;dword dwFlags;"

    [/autoit] [autoit][/autoit] [autoit]

    ;;; Example
    $pid = ProcessExists("MeinProgramm.exe")
    $arr=_GetAllProcessThreads($pid)
    sleep(5000)
    $arr1=_GetAllProcessThreads($pid)
    ;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ; Vergleiche $arr & $arr1 ob Änderung eingetreten ist, die Werte werden nicht benötigt,
    ;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ;_ArrayDisplay($arr)
    ; Get all threads in the system
    ;$arr=_GetAllThreads()
    ; And display them
    ;_ArrayDisplay($arr)

    [/autoit] [autoit][/autoit] [autoit]

    ;;; End of example

    [/autoit] [autoit][/autoit] [autoit]

    ;;;;;;;;;;;;_GetAllThreads;;;;;;;;;;;;;;;;;;;;
    ; Returns info of all the threads on the system
    ; Reterns a 2D array with the following structure:
    ;
    ; [n][0] = th32ThreadId - Thread ID
    ; [n][1] = th32OwnerProcessID - Pid of owener process
    ; [n][2] = tpBasePri - Priority of Thread (range 0-31)
    ;
    ; More info about the function:
    ;
    ; http://msdn.microsoft.com/en-us/library/ms682489(VS.85).aspx
    ; http://msdn.microsoft.com/en-us/library/ms686728(VS.85).aspx
    ; http://msdn.microsoft.com/en-us/library/ms686735(VS.85).aspx
    ;
    ; © monoceres 2008
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetAllThreads()
    $call = DllCall("Kernel32.dll", "ptr", "CreateToolhelp32Snapshot", "dword", $TH32CS_SNAPTHREAD, "dword", 0)
    $handle = $call[0]
    Local $RetArr[1][3]
    ;ConsoleWrite("Handle: " & $handle & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    $te32=DllStructCreate($THREADENTRY32)
    DllStructSetData($te32,"dwSize",DllStructGetSize($te32))
    $call=DllCall("Kernel32.dll","int","Thread32First","ptr",$handle,"ptr",DllStructGetPtr($te32))
    _GetAllThreads_ArrHelper($RetArr,$te32)
    Do
    $call=DllCall("Kernel32.dll","int","Thread32Next","ptr",$handle,"ptr",DllStructGetPtr($te32))
    If Not $call[0] Then ExitLoop
    _GetAllThreads_ArrHelper($RetArr,$te32)
    Until True And False
    _ArrayDelete($RetArr,0)
    _WinAPI_CloseHandle($handle)
    Return $RetArr
    EndFunc ;==>GetAllThreads
    ; Same as _GetAllThreads, but with a simple pid filter
    Func _GetAllProcessThreads($iPid)
    $call = DllCall("Kernel32.dll", "ptr", "CreateToolhelp32Snapshot", "dword", $TH32CS_SNAPTHREAD, "dword", 0)
    $handle = $call[0]
    Local $RetArr[1][3]
    ConsoleWrite("Handle: " & $handle & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    $te32=DllStructCreate($THREADENTRY32)
    DllStructSetData($te32,"dwSize",DllStructGetSize($te32))
    $call=DllCall("Kernel32.dll","int","Thread32First","ptr",$handle,"ptr",DllStructGetPtr($te32))
    If DllStructGetData($te32,"th32OwnerProcessID")=$iPid Then _GetAllThreads_ArrHelper($RetArr,$te32)
    Do
    $call=DllCall("Kernel32.dll","int","Thread32Next","ptr",$handle,"ptr",DllStructGetPtr($te32))
    If Not $call[0] Then ExitLoop
    If DllStructGetData($te32,"th32OwnerProcessID")=$iPid Then _GetAllThreads_ArrHelper($RetArr,$te32)
    Until True And False
    _ArrayDelete($RetArr,0)
    _WinAPI_CloseHandle($handle)
    Return $RetArr
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetAllThreads_ArrHelper(ByRef $Arr,$TE32_Struct)
    $ub=Ubound($Arr)
    ReDim $Arr[$ub+1][3]
    $Arr[$ub][0]=DllStructGetData($TE32_Struct,"th32ThreadId")
    ;$Arr[$ub][1]=DllStructGetData($TE32_Struct,"th32OwnerProcessID")
    ;$Arr[$ub][2]=DllStructGetData($TE32_Struct,"tpBasePri")
    EndFunc

    [/autoit]

    - MfG OpaEd

    • Offizieller Beitrag
    Spoiler anzeigen
    [autoit]

    #include <WinAPi.au3>
    #include <array.au3>
    Global Const $TH32CS_SNAPTHREAD = 0x00000004
    Global Const $THREADENTRY32 = "dword dwSize;dword cntUsage;dword th32ThreadId;dword th32OwnerProcessID;long tpBasePri;long tpDeltaPri;dword dwFlags;"

    [/autoit] [autoit][/autoit] [autoit]

    ;;; Example
    $pid = ProcessExists("MeinProgramm.exe")
    $arr = _GetAllProcessThreads($pid)
    Sleep(5000)
    $arr1 = _GetAllProcessThreads($pid)
    If $arr <> $arr1 Then
    MsgBox(0, "Info", "Array sind ungleich")
    Else
    MsgBox(0, "Info", "Array sind gleich")
    EndIf
    ;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ; Vergleiche $arr & $arr1 ob Änderung eingetreten ist, die Werte werden nicht benötigt,
    ;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ;_ArrayDisplay($arr)
    ; Get all threads in the system
    ;$arr=_GetAllThreads()
    ; And display them
    ;_ArrayDisplay($arr)

    [/autoit] [autoit][/autoit] [autoit]

    ;;; End of example

    [/autoit] [autoit][/autoit] [autoit]

    ;;;;;;;;;;;;_GetAllThreads;;;;;;;;;;;;;;;;;;;;
    ; Returns info of all the threads on the system
    ; Reterns a 2D array with the following structure:
    ;
    ; [n][0] = th32ThreadId - Thread ID
    ; [n][1] = th32OwnerProcessID - Pid of owener process
    ; [n][2] = tpBasePri - Priority of Thread (range 0-31)
    ;
    ; More info about the function:
    ;
    ; http://msdn.microsoft.com/en-us/library/ms682489(VS.85).aspx
    ; http://msdn.microsoft.com/en-us/library/ms686728(VS.85).aspx
    ; http://msdn.microsoft.com/en-us/library/ms686735(VS.85).aspx
    ;
    ; © monoceres 2008
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetAllThreads()
    $call = DllCall("Kernel32.dll", "ptr", "CreateToolhelp32Snapshot", "dword", $TH32CS_SNAPTHREAD, "dword", 0)
    $handle = $call[0]
    Local $RetArr[1][3]
    ;ConsoleWrite("Handle: " & $handle & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    $te32 = DllStructCreate($THREADENTRY32)
    DllStructSetData($te32, "dwSize", DllStructGetSize($te32))
    $call = DllCall("Kernel32.dll", "int", "Thread32First", "ptr", $handle, "ptr", DllStructGetPtr($te32))
    _GetAllThreads_ArrHelper($RetArr, $te32)
    Do
    $call = DllCall("Kernel32.dll", "int", "Thread32Next", "ptr", $handle, "ptr", DllStructGetPtr($te32))
    If Not $call[0] Then ExitLoop
    _GetAllThreads_ArrHelper($RetArr, $te32)
    Until True And False
    _ArrayDelete($RetArr, 0)
    _WinAPI_CloseHandle($handle)
    Return $RetArr
    EndFunc ;==>_GetAllThreads
    ; Same as _GetAllThreads, but with a simple pid filter
    Func _GetAllProcessThreads($iPid)
    $call = DllCall("Kernel32.dll", "ptr", "CreateToolhelp32Snapshot", "dword", $TH32CS_SNAPTHREAD, "dword", 0)
    $handle = $call[0]
    Local $RetArr[1][3]
    ConsoleWrite("Handle: " & $handle & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    $te32 = DllStructCreate($THREADENTRY32)
    DllStructSetData($te32, "dwSize", DllStructGetSize($te32))
    $call = DllCall("Kernel32.dll", "int", "Thread32First", "ptr", $handle, "ptr", DllStructGetPtr($te32))
    If DllStructGetData($te32, "th32OwnerProcessID") = $iPid Then _GetAllThreads_ArrHelper($RetArr, $te32)
    Do
    $call = DllCall("Kernel32.dll", "int", "Thread32Next", "ptr", $handle, "ptr", DllStructGetPtr($te32))
    If Not $call[0] Then ExitLoop
    If DllStructGetData($te32, "th32OwnerProcessID") = $iPid Then _GetAllThreads_ArrHelper($RetArr, $te32)
    Until True And False
    _ArrayDelete($RetArr, 0)
    _WinAPI_CloseHandle($handle)
    Return $RetArr
    EndFunc ;==>_GetAllProcessThreads

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetAllThreads_ArrHelper(ByRef $arr, $TE32_Struct)
    $ub = UBound($arr)
    ReDim $arr[$ub + 1][3]
    $arr[$ub][0] = DllStructGetData($TE32_Struct, "th32ThreadId")
    ;$Arr[$ub][1]=DllStructGetData($TE32_Struct,"th32OwnerProcessID")
    ;$Arr[$ub][2]=DllStructGetData($TE32_Struct,"tpBasePri")
    EndFunc ;==>_GetAllThreads_ArrHelper

    [/autoit]
  • Hi Raupi,
    das klappt so aber nicht, habe es auch mit den Vergleichsoperatoren versucht, das Ergebniss ist aber falsch.
    Mir ist noch was anderes aufgefallen. Mit dem Sleep nutzt mir die UDF nichts.
    Um die Threads zu ueberwachen musste ich das Script in einer weiteren Instanz starten und dann vergleichen :!:

    - MfG OpaEd