Jump to content

_AdlibEnhance.au3 (UDF) - Call functions with parameters, pause and resume!


JScript
 Share

Recommended Posts

Function Reference


_AdlibEnhance.au3

Adlib function with support for parameters, pause and resume using Call Back!

Sintax:

_Adlib_Register( "Function" [, "Params" [, Time [, RepeatCount ]]] )
_Adlib_Pause( "Function" )
_Adlib_Resume( "Function" )
_Adlib_SetTimer( "Function" [, Time ] )
_Adlib_UnRegister( "Function" )

Supports:

; You can call functions with parameters and native functions also!

Downloads:

Version: 0.10

_AdlibEnhance_(RedirectLink).html

Note: Usage example is included!

Sample:

Posted Image

Fixes:

  • 0.10.1612.2600b
  • 16/10/2012 -> First release!


Regards,

João Carlos.

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Nice!

Is there any way to call the function with different parameters every time?

the way it it right now, the parameters are stored when _Adlib_Register() is called.

; #FUNCTION# ====================================================================================================================
; Name...........: _Adlib_SetParams
; Description ...: Pauses the Enhanced Adlib functionality for defined function.
; Syntax.........: _Adlib_Pause( "Function", "Params" )
; Parameters ....: Function - The name of the adlib function to pause.
;                  Params - The new parameter(s).
; Return values .: Success - Return 1
; Failure - Return 0
; Author ........: darthWhatever
; Modified.......:
; Remarks .......:
; Related .......: _Adlib_Resume, _Adlib_Register, _Adlib_UnRegister, _Adlib_SetTimer
; Link ..........;
; Example .......; _Adlib_SetParams( "MyFunction", "NewParam1|NewParam2" )
; ===============================================================================================================================
Func _Adlib_SetParams($sFuncName, $sParams)
Local $iIndex = __ADB_GetIndex($sFuncName)
If Not $iIndex Then Return 0
$avADB_CALLS[$iIndex][1] = $sParams
Return 1
EndFunc ;==>_Adlib_SetParams

[font=arial, sans-serif]How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?[/font][font=arial, sans-serif]<div>This is how you annoy a web developer.</span>[/font]

Link to comment
Share on other sites

#include "_AdlibEnhance.au3"
_Adlib_Register("_Exit", "Info|Enhanced Adlib function!", 500, 1)

While 1
sleep(250)
WEnd

Func _Exit($sTitle, $sText)
ConsoleWrite("Why Does it crash? Exit code: -1073741819" & @CRLF)
EndFunc ;==>_Exit

Taken from your example, every time i try a counted Register. It crashes when it reaches its timer?

Is this the same for anyone else ? Is this how that function is meant to work ?

Edited by IanN1990
Link to comment
Share on other sites

Or I did not understand or I do not know what you're talking about!

The above example had no problems for me, it works normal... :huh:

What is the OS you use, which version of AutoIt?

My SciTE output:

>"D:Program FilesAutoIt3SciTEAutoIt3WrapperAutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "D:DropboxAutoIt v3 - ProjectsAdlibEnhanceExample.au3" /UserParams
+>20:35:07 Starting AutoIt3Wrapper v.2.1.0.33 Environment(Language:0416 Keyboard:00010416 OS:WIN_7/ CPU:X64 OS:X86)
>Running AU3Check (1.54.22.0) from:D:Program FilesAutoIt3
+>20:35:07 AU3Check ended.rc:0
>Running:(3.3.8.1):D:Program FilesAutoIt3autoit3.exe "D:DropboxAutoIt v3 - ProjectsAdlibEnhanceExample.au3"
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
+>20:35:20 AutoIT3.exe ended.rc:0
>Exit code: 0 Time: 14.344

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Fixed.

I forgot on the laptop ages ago i switched the autoit and autoit64.exe "cant remember why*.

Your Scite Output plus the fact the code worked fine on my dads pc but not the laptop help spark the idea as well.

Sorry for the confusion.

Edited by IanN1990
Link to comment
Share on other sites

It works, there isnt a problem any more so theres not much output for me to post :D

In the Autoit File i had the 64bit version named 32 "so by default autoit always ran 64 bit". I fear this is what was causing the problem because when i put back the 2 separate version.

AutoIt3.exe

AutoIt3_x64.exe

It works fine again :) So the problem was my fault.

On a completely different note.

#include "_AdlibEnhance.au3"

While 1
sleep(1000)
_Adlib_Register("_Exit", "Info|Enhanced Adlib function!", 2000, 1)
WEnd

Func _Exit($sTitle, $sText)
ConsoleWrite("_Exit Has RuN" & @CRLF)
EndFunc ;==>_Exit

The code only runs once, this might be a silly thought but wouldn't it be better when $Count reaches its set limit and the Adlib has finished, the function itself should be de registered as well. So it could be called again later if needed?

Edited by IanN1990
Link to comment
Share on other sites

_Adlib_Register( "Function" [, "Params" [, Time [, RepeatCount ]]] )

So

_Adlib_Register("_Exit", "Info|Enhanced Adlib function!", 2000)

Runs forever!

Try this:

#include "_AdlibEnhance.au3"

_Adlib_Register("_Exit", "Info|Enhanced Adlib function!", 2000)

While 1
    Sleep(1000)
WEnd

Func _Exit($sTitle, $sText)
    ConsoleWrite("_Exit Has RuN" & @CRLF)
EndFunc   ;==>_Exit

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

hmm not quite what i ment :)

In my code i have a mouse hook, and as i am sure most people know you should not use sleeps, whiles or anything that delays code in a hook. It should be procressed and control returned as fast as possible. So for big codes i would call a AdlibRegister (which will prob be replaced in any event with this improved version :)". I just figured i could have some code that calls your fuction, with a count of 1. So it would only run once until the hook is triggered again.

Random Example i came up with might be like this. Its kinda bad but shows my mind-set ^^ (Yes its not the hook example but that code is long and a example would be complicated)

#include "_AdlibEnhance.au3"

local $hWnd = GUICreate("", 260, 100)
local $Button1 = GUICtrlCreateButton("Button1", 45, 0, 150, 20)
local $Button2 = GUICtrlCreateButton("Button2", 45, 75, 150, 20)
GUISetState()

While True
$Msg = GUIGetMsg()
     Switch $Msg
Case $Button1
_Adlib_Register("TimeOut", "Button1|", 250, 5)
Case $Button2
_Adlib_Register("TimeOut", "Button2|", 250, 5)
     EndSwitch
Wend

Func TimeOut($sTitle, $Text)
ConsoleWrite($sTitle & " Has been Pressed, This is a random function" & @CRLF)
EndFunc ;==>_Exit

So as you can see, you could only click one of the buttons only once, as once the count is finished. The Function is not unregistered and therefore cant be called again.

Edited by IanN1990
Link to comment
Share on other sites

Nice UDF. Will be very useful for a few of my projects. Thanks!

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

  • 1 year later...
  • 2 years later...

So this adlib works just like the normal adlib in Autoit except that you can parse params, right?

That means that the main script is beeing paused when the adlib is called?

 

Edit: even a MsgBox isn't stopping the adlib? :D
What is this? Some kind of "multithreading"?

Edit2: When limiting the calls of the adlib, the function get's automatically unregistered? So there is no need to unregister it myself?

Edited by Leo1906
Link to comment
Share on other sites

  • 4 weeks later...

Hi @JScript

I love this UDF, but I ran into an error when I used _Adlib_UnRegister.

When I ran the script below it would give me Array Errors

#include "_AdlibEnhance.au3"

Global $iCount = 0
_Adlib_Register("_Test1", "", 500)

While 1
    GUIGetMsg()
WEnd

Func _Test1()
    ConsoleWrite("(Stop @ 5)" & @TAB & "Count: " & $iCount & @CRLF)
    If $iCount = 5 Then
        _Adlib_UnRegister("_Test1")
        ConsoleWrite("Yes! Stopped @ " & $iCount & @CRLF)
    EndIf
    $iCount += 1
EndFunc

I played around a bit and found it works If I pause it first then unregister it.

So I modified the UDF function to kill the timer first as shown below:

Func _Adlib_UnRegister($sFuncName = "")
    Local $iIndex

    $iIndex = __ADB_GetIndex($sFuncName)
    If Not $iIndex Then Return 0
    
    __ADB_KillTimer($avADB_CALLS[$iIndex][4], $iIndex) ; Added This Line

    For $i = $iIndex To UBound($avADB_CALLS) - 2
        For $j = 0 To 9
            $avADB_CALLS[$i][$j] = $avADB_CALLS[$i + 1][$j]
        Next
    Next
    ReDim $avADB_CALLS[$avADB_CALLS[0][0]][10]
    $avADB_CALLS[0][0] -= 1

    Return 0
EndFunc   ;==>_Adlib_UnRegister

Now it works perfectly!

 

Link to comment
Share on other sites

  • 3 years later...

Hey, the UDF is still working, so I hope to find some help or a "newer" UDF :)

I want to register one function with different Paramters. Like this, but this isnt working:

#include "_AdlibEnhance.au3"

_Adlib_Register("_MyAdlib", "1", 1000)
_Adlib_Register("_MyAdlib", "2", 2000)
_Adlib_Register("_Exit", "", 5000)

While 1
    GUIGetMsg()
WEnd

Func _MyAdlib($sText)
    ConsoleWrite($sText & @CRLF)
EndFunc   ;==>MyAdlib

Func _Exit()
    Sleep(2000)
    Exit
EndFunc   ;==>_Exit

Right now my code isnt very flexible, I use "Helper"-functions like this:

AdlibRegister("AdlibHelperPega" & $iID)

Func AdlibHelper1()
    _MyAdlib(1)
EndFunc

Func AdlibHelper2()
    _MyAdlib(2)
EndFunc

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...