xroot Posted March 2, 2015 Share Posted March 2, 2015 Lots of us have used the "ScriptControl" object in Autoit to create simple classes using jScript, vbScript. For example, I created a simple Car class in jScript. #include "jsFunc.au3" jsc('function Car(make,color,year){') ;Car class jsc('this.make = make;') ;property jsc('this.color = color;') jsc('this.year = year;') jsc('this.Info = function(){return this.year + " " + this.color + " " + this.make;}}') $js.AddCode($jsCode) ;add code to the global module ;MsgBox(0,"jScript",$jscode) ;debug local $car = $js.Eval('new Car("Jaguar F-Type","Black",2015);') ;car class object msgbox(64,"New Car Class 1",$car.Info(),2) ;show car class properties ;change car properties $car.make = "Porsche Speedster" $car.color = "Red" $car.year = 1955 msgbox(64,"New Car Class 2",$car.Info(),2) ;show car class properties The Car class is not very useful. I needed the ability to create classes that makes Autoit more functional and easy to produce with the power of Autoit. The VARIANT class is more interesting and functional, showing todays long date. Of course using vbScript's "FormatDateTime" to show long date in one line is simpler. I'am just trying to show how easy it is too create and use meaningful classes. expandcollapse popup#include "jsFunc.au3" jsc('function VARIANT(){') ;VARIANT class jsc('this.vt = 0;') ;property jsc('this.union = 0;') jsc('this.Now = new Date().toString();') ;string date object jsc('this.api = new ActiveXObject("Apidll.ApidllC");') ;api class object jsc('this.Ptr = this.api.CallApi("kernel32","GlobalAlloc",64,16);') ;VARIANT structure Ptr jsc('this.StrPtr = this.api.CallApi("kernel32","GlobalAlloc",64,32);') ;VARIANT string Ptr jsc('this.class_Set = function(){') jsc('this.api.Set_Data(this.Ptr ,this.vt ,2);') ;vt_type jsc('this.api.Set_Data(this.Ptr+8,this.union,this.vt);}') ;vt_data ;formats a variant containing named date and time information into a string jsc('this.VarFormatDateTime = function(pvarIn,iNamedFormat,dwFlags,pbstrOut){') jsc('return this.api.CallApi("oleaut32","VarFormatDateTime",pvarIn,iNamedFormat,dwFlags,pbstrOut);}') jsc('this.class_Terminate = function(){') jsc('this.api.CallApi("kernel32","GlobalFree",this.Ptr);') jsc('this.api.CallApi("kernel32","GlobalFree",this.StrPtr);}}') $js.AddCode($jsCode) ;add code to the global module ;MsgBox(0,"jScript",$jscode) ;debug local $longdate = 1 local $dwflags = 0 local $VT_LPWSTR = 31 local $varnt = $js.Eval("new VARIANT();") ;variant class object ; set date variant $varnt.vt = 7 ;vt_type date $varnt.union = (@YEAR-1900)*365+@YDAY+29 ;vt_date data $varnt.class_Set() ;update class variant ;get long date $varnt.VarFormatDateTime($varnt.Ptr, $longdate, $dwflags, $varnt.StrPtr) Msgbox(64,$varnt.Now, $varnt.api.Get_Data($varnt.StrPtr, $VT_LPWSTR)) ;cleanup $varnt.class_Terminate() $varnt = 0 I Created "Apidll.ApidllC", an Activex Class that dynamically calls a function in any dll. This class is simple with a few methods, for more information see the Apidll.chm file. This gives jScript, and vbScript the ability to call the Api and do pointers, and giving Autoit the ability to create classes on the fly. ApiDll.zip TheAutomator 1 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