Jump to content

Recommended Posts

Posted (edited)

I haven't touched AutoIt in over a year, so I'm a bit rusty. 
Here is an attempt to incorporate the Get/Set property into @trancexx ObjectFromTag code, similar to the AutoItObject UDF.

Example 1:

#include "ObjFromTag_v1a UDF.au3"

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")

__Example1()
Func __Example1()
    ConsoleWrite("> __Example4() " & @CRLF)
    Local $t_TestObj
    Local $o_TestObj = __ObjectFromTag("__MyInterface_", '', $t_TestObj, 'int Ln;char Msg[30];')

    __SetProperty($o_TestObj, "Ln", 555)
    __SetProperty($o_TestObj, "Msg", 'Is it working.')

    ConsoleWrite("+>>> Ln         :   " & __GetProperty($o_TestObj, "Ln") & @CRLF)
    ConsoleWrite("+>>> Msg        :   " & __GetProperty($o_TestObj, "Msg") & @CRLF)

    If IsObj($o_TestObj) Then $o_TestObj = 0
    __DeleteObjectFromTag($t_TestObj)
    ConsoleWrite("----The End----" & @CRLF)
EndFunc


Func __MyInterface_QueryInterface($pSelf, $pRIID, $pObj)
    Return __QueryInterface($pSelf, $pRIID, $pObj)
EndFunc

Func __MyInterface_AddRef($pSelf)
    Return __AddRef($pSelf)
EndFunc

Func __MyInterface_Release($pSelf)
    Return __Release($pSelf)
EndFunc

Func _ErrFunc()
    ConsoleWrite("! COM Error !  Number: 0x" & Hex($oError.number, 8) & "   ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
    Return
EndFunc   ;==>_ErrFunc

 

Example 2:

#include "ObjFromTag_v1a UDF.au3"

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")

__Example2()
Func __Example2()
    ConsoleWrite("> __Example2() " & @CRLF)
    Local $t_TestObj
    Local $o_TestObj = __ObjectFromTag("__MyInterface_", 'Open hresult();Close hresult();', $t_TestObj, 'handle WinHnd;')
    If Not IsObj($o_TestObj) Then Return

    $o_TestObj.Open()
    $o_TestObj.Close()

    If IsObj($o_TestObj) Then $o_TestObj = 0
    __DeleteObjectFromTag($t_TestObj)
    ConsoleWrite("----The End----" & @CRLF)
EndFunc


Func __MyInterface_QueryInterface($pSelf, $pRIID, $pObj)
    Return __QueryInterface($pSelf, $pRIID, $pObj)
EndFunc

Func __MyInterface_AddRef($pSelf)
    Return __AddRef($pSelf)
EndFunc

Func __MyInterface_Release($pSelf)
    Return __Release($pSelf)
EndFunc

Func __MyInterface_Open($pSelf)
    Run("notepad.exe")
    WinWait("[CLASS:Notepad]", "", 10)
    Local $hWnd = WinGetHandle("[CLASS:Notepad]")
    __SetProperty($pSelf, "WinHnd", $hWnd)
    Return 0
EndFunc

Func __MyInterface_Close($pSelf)
    WinClose(__GetProperty($pSelf, "WinHnd"))
    Return 0
EndFunc

Func _ErrFunc()
    ConsoleWrite("! COM Error !  Number: 0x" & Hex($oError.number, 8) & "   ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
    Return
EndFunc   ;==>_ErrFunc

 

Example 3:

#include "ObjFromTag_v1a UDF.au3"

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")

__Example3()
Func __Example3()
    ConsoleWrite("> __Example3() " & @CRLF)
    Local $t_TestObj
    Local $o_TestObj = __ObjectFromTag("__MyInterface_", 'MsgBox hresult();', $t_TestObj, 'char Title[10];char Text[30];int Flag;')
    If Not IsObj($o_TestObj) Then Return

    __SetProperty($o_TestObj, "Title", "Something")
    __SetProperty($o_TestObj, "Text", 'Is it working.')
    __SetProperty($o_TestObj, "Flag", 64 + 262144)

    $o_TestObj.MsgBox()

    If IsObj($o_TestObj) Then $o_TestObj = 0
    __DeleteObjectFromTag($t_TestObj)
    ConsoleWrite("----The End----" & @CRLF)
EndFunc

Func __MyInterface_QueryInterface($pSelf, $pRIID, $pObj)
    Return __QueryInterface($pSelf, $pRIID, $pObj)
EndFunc

Func __MyInterface_AddRef($pSelf)
    Return __AddRef($pSelf)
EndFunc

Func __MyInterface_Release($pSelf)
    Return __Release($pSelf)
EndFunc

Func __MyInterface_MsgBox($pSelf)
    MsgBox(__GetProperty($pSelf, "Flag"), __GetProperty($pSelf, "Title"), __GetProperty($pSelf, "Text"))
EndFunc

Func _ErrFunc()
    ConsoleWrite("! COM Error !  Number: 0x" & Hex($oError.number, 8) & "   ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
    Return
EndFunc   ;==>_ErrFunc

 

 

ObjFromTag_v1a UDF.au3

Edited by jugador

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...