Problem mit UDF

  • Hey Leute,
    ich hab ein Problem mit dem UDF Timers.au3. ICh brauche dieses Include für die Funktion: _Timer_SetTimer.
    Ich kenne mich mit UDFs nicht aus. Die sind mir zu schwer. Auf jedenfall sagt mein SciTe folgendes:

    C:\Programme\AutoIt3\Include\Timers.au3 (282) : ==> Badly formatted "Func" statement.:
    $hCallBack = DllCallbackRegister($sTimerFunc, "none", "hwnd;int;int;dword")

    Danke

    Manlius

  • Sry, aber meine Hellseherin hat Urlaub!

    [autoit]

    If Not $code = "gegeben" Then $Loesung = "Weit entfernt"

    [/autoit]

    MfG. tobi_girst

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »tobi_girst« (Morgen, 25:63)

  • Das Timers UDF sieht so aus:

    Spoiler anzeigen
    [autoit]

    #include-once

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

    ; #INDEX# =======================================================================================================================
    ; Title .........: Timers
    ; AutoIt Version: 3.2.3++
    ; Language: English
    ; Description ...: An application uses a timer to schedule an event for a window after a specified time has elapsed.
    ; Each time the specified interval (or time-out value) for a timer elapses, the system notifies the window
    ; associated with the timer. Because a timer's accuracy depends on the system clock rate and how often the
    ; application retrieves messages from the message queue, the time-out value is only approximate.
    ; Author ........: Gary Frost
    ; ===============================================================================================================================

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

    ; #VARIABLES# ===================================================================================================================
    Global $_Timers_aTimerIDs[1][3]
    ; ===============================================================================================================================

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

    ; ===============================================================================================================================
    ; #CURRENT# =====================================================================================================================
    ;_Timer_Diff
    ;_Timer_GetIdleTime
    ;_Timer_GetTimerID
    ;_Timer_Init
    ;_Timer_KillAllTimers
    ;_Timer_KillTimer
    ;_Timer_SetTimer
    ; ===============================================================================================================================

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

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ;_Timer_QueryPerformanceCounter
    ;_Timer_QueryPerformanceFrequency
    ; ===============================================================================================================================

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _Timer_Diff
    ; Description ...: Returns the difference in time from a previous call to _Timer_Init
    ; Syntax.........: _Timer_Diff($iTimeStamp)
    ; Parameters ....: $iTimeStamp - Timestamp returned from a previous call to _Timer_Init().
    ; Return values .: Success - Returns the time difference (in milliseconds) from a previous call to _Timer_Init().
    ; Author ........: Gary Frost, original by Toady
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: _Timer_Diff
    ; Link ..........;
    ; Example .......; Yes
    ; ===============================================================================================================================
    Func _Timer_Diff($iTimeStamp)
    Return 1000 * (_Timer_QueryPerformanceCounter() - $iTimeStamp) / _Timer_QueryPerformanceFrequency()
    EndFunc ;==>_Timer_Diff

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

    ; #FUNCTION#;===============================================================================
    ; Name...........: _Timer_GetIdleTime
    ; Description ...: Returns the number of ticks since last user activity (i.e. KYBD/Mouse)
    ; Syntax.........: _Timer_GetIdleTime()
    ; Parameters ....: None
    ; Return values .: Success - integer ticks since last (approx. milliseconds) since last activity
    ; Failure - Sets @extended = 1 if rollover occurs (see remarks)
    ; Author ........: PsaltyDS at http://www.autoitscript.com/forum
    ; Modified.......:
    ; Remarks .......: The current ticks since last system restart will roll over to 0 every 50 days or so,
    ; which makes it possible for last user activity to be before the rollover, but run time
    ; of this function to be after the rollover. If this happens, @extended = 1 and the
    ; returned value is ticks since rollover occured.
    ; Related .......:
    ; Link ..........;
    ; Example .......; Yes
    ;;==========================================================================================
    Func _Timer_GetIdleTime()
    ; Get ticks at last activity
    Local $tStruct = DllStructCreate("uint;dword");
    DllStructSetData($tStruct, 1, DllStructGetSize($tStruct));
    DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct))

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

    ; Get current ticks since last restart
    Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount")

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

    ; Return time since last activity, in ticks (approx milliseconds)
    Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2)
    If $iDiff >= 0 Then
    ; Normal return
    Return $iDiff
    Else
    ; Rollover of ticks counter has occured
    Return SetError(0, 1, $avTicks[0])
    EndIf
    EndFunc ;==>_Timer_GetIdleTime

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _Timer_GetTimerID
    ; Description ...: Returns the Timer ID from $iwParam
    ; Syntax.........: _Timer_GetTimerID($iwParam)
    ; Parameters ....: $iwParam - Specifies the timer identifier event.
    ; Return values .: Success - The Timer ID
    ; Failure - 0
    ; Author ........: Gary Frost
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: _Timer_SetTimer
    ; Link ..........;
    ; Example .......; Yes
    ; ===============================================================================================================================
    Func _Timer_GetTimerID($iwParam)
    Local $_iTimerID = Dec(Hex($iwParam, 8)), $iMax = UBound($_Timers_aTimerIDs) - 1
    For $x = 1 To $iMax
    If $_iTimerID = $_Timers_aTimerIDs[$x][1] Then Return $_Timers_aTimerIDs[$x][0]
    Next
    Return 0
    EndFunc ;==>_Timer_GetTimerID

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _Timer_Init
    ; Description ...: Returns a timestamp (in milliseconds).
    ; Syntax.........: _Timer_Init()
    ; Parameters ....:
    ; Return values .: Success - Returns a timestamp number (in milliseconds).
    ; Author ........: Gary Frost, original by Toady
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: _Timer_Diff
    ; Link ..........;
    ; Example .......; Yes
    ; ===============================================================================================================================
    Func _Timer_Init()
    Return _Timer_QueryPerformanceCounter()
    EndFunc ;==>_Timer_Init

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _Timer_KillAllTimers
    ; Description ...: Destroys all the timers
    ; Syntax.........: _Timer_KillAllTimers($hWnd)
    ; Parameters ....: $hWnd - Handle to the window associated with the timers.
    ; |This value must be the same as the hWnd value passed to the _Timer_SetTimer function that created the timer
    ; Return values .: Success - True
    ; Failure - False
    ; Author ........: Gary Frost
    ; Modified.......: Squirrely1
    ; Remarks .......: The _Timer_KillAllTimers function does not remove WM_TIMER messages already posted to the message queue
    ; Related .......: _Timer_KillTimer, _Timer_SetTimer
    ; Link ..........;
    ; Example .......; Yes
    ; ===============================================================================================================================
    Func _Timer_KillAllTimers($hWnd)
    Local $iResult, $hCallBack = 0, $iNumTimers = $_Timers_aTimerIDs[0][0]
    If $iNumTimers Then
    For $x = $iNumTimers To 1 Step -1
    If IsHWnd($hWnd) Then
    $iResult = DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "int", $_Timers_aTimerIDs[$x][1])
    If @error Then Return SetError(-1, -1, False)
    Else
    $iResult = DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "int", $_Timers_aTimerIDs[$x][0])
    If @error Then Return SetError(-1, -1, False)
    EndIf
    $hCallBack = $_Timers_aTimerIDs[$x][2]
    If $hCallBack <> 0 Then DllCallbackFree($hCallBack)
    $_Timers_aTimerIDs[0][0] -= 1
    Next
    ReDim $_Timers_aTimerIDs[1][3]
    Else
    Return False
    EndIf
    Return $iResult[0] <> 0
    EndFunc ;==>_Timer_KillAllTimers

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _Timer_KillTimer
    ; Description ...: Destroys the specified timer
    ; Syntax.........: _Timer_KillTimer($hWnd, $iTimerID)
    ; Parameters ....: $hWnd - Handle to the window associated with the specified timer.
    ; |This value must be the same as the hWnd value passed to the _Timer_SetTimer function that created the timer
    ; $iTimerID - Specifies the timer to be destroyed
    ; Return values .: Success - True
    ; Failure - False
    ; Author ........: Gary Frost
    ; Modified.......: Squirrely1
    ; Remarks .......: The _Timer_KillTimer function does not remove WM_TIMER messages already posted to the message queue
    ; Related .......: _Timer_KillAllTimers, _Timer_SetTimer
    ; Link ..........; @@MsdnLink@@ KillTimer
    ; Example .......; Yes
    ; ===============================================================================================================================
    Func _Timer_KillTimer($hWnd, $iTimerID)
    Local $iResult[1] = [0], $hCallBack = 0, $iUBound = UBound($_Timers_aTimerIDs) - 1
    For $x = 1 To $iUBound
    If $_Timers_aTimerIDs[$x][0] = $iTimerID Then
    If IsHWnd($hWnd) Then
    $iResult = DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "int", $_Timers_aTimerIDs[$x][1])
    Else
    $iResult = DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "int", $_Timers_aTimerIDs[$x][0])
    EndIf
    If @error Then Return SetError(-1, -1, False)
    If $iResult[0] = 0 Then Return SetError(-1, -1, False)
    $hCallBack = $_Timers_aTimerIDs[$x][2]
    If $hCallBack <> 0 Then DllCallbackFree($hCallBack)
    For $i = $x To $iUBound - 1
    $_Timers_aTimerIDs[$i][0] = $_Timers_aTimerIDs[$i + 1][0]
    $_Timers_aTimerIDs[$i][1] = $_Timers_aTimerIDs[$i + 1][1]
    $_Timers_aTimerIDs[$i][2] = $_Timers_aTimerIDs[$i + 1][2]
    Next
    ReDim $_Timers_aTimerIDs[UBound($_Timers_aTimerIDs - 1)][3]
    $_Timers_aTimerIDs[0][0] -= 1
    ExitLoop
    EndIf
    Next
    Return $iResult[0] <> 0
    EndFunc ;==>_Timer_KillTimer

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

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ; Name...........: _Timer_QueryPerformanceCounter
    ; Description ...: Retrieves the current value of the high-resolution performance counter
    ; Syntax.........: _Timer_QueryPerformanceCounter()
    ; Parameters ....:
    ; Return values .: Success - Current performance-counter value, in counts
    ; Failure - -1
    ; Author ........: Gary Frost
    ; Modified.......:
    ; Remarks .......:
    ; Related .......: _Timer_QueryPerformanceFrequency
    ; Link ..........; @@MsdnLink@@ QueryPerformanceCounter
    ; Example .......;
    ; ===============================================================================================================================
    Func _Timer_QueryPerformanceCounter()
    Local $tperf = DllStructCreate("int64")
    DllCall("kernel32.dll", "int", "QueryPerformanceCounter", "ptr", DllStructGetPtr($tperf))
    If @error Then Return SetError(-1, -1, -1)
    Return DllStructGetData($tperf, 1)
    EndFunc ;==>_Timer_QueryPerformanceCounter

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

    ; #INTERNAL_USE_ONLY#============================================================================================================
    ; Name...........: _Timer_QueryPerformanceFrequency
    ; Description ...: Retrieves the current value of the high-resolution performance counter
    ; Syntax.........: _Timer_QueryPerformanceFrequency()
    ; Parameters ....:
    ; Return values .: Success - Current performance-counter frequency, in counts per second
    ; Failure - 0
    ; Author ........: Gary Frost
    ; Modified.......:
    ; Remarks .......: If the installed hardware does not support a high-resolution performance counter, the return can be zero.
    ; Related .......: _Timer_QueryPerformanceCounter
    ; Link ..........; @@MsdnLink@@ QueryPerformanceCounter
    ; Example .......;
    ; ===============================================================================================================================
    Func _Timer_QueryPerformanceFrequency()
    Local $tperf = DllStructCreate("int64")
    DllCall("kernel32.dll", "int", "QueryPerformanceFrequency", "ptr", DllStructGetPtr($tperf))
    If @error Then Return SetError(-1, -1, 0)
    Return DllStructGetData($tperf, 1)
    EndFunc ;==>_Timer_QueryPerformanceFrequency

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _Timer_SetTimer
    ; Description ...: Creates a timer with the specified time-out value
    ; Syntax.........: _Timer_SetTimer($hWnd[, $iElapse = 250[, $sTimerFunc = ""[, $iTimerID = -1]]])
    ; Parameters ....: $hWnd - Handle to the window to be associated with the timer.
    ; |This window must be owned by the calling thread
    ; $iElapse - Specifies the time-out value, in milliseconds
    ; $sTimerFunc - Function name to be notified when the time-out value elapses
    ; $iTimerID - Specifies a timer identifier.
    ; |If $iTimerID = -1 then a new timer is created
    ; |If $iTimerID matches an existing timer then the timer is replaced
    ; |If $iTimerID = -1 and $sTimerFunc = "" then timer will use WM_TIMER events
    ; Return values .: Success - Integer identifying the new timer
    ; Failure - 0
    ; Author ........: Gary Frost
    ; Modified.......: Squirrely1
    ; Remarks .......:
    ; Related .......: _Timer_KillTimer, _Timer_KillAllTimers, _Timer_GetTimerID
    ; Link ..........; @@MsdnLink@@ SetTimer
    ; Example .......; Yes
    ; ===============================================================================================================================
    Func _Timer_SetTimer($hWnd, $iElapse = 250, $sTimerFunc = "", $iTimerID = -1)
    Local $iResult[1], $pTimerFunc = 0, $hCallBack = 0, $iIndex = $_Timers_aTimerIDs[0][0] + 1
    If $iTimerID = -1 Then ; create a new timer
    ReDim $_Timers_aTimerIDs[$iIndex + 1][3]
    $_Timers_aTimerIDs[0][0] = $iIndex
    $iTimerID = $iIndex + 1000
    For $x = 1 To $iIndex
    If $_Timers_aTimerIDs[$x][0] = $iTimerID Then
    $iTimerID = $iTimerID + 1
    $x = 0
    EndIf
    Next
    If $sTimerFunc <> "" Then ; using callbacks, if $sTimerFunc = "" then using WM_TIMER events
    $hCallBack = DllCallbackRegister($sTimerFunc, "none", "hwnd;int;int;dword")
    If $hCallBack = 0 Then Return SetError(-1, -1, 0)
    $pTimerFunc = DllCallbackGetPtr($hCallBack)
    If $pTimerFunc = 0 Then Return SetError(-1, -1, 0)
    EndIf
    $iResult = DllCall("user32.dll", "int", "SetTimer", "hwnd", $hWnd, "int", $iTimerID, "int", $iElapse, "ptr", $pTimerFunc)
    If @error Then Return SetError(-1, -1, 0)
    If $iResult[0] = 0 Then Return SetError(-1, -1, 0)
    $_Timers_aTimerIDs[$iIndex][0] = $iResult[0] ; integer identifier
    $_Timers_aTimerIDs[$iIndex][1] = $iTimerID ; timer id
    $_Timers_aTimerIDs[$iIndex][2] = $hCallBack ; callback identifier, need this for the Kill Timer
    Else ; reuse timer
    For $x = 1 To $iIndex - 1
    If $_Timers_aTimerIDs[$x][0] = $iTimerID Then
    If IsHWnd($hWnd) Then $iTimerID = $_Timers_aTimerIDs[$x][1]
    $hCallBack = $_Timers_aTimerIDs[$x][2]
    If $hCallBack <> 0 Then ; call back was used to create the timer
    $pTimerFunc = DllCallbackGetPtr($hCallBack)
    If $pTimerFunc = 0 Then Return SetError(-1, -1, 0)
    EndIf
    $iResult = DllCall("user32.dll", "int", "SetTimer", "hwnd", $hWnd, "int", $iTimerID, "int", $iElapse, "ptr", $pTimerFunc)
    If @error Then Return SetError(-1, -1, 0)
    If $iResult[0] = 0 Then Return SetError(-1, -1, 0)
    ExitLoop
    EndIf
    Next
    EndIf
    Return $iResult[0]
    EndFunc ;==>_Timer_SetTimer

    [/autoit]
  • Ein PRogramm im AUtoit Compiler dass das Programm verschlüsselt (so habs ich verstanden) aber noch funktioniert

  • Das ist ein Obfuscator.

    Und so funktioniert Timersettimer:

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <GuiConstantsEx.au3>
    #include <Timers.au3>

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

    Opt("MustDeclareVars", 1)

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

    Global $iMemo

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

    _Example_CallBack()

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

    Func _Example_CallBack()
    Local $hGUI, $iTimer

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


    $hGUI = GUICreate("Timers Using CallBack Function(s)", 400, 320)
    $iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, BitOR($WS_HSCROLL, $WS_VSCROLL))
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    $iTimer = _Timer_SetTimer($hGUI, 500, "_Timerfunc")
    GUISetState()

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

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    ExitLoop
    EndSwitch
    WEnd
    ConsoleWrite("Killed All Timers? " & _Timer_KillAllTimers($hGUI) & @LF)
    GUIDelete()
    EndFunc ;==>_Example_CallBack

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

    ; call back function
    Func _Timerfunc($hWnd, $Msg, $iIDTimer, $dwTime)
    #forceref $hWnd, $Msg, $iIDTimer, $dwTime
    MemoWrite("Timer called @"&@HOUR&":"&@MIN&":"&@SEC&"."&@MSEC)
    EndFunc ;==>_UpdateProgressBar

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

    ; Write a line to the memo control
    Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
    EndFunc ;==>MemoWrite

    [/autoit]
  • Ah ok thx hab den Fehler jetzt gefunden. Jetzt zeigt´s auf jedenfall nicht mehr die fehlermeldung an.
    Ich will _Timer_SetTimer als AdlibEnable Ersatz nehmen. Aber iwie check ich das in der Hilfe nicht. Die erste Angabe von der Funktion:

    Handle zu dem Fenster, welches zu dem Timer gehört.
    Dieses Fenster muß zu dem aufgerufenen Thread gehören

    Ich habe in meinem Sript keine GUI oder ähnliches...
    Was muss ich dann hier schreiben?!: _Timer_SetTimer (hier,3000,"Adlib Ersatz")

    Einmal editiert, zuletzt von Manlius (16. Juni 2009 um 20:51)


  • Ich habe in meinem Sript keine GUI oder ähnliches...

    dann musst du eine GUI erstellen, es reicht die Zeile $hGUI = GUICreate ..., GuiSetstate wird nicht benötigt ;)

  • Ich habe in meinem Sript keine GUI oder ähnliches...
    Was muss ich dann hier schreiben?!: _Timer_SetTimer (hier,3000,"Adlib Ersatz")


    Moin,

    sollte auch ohne GUI gehen ... ;)

    [autoit]


    $nTimer = _Timer_SetTimer (0,3000,"Adlib Ersatz")
    ...
    _Timer_KillTimer(0, $nTimer)

    [/autoit]


    Gruß
    Greenhorn


  • Mit GUI ist sicherer ;) wenn man dann doch mal KillTimer vergisst, wird er gelöscht, sobald die GUI nicht mehr existiert, glaube ich mal gelesen zu haben ;)

    • Offizieller Beitrag

    Nicht zu vergessen ist auch der Funktionskopf der auzurufenden Funktion.
    Z.B.

    [autoit]

    Func _AdlibErsatz($hWnd, $Msg, $iIDTimer, $dwTime)

    [/autoit]

    Wenn die Parameter hinter dem Funktionsnamen weggelassen werden, funzt das ganze nicht und Autoit erhängt sich .
    Hab ich am Anfang vergessen und mir einen Wolf gesucht um den Fehler zu finden .

  • Kann man jetzt noch irgendwie verhindern, dass wenn die AdlibEnable Funktion an der Reihe ist, dass dann die _Timer_SetTimer Funktin nicht dazwischen funkt?!
    Weil in meinem Script, sieht das so aus:

    Spoiler anzeigen
    [autoit]


    If $funk1 = 1 Then
    AdlibEnable ("funk1",1000)
    EndIf
    If $1 Or $2 Or $3 Or $4 Or $5 = 1 Then
    $hwnd = GUICreate ("hallo")
    $nTimer = _Timer_SetTimer ($hwnd,3000,"funk2")
    EndIf

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

    Func funk1 ()
    PixelSearch (307,28,307,28,0x221D16,5)
    If Not @error Then
    usw... (hier kommt was längeres hin)
    Endif
    Endfunc

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

    Func funk2 ($hwnd, $Msg, $iIDTimer, $dwTime)
    $p = PixelGetColor (742,189)
    If $p = 0xFFFBFF Then
    usw....
    Endif
    Endfunc

    [/autoit]