rassillon Posted August 5, 2011 Share Posted August 5, 2011 Hi everyone, I am reasonably capable with AutoIt... I even to the point of working out some dll calls myself and writing some rather complex scripts. It is my language of choice when I have one but I also use vbs/js/vb/perl/php/python/kix/batch/c++/java/etc to varying degrees some more than others. Just putting that out there....but I can be a bit dense sometimes too. Ok now for the question. I have a project I am in the planning stages for with a snippet here and a snippet there working out the more complex functions. I need, yes need to incorporate the use of the MSScriptControl into the project to support VBS and JS scripts. I can 1.create the object 2.set the language 3.add code 4.run that code What I can't figure out is how to AddObject so as to provide my internal Funcs to the running script The vb examples I see create a class module and then use the "new" keyword Here is a MS page about how to do it http://support.microsoft.com/kb/185697 Since AutoIt is not OO I don't know how to go about this. If someone could give me a simple working example I would be super grateful. I am not trying to get you to write my code for me, I have been on many forums and I am not that guy. I will provide a code example if needed with pseudo code to represent what I want but there are several examples on the forum already using MSScriptControl and AddCode, but none that use AddObject. I have tried several google searches but all I come up with are VB examples for AddObject... Anyway, I am long winded but I would appreciate the help if someone could provide it. Thanks in advance! Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 5, 2011 Share Posted August 5, 2011 (edited) If you mean "my internal Funcs" as your AutoIt script functions, it just doesn't work that way. The object has to exist before you add the reference to it with .AddObject. AutoIt's functions are not objects, so they can't be added that way.You might look for some work ProgAndy, trancexx, and others were doing on Edit: Added link. Edited August 5, 2011 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
ProgAndy Posted August 5, 2011 Share Posted August 5, 2011 (edited) Using AutoIt-Object, you cann add the object but somehow calls to functions fail. Probably ScriptControl expects a Typelib which we do not provide. expandcollapse popup$oScript = ObjCreate("ScriptControl") #include "AutoItObject.au3" Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Func _ErrFunc() ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) Return EndFunc ;==>_ErrFunc _AutoItObject_StartUp() $oTest = _AutoItObject_Create() _AutoItObject_AddMethod($oTest, "Message", "__Message") $oTest.Message("test") With $oScript .Language = "VBScript" .AllowUI = True .AddObject ("bbv", $oTest) .AddCode ("Sub Test"& @CRLF _ & ' MsgBox("Hello world")'& @CRLF _ & ' bbv.Prt("call")'& @CRLF _ & 'End Sub'& @CRLF ) .Run("Test") EndWith Func __Message($this, $text) MsgBox(0, 'Message Object', $text) EndFunc $oScript = 0 $oTest = 0 _AutoItObject_Shutdown() Edited August 5, 2011 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
rassillon Posted August 5, 2011 Author Share Posted August 5, 2011 If you mean "my internal Funcs" as your AutoIt script functions, it just doesn't work that way. The object has to exist before you add the reference to it with .AddObject. AutoIt's functions are not objects, so they can't be added that way. You might look for some work ProgAndy, trancexx, and others were doing on Edit: Added link. PsaltyDS, thanks for the response and the link. "my internal funcs" refered to functions I write using the Func/EndFunc structure in my main AU3 I realize autoit's functions are not objects built-in or user defined, This is the reason class modules and new keyword was used in the VB example I cited, so that you could have an object. I probably should have been clearer in my question. Thank you again for your input! I see ProgAndy has posted as well, let me see what he has to say.... Using AutoIt-Object, you cann add the object but somehow calls to functions fail. Probably ScriptControl expects a Typelib which we do not provide. expandcollapse popup$oScript = ObjCreate("ScriptControl") #include "AutoItObject.au3" Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Func _ErrFunc() ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) Return EndFunc ;==>_ErrFunc _AutoItObject_StartUp() $oTest = _AutoItObject_Create() _AutoItObject_AddMethod($oTest, "Message", "__Message") $oTest.Message("test") With $oScript .Language = "VBScript" .AllowUI = True .AddObject ("bbv", $oTest) .AddCode ("Sub Test"& @CRLF _ & ' MsgBox("Hello world")'& @CRLF _ & ' bbv.Prt("call")'& @CRLF _ & 'End Sub'& @CRLF ) .Run("Test") EndWith Func __Message($this, $text) MsgBox(0, 'Message Object', $text) EndFunc $oScript = 0 $oTest = 0 _AutoItObject_Shutdown() ProgAndy, You are freakin awesome!!!!!! Just one little issue with your code & ' bbv.Prt("call")'& @CRLF _ should be & ' bbv.Message("call")'& @CRLF _ Effin A Man! Link to comment Share on other sites More sharing options...
ProgAndy Posted August 5, 2011 Share Posted August 5, 2011 I renamed it and forgot this occurence. Anyways, it doesn't work for me. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
rassillon Posted August 5, 2011 Author Share Posted August 5, 2011 I renamed it and forgot this occurence. Anyways, it doesn't work for me. No way.... It works perfectly for me. expandcollapse popup$oScript = ObjCreate("ScriptControl") #include "AutoItObject.au3" Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Func _ErrFunc() ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) Return EndFunc ;==>_ErrFunc _AutoItObject_StartUp() $oTest = _AutoItObject_Create() _AutoItObject_AddMethod($oTest, "Message", "__Message") $oTest.Message("test") With $oScript .Language = "VBScript" .AllowUI = True .AddObject ("bbv", $oTest) .AddCode ("Sub Test"& @CRLF _ & ' MsgBox("Hello world")'& @CRLF _ & ' bbv.Message("call")'& @CRLF _ & 'End Sub'& @CRLF ) .Run("Test") EndWith Func __Message($this, $text) MsgBox(0, 'Message Object', $text) EndFunc $oScript = 0 $oTest = 0 _AutoItObject_Shutdown() All I did was download AutoItObject Package 1.2.8.2 Unzip it Place the above script in the same directory. Run it... Hmmmm.... Link to comment Share on other sites More sharing options...
ProgAndy Posted August 5, 2011 Share Posted August 5, 2011 No way.... It works perfectly for me.You are right. I just found out that there were different versions of AuO in my include paths, it works after deleting the old versions *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
rassillon Posted August 5, 2011 Author Share Posted August 5, 2011 You are right. I just found out that there were different versions of AuO in my include paths, it works after deleting the old versions 1.) That makes me feel better because I don't have to worry so much about some strange behaviour.2.) Now I can reiterate You Da Man!3.) Sounds like you can be as lazy as me with your dev environment...lol Link to comment Share on other sites More sharing options...
ProgAndy Posted August 5, 2011 Share Posted August 5, 2011 3.) Sounds like you can be as lazy as me with your dev environment...lolI have multiple folders for UDFs and sometimes I add updated UDFs to the wrong one *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now