doudou Posted April 23, 2010 Share Posted April 23, 2010 (edited) Ever wanted to be able to use functions in your AU3 scripts from WSH, VBasic or other COM capable programming language? Well, now it is possible.Please meet: AU3Automation library. It consists of two parts, a COM proxy DLL AU3Aut.dll/AU3Aut64.dll and a small UDF AU3Automation.au3 - both are in the attached archive. Extract the DLL somewhere on your computer (<WinDir>system32 would be a good destination but it is up to you), doregsvr32 AU3Aut.dllresp. on 64-bit systemregsvr32 AU3Aut64.dll(or alternatively just run attached AU3AutRegsiter.au3 script) in the directory, where you extracted it, copy then the UDF files in your AutoIt include directory and start writing automation servers in AU3.Things you can do with AU3AutomationCreate COM server in your plain or compiled AU3 script, in latter case AutoIt doesn't even need to be installed on the target computer to use the server.Export any user defined function.Export any global variable (some types aren't supported, s. exceptions below).Call exported functions or read/write exported variables from any programming language that supports late binding (i.e. "CreateObject").Read all AutoIt @macros from COM clients. Although some macros appear quite pointless in the client context (like dynamic ones: @error, @NumParams, @ScriptLineNumber) but most of them are pretty handy.Things you cannot do with AU3AutomationExport AutoIt built-in functions. A simple UDF wrapper would be exactly as good.Export DllStruct variables or use them as parameter or return type in exported function. No great loss: most of possible clients won't understand them anyway.Access parameters in exported functions ByRef.Raise a specific COM error from within AU3. This is planned in the future, in the meantime you always can export a readonly variable and save error code or description in it (s. example below).Use objects created with AutoItObject in exported variables or return values of exported functions. This is a pity but maybe one day I can convince the AIO team to add marshalling to their great tool.Make coffee, your wife happy and perform brain surgery.Things you shouldn't do with AU3AutomationUse pointers (not even converted to numbers) in exported variables and return values of exported functions. Because the COM server is started in a separate process it has its own address space and all pointers are invalid - thus useless - from the client's perspective.Block the execution of an exported function for to long (f.i. by displaying a MsgBox without timeout). AU3Aut proxy only waits a certain time span for a call to complete and let the client see failure if the call doesn't return in time. The default timeout is 20000 ms and can be set in the client as the second optional parameter of AU3Aut.Load().Use AU3Aut server in ASP or any other networking server application accessible from behind the firewall, it is just to risky.Manufacture weapons of mass destruction.Here's one possible application - a VBScript that uses AU3Script to show "Open File" common dialog.COM server (OpenFileDialog.au3):#include "AU3Automation.au3" _AU3Aut_ExportVariable("title", False, "") _AU3Aut_ExportVariable("initialDir", False, "") _AU3Aut_ExportVariable("filter", False, "All (*.*)") _AU3Aut_ExportVariable("options") _AU3Aut_ExportVariable("defaultName", False, "") _AU3Aut_ExportVariable("error", True) _AU3Aut_ExportFunction("Show") If Not _AU3Aut_Publish() Then Exit -1 _AU3Aut_StayAliveWhileInUse() Func Show() Local $result = FileOpenDialog($title, $initialDir, $filter, $options, $defaultName) $error = @error Return $result EndFuncCOM client (OpenFileDialog.vbs):Set scr = WScript.CreateObject("AU3Aut.Scriptlet") Set dialog = scr.Load("OpenFileDialog.au3") dialog.title = "Please Select File" dialog.filter = "Text Files (*.txt)" dialog.options = 1 Or 2 path = dialog.Show() WScript.Echo "OpenFileDialog returned [" & path & "], error was " & dialog.errorSome more usage examples are in the samples archive.RequirementsAutoIt 22.214.171.124 (minimum)AutoItObject 1.0.x (though its core functionality isn't the subject here, it provides OLE tools I was to lazy to write myself )DDEML 1.5.4 (make sure you have at least this version)DownloadAU3Automation 1.0.6AU3Automation_samples 1.0.1Don't forget: HelpersUDFProject Links @ SourceForgeProject homeFilesSource codeTracker Edited May 6, 2013 by doudou mLipok 1 UDFS & Apps: Spoiler DDEML.au3 - DDE Client + ServerLocalization.au3 - localize your scriptsTLI.au3 - type information on COM objects (TLBINF emulation)TLBAutoEnum.au3 - auto-import of COM constants (enums)AU3Automation - export AU3 scripts via COM interfacesTypeLibInspector - OleView was yesterday Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE Link to comment Share on other sites More sharing options...
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
Already have an account? Sign in here.Sign In Now