genius257

AutoItObject Pure AutoIt

10 posts in this topic

#1 ·  Posted (edited)

I've made a library, based on AutoItObject UDF with the goal of implementing getter and setter functionality and make it possible to define new object properties in as few steps as possible.

Thank you to @trancexx for getting me on the right track, and all users in Hooking into the IDispatch interface for the code to get me going.

If I've forgotten to add credit, please let me know :)

Example:

#include "AutoItObject_Internal.au3"
$myCar = IDispatch()
$myCar.make = 'Ford'
$myCar.model = 'Mustang'
$myCar.year = 1969
$myCar.__defineGetter('DisplayCar', DisplayCar)

Func DisplayCar($oThis)
    Return 'A Beautiful ' & $oThis.parent.year & ' ' & $oThis.parent.make & ' ' & $oThis.parent.model
EndFunc

MsgBox(0, "", $myCar.DisplayCar)

More examples: https://github.com/genius257/AutoIt-projects/tree/master/AutoItObject Internal/Examples

Version: 1.0.3

AutoItObject_Internal.au3

Documentation:

 

README.md3.png

Edit2 (19th March 2017):

First of all, sorry about the lack of updates on this project. I always start too many projects and end up ignoring old projects, if I run into problems ^^'.

So I've started moving my AutoIt scripts to GitHub. I will still post the most recent script version here.

Edited by genius257
3 people like this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This seems something very interesting.... and even more when support for adding methods will be ready.
...worth stay tuned.... :)
Thanks for sharing.

p.s.
this line in AutoItObject_Internal.au3 raises an error:

If $iID==-1 Then Return Return $DISP_E_UNKNOWNNAME

 

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
7 hours ago, Chimp said:

This seems something very interesting.... and even more when support for adding methods will be ready.
...worth stay tuned.... :)
Thanks for sharing.

p.s.
this line in AutoItObject_Internal.au3 raises an error:

If $iID==-1 Then Return Return $DISP_E_UNKNOWNNAME

 

Glad you like it ;)

Sorry about the error. My SciTE did not warn me, but after installing "SciTE4AutoIt3.exe" i now see what you mean ^^

I'll fix and re-upload immediately

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

version: 0.1.2

added basic support for methods via "__defineMethod" will update example.

 

Edit:

I been spending all this time looking into function reference, but it might be impossible, without knowing the structure Autoit uses. I feel like i got as close as i could, without just poking the bytes and hoping to get lucky. So I've added the above to try and get somewhat the same result.

Please inform me, if someone can help me with this.

Edited by genius257

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

version: 1.0.0

Every type should now be supported with ease.

"__defineMethod" is now deprecated

"__unset" added

"__lock" added

Documentation will be above for most recent release, or on GitHub for older releases.

Edited by genius257
1 person likes this

Share this post


Link to post
Share on other sites

#6 ·  Posted

Nice. Some suggestions to join knowledge

Check also clr thread where we are working on c# clr solution for .net objects integrating into autoit..

Check oope.au3

Search for running object table in forums by trancex as it registers object on the fly so you can reach it from for example vbscript or other com languages.

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

version: 1.0.2

"__keys" added

"arguments" property added to AccessorObject.

see documentation above for more info.

 

Example to show one way to use the arguments property and to show it works with things such as ScriptControl:

#include "AutoItObject_Internal.au3"

#AutoIt3Wrapper_Run_Au3Check=N

$AutoItError = ObjEvent("AutoIt.Error", "ErrFunc") ; Install a custom error handler
Func ErrFunc($oError)
    ConsoleWrite("!>COM Error !"&@CRLF&"!>"&@TAB&"Number: "&Hex($oError.Number,8)&@CRLF&"!>"&@TAB&"Windescription: "&StringRegExpReplace($oError.windescription,"\R$","")&@CRLF&"!>"&@TAB&"Source: "&$oError.source&@CRLF&"!>"&@TAB&"Description: "&$oError.description&@CRLF&"!>"&@TAB&"Helpfile: "&$oError.helpfile&@CRLF&"!>"&@TAB&"Helpcontext: "&$oError.helpcontext&@CRLF&"!>"&@TAB&"Lastdllerror: "&$oError.lastdllerror&@CRLF&"!>"&@TAB&"Scriptline: "&$oError.scriptline&@CRLF)
EndFunc ;==>ErrFunc

Example01()
Example02()

Func Example01()
    Local $o=IDispatch()
    $o.__defineGetter("a", _MsgBox)
    Local $oSC=ObjCreate("ScriptControl")
    $oSC.language = "JScript"
    ($oSC.Eval("Function('e','return e.a;')"))($o)
EndFunc

Func Example02()
    Local $oWindow = IDispatch()
    $oWindow.hwnd = GUICreate("title", 700, 320)
    $oWindow.__defineGetter("Show", Wnd_Show)
    $oWindow.__defineGetter("Hide", Wnd_Hide)
    $oWindow.__defineGetter("bkColor", Wnd_bkColor)
    $oWindow.__defineGetter("width", Wnd_width)
    $oWindow.__defineGetter("height", Wnd_height)
    $oWindow.__defineGetter("title", Wnd_title)
    $oWindow.__defineGetter("onExit", Wnd_onExit)

    $oWindow.Show.width(300).bkColor(0xC2E34E).height(300).title("Example 2").onExit(_MyExit)

    While 1
        Sleep(10)
    WEnd
EndFunc

Func _MsgBox()
    Return MsgBox(0, "_MsgBox", "test")
EndFunc

Func Wnd_Show($oSelf)
    GUISetState(@SW_SHOW, $oSelf.parent.hwnd)
    Return $oSelf.parent
EndFunc

Func Wnd_Hide($oSelf)
    GUISetState(@SW_HIDE, $oSelf.parent.hwnd)
    Return $oSelf.parent
EndFunc

Func Wnd_bkColor($oSelf)
    If Not ($oSelf.arguments.length==1) Then Return SetError(1, 1, $oSelf.parent
    GUISetBkColor($oSelf.arguments.values[0], $oSelf.parent.hwnd)
    Return $oSelf.parent
EndFunc

Func Wnd_width($oSelf)
    If Not ($oSelf.arguments.length==1) Then Return SetError(1, 1, $oSelf.parent
    Local $aPos = WinGetPos(ptr($oSelf.parent.hwnd), "")
    WinMove(ptr($oSelf.parent.hwnd), "", $aPos[0], $aPos[1], $oSelf.arguments.values[0], $aPos[3], 0)
    Return $oSelf.parent
EndFunc

Func Wnd_height($oSelf)
    If Not ($oSelf.arguments.length==1) Then Return SetError(1, 1, $oSelf.parent
    Local $aPos = WinGetPos(ptr($oSelf.parent.hwnd))
    WinMove(ptr($oSelf.parent.hwnd), "", $aPos[0], $aPos[1], $aPos[2], $oSelf.arguments.values[0], 0)
    Return $oSelf.parent
EndFunc

Func Wnd_title($oSelf)
    If Not ($oSelf.arguments.length==1) Then Return SetError(1, 1, $oSelf.parent)
    WinSetTitle(ptr($oSelf.parent.hwnd), "", $oSelf.arguments.values[0])
    Return $oSelf.parent
EndFunc

Func Wnd_onExit($oSelf)
    If Not ($oSelf.arguments.length==1) Then Return SetError(1, 1, $oSelf.parent)
    opt("GuiOnEventMode", 1)
    GUISetOnEvent(-3, $oSelf.arguments.values[0], ptr($oSelf.parent.hwnd))
EndFunc

Func _MyExit()
    Exit
EndFunc

 

Edited by genius257
Example added
1 person likes this

Share this post


Link to post
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

  • Similar Content

    • Simpel
      By Simpel
      Hi,
      since some days I become this error message exiting my app:

      Eventviewer shows following data:
      Name der fehlerhaften Anwendung: autoit3.exe, Version: 3.3.14.2, Zeitstempel: 0x55fc1979 Name des fehlerhaften Moduls: ntdll.dll, Version: 6.1.7601.23864, Zeitstempel: 0x595fa490 Ausnahmecode: 0xc000000d Fehleroffset: 0x000987e0 I stripped my code from 1500 lines down to 70:
      #include <GUIConstants.au3> Global $g_sPathToPDF = ; path to some pdf file to show Opt("GUIOnEventMode", 1) ; default ist 0 ; 1 bedeutet, daß bei Klick direkt die darunterbeschriebene Funktion ausgeführt wird Global $g_hGUI_MAIN ; Haupt-GUI Global $g_hDummy_Main ; Dummy um Fokus in der Haupt-GUI unsichtbar zu setzen Global $g_hGUI_Pruefen ; GUI zum Prüfen aller PDF Global $g_hGUI_PDF ; GUI PDF-Ansicht der ausgewählten PDF Global $g_hPDF ; ActiveX control welches das PDF enthält Global $g_oAcrobatReader ; AcrobatReaderObjekt in dem die PDF gezeigt werden _GUI_Main() GUISetOnEvent ($GUI_EVENT_CLOSE, "_Exit_Main" , $g_hGUI_MAIN) While 1 Sleep(1) WEnd Exit Func _GUI_Main() ; GUI-MAIN $g_hGUI_MAIN = GUICreate("MAIN", 390, 390, 763, 372) GUISetFont(12) GUICtrlCreateButton("NEXT", 20, 20, 350, 55, $BS_DEFPUSHBUTTON) ; Default-Knopf GUICtrlSetOnEvent(-1, "_GUI_Pruefen") GUISetState(@SW_SHOW, $g_hGUI_MAIN) ; GUI anzeigen EndFunc Func _GUI_Pruefen() ; GUI zum Prüfen der PDF GUISetState(@SW_HIDE, $g_hGUI_MAIN) ; MAIN-GUI ausblenden Opt("GUIOnEventMode", 0) ; wieder auf Default gesetzt $g_hGUI_Pruefen = GUICreate("RIGHT", 490,950, 1057, 91, -1, $WS_EX_APPWINDOW, $g_hGUI_MAIN) _AcrobatShow($g_sPathToPDF, "", 367, 91, 674, 950, $g_hGUI_Pruefen) ; PDF-GUI erstellen GUISetState(@SW_SHOW, $g_hGUI_Pruefen) ; GUI-Prüfen anzeigen Local $msg While 1 $msg = GuiGetMsg() ; Aktion mit der GUI registrieren Switch $msg ; je nach Aktion mit der GUI Case $GUI_EVENT_CLOSE ; X gedrückt $g_oAcrobatReader = "" ; zerstöre das Objekt AcrobatReader GUIDelete($g_hGUI_PDF) ; lösche die GUI-PDF GUIDelete($g_hGUI_Pruefen) ; lösche die GUI-Prüfen Opt("GUIOnEventMode", 1) ; Default 0 GUISetState(@SW_SHOW, $g_hGUI_MAIN) ; MAIN-GUI wieder zeigen Return EndSwitch WEnd EndFunc Func _Exit_Main() ; ausführen, wenn die MAIN-GUI schließt ConsoleWrite("EXIT" & @CRLF) Exit EndFunc Func _AcrobatShow($sFile, $sTitle = "PDF ", $iLeft = 50, $iTop = 0, $iWidth = 1000, $iHeight = 700, $hWnd = "") ; GUI-PDF erstellen If FileExists($sFile) Then ; wenn das PDF existiert $g_oAcrobatReader = ObjCreate("AcroPDF.PDF.1") $g_oAcrobatReader.src = $sFile ; Quelle ist das File $g_oAcrobatReader.SetLayoutMode("SinglePage") ; default "SinglePage" $g_oAcrobatReader.SetPageMode("none") ; default "none" $g_oAcrobatReader.SetShowToolbar(0) ; Tool-Bar nicht zeigen 0 $g_oAcrobatReader.SetShowScrollbars(0) ; Scroll-Balken nicht zeigen 0 $g_oAcrobatReader.SetView("fit") ; "fit" falls wer eigene Einstellungen im Reader gespeichert hat $g_hGUI_PDF = GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, -1, -1, $hWnd) ; GUI als Child zu GUI-PRUEFEN erstellen - es soll nicht aktiviert werden $g_hPDF = GUICtrlCreateObj($g_oAcrobatReader, 0, 0, $iWidth, $iHeight) ; Objekt für das PDF erstellen GUICtrlSetStyle($g_hPDF, $WS_VISIBLE) ; PDF anzeigen GUISetState(@SW_SHOW, $g_hGUI_PDF) ; GUI-PDF anzeigen Else MsgBox(0, 'ERROR', "No PDF found.") EndIf EndFunc Do following steps to prove:
      - start app
      - click "next" on main gui
      - wait minimum 5 seconds (until the arrows left and right on "gui left" disappear)
      - close gui left or right
      - close main gui
      - look on console written "EXIT" the last code line before exit
      - now windows error message above appears
      The funny thing is if I don't wait the 5 seconds (before the half transparent arrows disappear) closing the gui then I will get no win error message.
      If I comment _AcrobatShow() out then the error never appears. So it seemed to be an acrobat reader issue. Every week at work there are a lot of updates, but there is no chance to know which one. But since one update this error happens.
      Any solutions? Regards, Conrad
    • WoodGrain
      By WoodGrain
      Hi All,
      I've coded the small script below, but it can't seem to get the instance of Windows Media player as it keeps going to @error, I've not used com objects before so any assistance would be appreciate. I already have WMP open and minimised. I retrieved "WMPlayerApp" from the AutoIT info tool, I've included a copy below.
      I'm using these sources:
      https://msdn.microsoft.com/en-us/library/dd564085.aspx
      https://msdn.microsoft.com/en-us/library/dd564018.aspx
      $oWMP = ObjGet("", "WMPlayerApp") If @error Then MsgBox(0, "Can't get WMP", "Couldn't connect to the WMP instance") Exit EndIf $wmpPlayState = $oWMP.playState MsgBox(0, "Play State", $wmpPlayState) $wmpSongName = $oWMP.currentMedia.name MsgBox(0, "Play State", $wmpSongName) I've also seen references to the below, but I want to get an existing open WMP:
      ObjCreate("wmplayer.OCX") and have looked at the WMP.udf but can't see how it will do either of the functions I've coded above.
       
    • harvester2001
      By harvester2001
      Hi
      I need help, I found script to check computer model. I want use it in loop to chceck multiple pc`s (targets.txt with computer names).
      But when i try use inside loop i get error: Variable must be of type "Object" and I dont know how to fix this
      Plz help
       
      Local $targets = @ScriptDir& "\targets.txt" Local $log_name = "\scan.log" $msgBox = MsgBox(4, "Scan", "need tergets.txt") Example() Func Example() If $msgBox = 7 Then exit EndIf If Not FileExists($targets) Then MsgBox($MB_SYSTEMMODAL, "", "File: targets.txt - no exist !") Exit EndIf FileOpen($targets, 0) Global $arr[1000] ReDim $arr[_FileCountLines($targets)+1] For $i = 1 to _FileCountLines($targets) $line = FileReadLine($targets, $i) $arr[$i] = $line ; chceck if pc is online Local $iPing = Ping($arr[$i], 250) If $iPing Then ; ONLINE Local $strComputer = $arr[$i] $colItems = "" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _ "0x10" + "0x20") If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Vendor: " & $objItem.Vendor & @CRLF $Output = $Output & "SN: " & $objItem.IdentifyingNumber & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "UUID: " & $objItem.UUID & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystemProduct" ) Endif Else ;OFFLINE _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" OFFLINE") EndIf Next EndFunc  
       
    • Leo1906
      By Leo1906
      I have a problem here. I have a Script wich opens a Gui with an iExplore Object embedded. The GuiCreate is in an external Function an called in the main while of the script.
      When the Gui closes the Gui gets destoyed. But unfortunately the iExplore Obejct still remains. You can see this by the RAM usage of the exe. After opening a Website the RAM usage stays at  ~ 50 Mb RAM (depending on the website).
      I want it to fall back to the normal state (around 4 MB).
      You can see my attempts to delete the object properly. According to the help an embedded object should get deleted when the GUI gets deleted ...?
       
      GUICreate("Display", 600, 360, -1, -1) Local $oIE = _IECreateEmbedded() $obj = GUICtrlCreateObj($oIE, 0, 0, 600, 360) GUICtrlSetColor(-1, 0xff0000) _IEPropertySet($oIE, "addressbar", False) _IEPropertySet($oIE, "menubar", False) _IEPropertySet($oIE, "statusbar", False) _IEPropertySet($oIE, "toolbar", False) _IEPropertySet($oIE, "resizable", False) _IENavigate($oIE, $dest&"\index.html") GUISetState(@SW_SHOW) While 1 Local $iMsg = GUIGetMsg() Local $tmsg = TrayGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE ;~ $obj = 0 ;~ _WinAPI_DeleteObject ( $obj ) ;~ _IEQuit($obj) ;~ _MemGlobalFree($obj) ;~ $oIE = 0 ;~ _WinAPI_DeleteObject ( $oIE ) ;~ _IEQuit($oIE) ;~ _MemGlobalFree($oIE) GUIDelete() Case $tmsg = $exit _exit() EndSelect WEnd  
      I would be very happy for your help  
      Kind regards
    • Hasoth
      By Hasoth
      Hi,
      I've encountered a problem while I tried to close popup in application that is using embeded GUI object. If site has function "onbeforeunload" asking if you really want to exit you will get a popup. In embeded gui object it completly freezes functions and I can't click/close/do anything. I've created sample code with microsoft function example and in external window. Any idea how to close popup in GUI embeded IE? I've tried navigating using _IENavigate($oIE, $sURL, 0) or  changing focus _IEaction($oIE,"focus") but nothing works.
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <IE.au3> HotKeySet("{F1}", "myExit") ;GUI setup $GUI_main = GUICreate("Menu", 800, 800, -1, -1) Global $oIE =_IECreateEmbedded() $ObjectIE = GUICtrlCreateObj($oIE, 0, 30, 800, 770) $cButton1 = GUICtrlCreateButton("Start test inside GUI window", 0, 0, 400, 30) $cButton2 = GUICtrlCreateButton("Start test outside GUI window", 400, 0, 400, 30) GUISetState(@SW_SHOW, $GUI_main) ;GUI While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_main Case $ObjectIE Case $cButton1 fTestFunction1() Case $cButton2 fTestFunction2() EndSwitch WEnd ;function inside GUI Func fTestFunction1() Local $sURL = "http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onbeforeunload.htm" $oIE.Navigate($sURL) _IELoadWait($oIE) $oIE.Navigate("https://www.google.com") MsgBox($MB_TOPMOST, "", "should appear while question box opened", 2) Sleep(2500) Send("!o") EndFunc ;function outside GUI Func fTestFunction2() Local $sURL = "http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onbeforeunload.htm" $oSecondIE = _IECreate ($sURL) _IELoadWait($oSecondIE) $oSecondIE.Navigate("https://www.google.com") MsgBox($MB_TOPMOST, "", "should appear while question box opened", 2) Sleep(2500) Send("!o") EndFunc ;shortcut to exit Func myExit() GUIDelete($GUI_main) Exit EndFunc