Hello All,
firstly: AutoItObject is awesome, thank you @ProgAndy + Co
Now my question:
I can't seem to call objects registered using _AutoItObject_RegisterObject via Python scripts.
I can however call the same object fine using PHP.
Example code that registers the object Hello.Application:
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include "AutoitObject.au3"
Func Hello($oSelf, $sName)
$sText = "Hello "&$sName&"!"
GUICtrlSetData($nEdit, $sText)
Return $sText
EndFunc
Func Close()
Exit
EndFunc
; Initialize:
_Singleton("Hello")
Opt("TrayIconHide", 1)
Opt("GUIOnEventMode", 1)
; Setup the COM interface:
_AutoItObject_StartUp()
$oObj = _AutoItObject_Class()
$oObj.AddMethod("Hello", "Hello")
$oComObj = $oObj.Object
_AutoItObject_RegisterObject($oComObj, "Hello.Application")
; Show the GUI:
GUICreate("Hello", 400, 45, -1, -1, $WS_CAPTION+$WS_POPUP+$WS_SYSMENU)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
$nEdit = GUICtrlCreateEdit("", 10, 10, 380, 25, $ES_READONLY)
GUISetState(@SW_SHOW)
; Main loop:
While True
Sleep(100)
WEnd
Example PHP code that works with the code above:
<?php
$hello = new COM("Hello.Application");
print $hello->Hello("Fred");
?>
Example Python code that doesn't work for me:
import comtypes.client
hello = comtypes.client.GetActiveObject("Hello.Application")
print hello.Hello("Fred")
I am a Python n00b, so I could easily be doing something wrong.
This Python code does however work if Microsoft Word is running:
import comtypes.client
word = comtypes.client.GetActiveObject("Word.Application")
Any pointers appreciated!