This Include-UDF idea was inspired from Feature Request on Bug Tracking System about a better OnAutoItStart/OnAutoItExit handling. So here it is:
#include <OnAutoItExit_Handler.au3> _OnAutoItExit_AddFunc("MyTestFunc", "Some data") _OnAutoItExit_AddFunc("MyTestFunc2", "Some other data") Sleep(1000) ;_OnAutoItExit_RemoveFunc("MyTestFunc") Func OnAutoItExit() ;If we have our own OnAutoItExit function, OnAutoItExit_Handler will add ("pick up") this function to the handler :) ;It's helpfull when this function is defined by some UDF that we using in our scripts. MsgBox(64, "Exit Results 1", "Exit Message from OnAutoItExit()") EndFunc Func MyTestFunc($sParam) MsgBox(64, "Exit Results 2", 'Exit Message from MyTestFunc("' & $sParam & '")') EndFunc Func MyTestFunc2($sParam) MsgBox(64, "Exit Results 3", 'Exit Message from MyTestFunc("' & $sParam & '")') EndFunc
* This include is usefull for the UDF writters, to let them set OnAutoItExit() function to free some resources, perhaps in the future i should add an option to check constantly the Opt("OnExitFunc") and add to the list if new function was set.
* If you are including some UDF that uses OnAutoItExit function, then «OnAutoItExit Handler» UDF will "catch" that function and call it when script is exits.
* OnAutoItStart() function can not be handled as OnAutoItExit() function (due to the lack of ability of changing it's name, and also because when it's called there is no variables declared and we can not add other function calls by func), but we still can add a multiple functions from inside OnAutoItStart function, example:
Func OnAutoItStart() Local $aOnAutoItStart_Funcs = StringSplit("OnAutoItStart_1|OnAutoItStart_2", "|");Add here as many as you need For $i = 1 To $aOnAutoItStart_Funcs If $aOnAutoItStart_Funcs[$i] = "OnAutoItStart" Then ContinueLoop;Prevent recursion error Call($aOnAutoItStart_Funcs[$i]) Next EndFunc
But it's not so practical (not usefull), since we can't use it to overcome other UDF's defined function (OnAutoItStart()).
Download: OnAutoItExit_Handler.zip 1.1K 319 downloads