Jump to content

Recommended Posts

  • 3 months later...
Posted

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!

Posted (edited)

The reason it doesn't work is I think you are trying to call an Active Object, instead of creating the object like you do with new COM()l in PHP.

EDIT: Heres your hint:

it however works if Microsoft Word is running:

So, only if there is already a word object running then, it works! So, you'll need to figure out how to create the object in python. ;)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Posted

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.

-snip-

 

Any pointers appreciated!

Hello, Welcome and thank you!

Is it possible for you to try the win32com package instead? I know that worked earlier. >Access AutoIt (<-- example there).

Posted

Thanks @AdmiralClaws! win32com does indeed work:

import win32com.client
hello = win32com.client.GetObject("Hello.Application")
print hello.Hello("Fred")
  • 3 months later...
Posted

i wanted to make some "two layered object" but cannot figure out how...

something like this:

$a1 = $oObj.SomeName.text
$a2 = $oObj.SomeName.filename
$a3 = $oObj.SomeName.width
$a4 = $oObj.SomeName.style

$a5 = $oObj.AnotherName.text
$a6 = $oObj.AnotherName.filename
$a7 = $oObj.AnotherName.width
$a8 = $oObj.AnotherName.style

is it possible?

Posted

This should work, but I've been up for twenty hours so far.  This is also untested.

#include "AutoItObject.au3"

_AutoItObject_Startup()

Global $obj = FirstObj()

$Obj.SomeName.text
$Obj.SomeName.filename
$Obj.SomeName.width
$Obj.SomeName.style

$Obj.AnotherName.text
$Obj.AnotherName.filename
$Obj.AnotherName.width
$Obj.SomeName.style

Func FirstObj()
    Local $this = _AutoItObject_Class()
    
    $this.AddProperty("SomeName", $ELSCOPE_PUBLIC, SomeName())
    
    $this.AddProperty("AnotherName", $ELSCOPE_PUBLIC, AnotherName())
    
    Return $this.Object
EndFunc

Func SomeName()
    Local $this = _AutoItObject_Class()
    
    $this.AddProperty("text", $ELSCOPE_PUBLIC, '')
    $this.AddProperty("filename", $ELSCOPE_PUBLIC, '')
    $this.AddProperty("width", $ELSCOPE_PUBLIC, '')
    $this.AddProperty("style", $ELSCOPE_PUBLIC, '')
    
    Return $this.Object
EndFunc

Func AnotherName()
    Local $this = _AutoItObject_Class()
    
    $this.AddProperty("text", $ELSCOPE_PUBLIC, '')
    $this.AddProperty("filename", $ELSCOPE_PUBLIC, '')
    $this.AddProperty("width", $ELSCOPE_PUBLIC, '')
    $this.AddProperty("style", $ELSCOPE_PUBLIC, '')
    
    Return $this.Object
EndFunc
  • 4 months later...
Posted (edited)

Hi ,

It seems chinese for me. The example are very hard to understand. 

Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

  • 2 months later...
Posted (edited)

Can someone tell me if the following is possible: Set a property equal to the result of an expression based on the values of other properties (upon instantiation)?  The example below doesn't work, but I think it would be the most direct way to achieve my goal if it could work. 

Ideally, _self property should always be correct and accessible immediately after instantiation, without any additional manual commands required to set it. I've thought about creating getter and setter methods, but even then you would need two commands, one to create the object, one to populate the _self property. 

Example: 

Func _FolderHolder()
    Local $oClassObject = _AutoItObject_Class()
    With $oClassObject
        .Create()
        .AddProperty("path", $ELSCOPE_PUBLIC, @ScriptDir)
        .AddProperty("id", $ELSCOPE_PUBLIC, "Folder1")
        .AddProperty("_self", $ELSCOPE_PRIVATE, $oClassObject.path & "\" & $oClassObject.self)
    EndWith
    Return $oClassObject.Object
EndFunc

 

Edited by redrider81
Posted (edited)

A perfectly acceptible workaround came to me , but of course only after I posted the question in the forum (See below). 

However, the question still warrants an answer however if anyone has time. I'm sure this could become an undesirable workaround in some cases.
    

Func _FolderHolder($sPath = @ScriptDir, $sId = "Folder1")
   Local $oClassObject = _AutoItObject_Class()
   With $oClassObject
      .Create()
      .AddProperty("path", $ELSCOPE_PUBLIC, $sPath)
      .AddProperty("id", $ELSCOPE_PUBLIC, $sId)
      .AddProperty("_self", $ELSCOPE_PRIVATE, $sPath & "\" & $sId)
   EndWith
   Return $oClassObject.Object
EndFunc

 

Edited by redrider81
Posted (edited)

Can anyone from the core team indicate if there is an elegant/easy method to do one of the following: 

Convert object directly to JSON string?

Convert an object to any format of string? 

Return the properties of the object as an array or delimited string?

Return the class name of the object created as a string? 

I'm trying to exchange my objects with ozmikes OO_JSON.au3 UDF . 

Thanks in advance. 

Edited by redrider81
Posted

I suppose you want to exchange objects definitions. The definition of the object it may be converted to a nice format but how would you deal with the methods implementation?

Posted

Good question, and one I had thought about.  I was just going to ignore them for my implementation because the only methods my AutoIt objects have are methods that save and retrieve data from the file system, and the only thing I'm doing with JSON objects is sending/receiving the properties. I don't have any dynamic JS methods to deal with. Thats fortunate... because to deal with the methods the proper way, would require something crazy, like creating a library that actually translates javascript functions to autoit functions and back. No way Jose.  

If I were to do that, I would more likely just do the program using pure OO_JSON, and make my methods JS methods,  and not even using AutoIt objects or functions.  To be honest, I would have done this already, but I don't know Javascript. I also was uncertain if dynamic JS methods in the OO_JSON framework could do all the same things that custom functions can do with AutoIt Objects. 

  • 1 month later...
Posted

Is this project still being developed? 

AutoItObject.au3 Line: 1162 

Func _AutoItObject_AddMethod(ByRef $oObject, $sName, $sAutoItFunc, $fPrivate = False)
    ; Author: Prog@ndy
    If Not IsObj($oObject) Then Return SetError(2, 0, 0)
    Local $iFlags = 0

    If $fPrivate Then $iFlags = $ELSCOPE_PRIVATE

    DllCall($ghAutoItObjectDLL, "none", "AddMethod", "idispatch", $oObject, "wstr", $sName, "wstr", $sAutoItFunc, 'dword', $iFlags)
    If @error Then Return SetError(1, @error, 0)
    Return True
EndFunc   ;==>_AutoItObject_AddMethod

Why not do this instead?

Func _AutoItObject_AddMethod(ByRef $oObject, $sName, $sAutoItFunc, $iFlags= $ELSCOPE_PUBLIC)
    ; Author: Prog@ndy
    If Not IsObj($oObject) Then Return SetError(2, 0, 0)
    DllCall($ghAutoItObjectDLL, "none", "AddMethod", "idispatch", $oObject, "wstr", $sName, "wstr", $sAutoItFunc, 'dword', $iFlags)
    If @error Then Return SetError(1, @error, 0)
    Return True
EndFunc   ;==>_AutoItObject_AddMethod
Posted

Is this project still being developed? 

Considering the multiple years with no updates I think it's safe to assume no. Notice how the OP doesn't even have the latest version?

Of course, if anybody wanted to continue it, the source code is still around.

Posted (edited)

Hmm, im having trouble iterating through an unkown size object, for in dosent seem to work so good, is a linked list the only way to go here?

 

 

Edit: stupid me, i didnt have anything to enumerate through... I used TicTacToes Linkedlist for ez use

Edited by tarretarretarre
  • 4 months later...
Posted

_AutoItObject_Startup() crashes immediatly executed under Autoit3_x64.exe (not under Autoit3.exe) with c0000005 (access violation):

#include <AutoItObject.au3>
_AutoItObject_Startup()
Sleep(2000)
_AutoItObject_Shutdown()

Environment:

OS: Win 10, 64 bit
AutoIt: 3.3.14.2
AutoItObject: 1.2.8.2

UDFS & Apps:

Spoiler

DDEML.au3 - DDE Client + Server
Localization.au3 - localize your scripts
TLI.au3 - type information on COM objects (TLBINF emulation)
TLBAutoEnum.au3 - auto-import of COM constants (enums)
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector - OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

  • 1 month later...
Posted (edited)

As this UDF no longer lives, there is a recent initiative from Minxomat to implement advanced OOP in AutoIT.

Edited by pedrit0
format

Pedrit0, calme et tranquille, la tete dans les nuages et la b*** dans le champagne.

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...