Jump to content

DLL CallBack, Is it possible in AutoIt?


leecole
 Share

Recommended Posts

Looking at how best to design a Speaking Reminder program. As the code below demonstraits, there can only be a single AdLib function active at a time. What about DLLcall for "CreateTimerQueueTimer". If I create a DLL Struct that contains a pointer to a CallBack function, what does that pointer actually point too?

Global Const $onemin = 60000
Global $2cnt=0
Global $3cnt=0
Func OnAutoItExit ( )
AdlibDisable()
 _TalkOBJ("Good bye",3)
EndFunc ;==>OnAutoItExit
;Main
AdlibEnable("Two",2 * $onemin); Set up 1st adlib
Sleep(2 * $onemin)
Adlibenable("Three",3 * $onemin); Set up second adlib
while 1; WAIT
    Sleep(9999999)
WEnd
Exit

Func Two()
    Local $min = @MIN, $hr = @HOUR, $Suffix="AM"
    $min = $min + 2
    If $min>=60 Then
        $min = $min - 60
        $hr = $hr + 1
    EndIf
    If $hr>=12 Then
        $hr = $hr - 12
        $Suffix = "PM"
    EndIf
    $2cnt = $2cnt + 1
    _TalkOBJ("Two: Entry number " & $2cnt & ", next entry should occur at " & $hr & ":" & $min & $Suffix,1)
    Return
EndFunc
    
Func Three()
    Local $min = @MIN, $hr = @HOUR, $Suffix="AM"
    $min = $min + 3
    If $min>=60 Then
        $min = $min - 60
        $hr = $hr + 1
    EndIf
    If $hr>=12 Then
        $hr = $hr - 12
        $Suffix = "PM"
    EndIf   
    $3cnt = $3cnt + 1
    _TalkOBJ("Three: Entry number " & $3cnt & ", next entry should occur at " & $hr & ":" & $min & $Suffix,2)
    Return
EndFunc

Func _TalkOBJ($s_text, $s_voice = 3)
Local $quite = 0
    Local $o_speech = ObjCreate ("SAPI.SpVoice")
    Select
        Case $s_voice == 0
            Return
        Case $s_voice == 1
            $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mary", "Language=409").Item(0)
            TrayTip("Female Reader",$s_text,1)
        Case $s_voice == 2
            $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mike", "Language=409").Item(0)
            TrayTip("Male Reader",$s_text,1)
        Case $s_voice == 3
            $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Sam", "Language=409").Item(0)
            TrayTip("OldMan Reader",$s_text,1)
    EndSelect
    $o_speech.Speak ($s_text)
    $o_speech = ""
    Sleep(1000)
    TrayTip("","",1)
EndFunc  ;==>_TalkOBJ

Talking Clockhttp://www.autoitscript.com/forum/index.php?showtopic=20751Talking Headlineshttp://www.autoitscript.com/forum/index.php?showtopic=20655Sometimes, I sits and thinkssometimes, I just sits

Link to comment
Share on other sites

instead of asking HOW to make your solution work,

you could tell us WHAT you need to do so we could think up a better solution.

(didnt really know how to word that but you get the point, i hope)

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

instead of asking HOW to make your solution work,

you could tell us WHAT you need to do so we could think up a better solution.

(didnt really know how to word that but you get the point, i hope)

Fair enough. I thought my example code would have made it clear that I would like to have multiple timers active, each with their own Callback Function. I really didn't expect the code that I posted to work, but I deceided to test the Adlib function myself. If you execute the code, I set up one timer callback with adlib, then wait long enough for it to execute the callback once, then I establish a different timer callback to another routine. The first callback works only once, but the second AdLibEnable not only sets a timer to the second function, it also cancels the first callback. Not unexpected..., but I wanted to be sure. So I ask about DLL Callbacks. Can I setup a DLL Callback into a AutoIt Function?

Talking Clockhttp://www.autoitscript.com/forum/index.php?showtopic=20751Talking Headlineshttp://www.autoitscript.com/forum/index.php?showtopic=20655Sometimes, I sits and thinkssometimes, I just sits

Link to comment
Share on other sites

or you could use something like this:

$call2 = 0
$call3 = 0

while 1
    Sleep($onemin)
    
    $call2 += 1
    $call3 += 1
    
    if $call2 = 2 Then
        Two()
        $call2 = 0
    EndIf
            
    if $call3 = 3 Then 
        Three()
        $call3 = 0
    EndIf
    
WEnd

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

or you could use something like this:

$call2 = 0
$call3 = 0

while 1
    Sleep($onemin)
    
    $call2 += 1
    $call3 += 1
    
    if $call2 = 2 Then
        Two()
        $call2 = 0
    EndIf
            
    if $call3 = 3 Then 
        Three()
        $call3 = 0
    EndIf
    
WEnd
There are obviuslly many solutions, my aim is to create a SetReminder application that would calculate if the reminder is today, if so, calculate how long from NOW, set a timer, with Callback for that time. Sleep forever. When Callback occurs, Speak aloud the REMINDER. I can achieve the results by using a single Timer CallBack, such as AdLib provides, but I really wanted MORE than just a reminder program. I already have a Talking Clock program (see link in signature) that uses AdLib, and as my sample to this Query, demonstrates, you can only have one Adlib Callback active in a single program, so I was looking for some less CPU intensive way to axhive multiple timer callbacks, hence my question about DLL CallBacks in AutoIt. There is also AT execution, but AT has problems if more than one AT is used. It will schedule multiple callbacks, but it then schedules them both to run the LAST. It is Brain Dead. An obvious solution would be to creat an array of reminders, Sort the array by Date/time so that the first entry is first in the array. Use AdLib to callback when first entry is due. Slleep forver. Callback function Speaks first reminder, dequeues reminder, calculates next reminder time, then reissues AdLibEnable with new calculated time. This would work OK, but not if I wanted to combine it with other Timed functions, such as my Speaking Clock. As seperate programs, the task is easy, I was just seeking looking forward, to needing multiple timer callbacks. Not looking for someone to write the code for me, just looking for an answer to the question, Can I have a DLL CallBack in AutoIt? In other words, when I issue a DLLCall that contains a pointer to a Function, Does that pointer point to executable code that will execute that Function?

Talking Clockhttp://www.autoitscript.com/forum/index.php?showtopic=20751Talking Headlineshttp://www.autoitscript.com/forum/index.php?showtopic=20655Sometimes, I sits and thinkssometimes, I just sits

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...