Jump to content
Sign in to follow this  
Michel Claveau

Simili COM server in AutoIt-GUI (with Python help)

Recommended Posts

Hi! (sorry for my bad english)

Thanks to

. AutoIt team

. Piccaso for WM_COPYDATA usage

. Livewire for the DLL for use Memory-Mapped-File in AutoIt

. Python team

. Mark Hammond for PyWin32

It's not a really COM-server in AutoIt.

It's limited.

In the fact, it's a dynamic server COM, in Python, which makes bridge with a special Autoit window

Need :

Python (2.4 or 2.5)

see: http://www.python.org/download/ (choose windows-installer)

or: http://www.ponx.org/download/CD/Python/python-2.5.1.msi

PyWin32

see: http://sourceforge.net/project/platformdow...?group_id=78018

or: http://www.ponx.org/download/CD/Python/pyw...win32-py2.5.exe

or ActivePython (from ActiveState) ; this distribution contain Python AND Pywin32

see: http://www.activestate.com/Products/activepython/index.plex

autoitmmap.dll (it's my release of the DLL or Livewire (see Autoit-forums))

Install:

create a directory (I suggest C:\Ponx)

copy, in this directory, the file pbautoit.py

in command-line, launch pbautoit.py

(must answer :

Enregistrement du server COM pbridge.autoit version 1.0

Registered: pbridge.autoit

)

copy in your disk, pbautoit1.au3 (I suggest C:\Ponx, but it's as you want)

in the same directory, copy autoitmmap.dll

It's all! Try examples.

Principe.

When you call a function of the COM-server, pbridge.autoit translate arguments

to strings (in cp1252), and call a windows-message (WM_COPYDATA) to the

autoit-window.

The "return" problem.

pbridge.autoit no have window ; cannot read windows-messages. The way for get

return values from AutoIt is Memory-Mapped-File (a DLL in AutoIt, mmap module

with Python)

But pbridge.autoit is not trigged, when values are availables. Then pbridge.autoit

try after 0.01 second, well each 0.1 second, during 30 s (this timeout will can

change).

A smart (?) stunt : for call who don't want return values, it's possible to

prefix the call(name)) with "NORETURN_" (this prefix is delete, for the internal

call to AutoIt)

Others :

All call names (functions) are translated in uppercase ; this, because some

languages don't distinguish case, and COM calls are perhaps upper- or perhaps lower- (for

example VB-script)

No TLB (TypeLiBrary) ; it's a dynamic COM server. It's the capability to use

functions declared after his launch. This is not compatible with static server

(& TLB).

Possible functions : in theory, any user functions callable into the Autoit-window

can be called by the client.

But some contraints : all parameters (including Unicode objects) are translated

in string (in cp1252) ; cannot include "|||" (separator) ; max length call :

32767 caracters ; don't use esapece in names ; don't use reserved names ; etc.

Only one predfined function :

autoitload(path,file)

load (open) the window of AutoIt-simili-serveur ; try during 5 secondes, then error

return : handle of window, or -1 if error

examples :

a.autoitload("D:\\dev\\autoit","pbautoit1.au3")

a.autoitload("C:\\autoit","pbautoit1.exe")

See attachment (file pbautoit.zip)

Edited by Michel Claveau

Share this post


Link to post
Share on other sites

Some examples of use :

in vb script:

Set auto = WScript.CreateObject("pbridge.autoit")

auto.autoitload "C:\ponx","pbautoit1.au3"
auto.message "Azërtyuiop" 

result = auto.addition(10000,234,432)
WScript.Echo CStr(result)

result = auto.splashtext("Tittrree","Wouaaaahhh!!!  A splash-text.",2000)
WScript.Echo CStr(result)

auto.noreturn_close()

in JScript:

auto = new ActiveXObject("pbridge.autoit");

auto.autoitload("C:\\ponx","pbautoit1.au3");
auto.message("Azërtyuiop");

result=auto.addition(10000,234,432);
WScript.Echo(result);

result=auto.splashtext("Tittrree","Wouaaaahhh!!!  A splash-text.",2000);
WScript.Echo(result);

auto.noreturn_close();

in Python:

# -*- coding: cp1252 -*-

import win32com.client,time,os,sys
aut = win32com.client.Dispatch('pbridge.autoit')

aut.autoitload("C:\\ponx","pbautoit1.au3")
print aut.message("Azërtyuiop")
print aut.addition(10000,234,432)
print aut.titi()   #this function is undefined (for test Error)
print aut.splashtest1()  #call with wait
aut.noreturn_splashtest1()  #same call, but return immediately
print "Retour immédiat."
#time.sleep(4)  #for wait the end a splastest1
print aut.splashtext("Tittrree","Wouaaaahhh!!!  A splash-text.",2000)
aut.noreturn_close()

in HTA (+JScript):

<hta:application
 application navigable="yes"
 windowstate="normal"
 caption="yes"
  />
<html>
<head><title>Test: Bridge Autoit</title>
<script type='text/javascript'>
function test(){
    self.resizeTo(300,200);
    self.moveTo(20,10);

    auto = new ActiveXObject("pbridge.autoit");

    auto.autoitload("C:\\ponx","pbautoit1.au3");
    result=auto.message("Azërtyuiop");
    document.write(result);
    document.write("<br>");

    result=auto.addition(10000,234,432);
    document.write(result);
    document.write("<br>");

    result = auto.splashtext("Tittrree","Wouaaaahhh!!!  A splash-text.",2000);
    document.write(result);
    document.write("<br>");

    auto.noreturn_close();
}
</script>

</head>

<body bgColor=#eeffff>
Test de Bridge Autoit<br>

<script type='text/javascript'>
setTimeout("test()",100);
</script>

</body>
</html>

...and, why not, in AutoIt:

$auto = ObjCreate("pbridge.autoit")

$auto.autoitload("C:\\ponx","pbautoit1.au3")
$auto.message("Azërtyuiop")

$result = $auto.addition(10000,234,432)
msgbox(0,"Addition",$result)

$result = $auto.splashtext("Tittrree","Wouaaaahhh!!!  A splash-text.",1000)
msgbox(0,"Addition",$result)

$auto.noreturn_close();
Edited by Michel Claveau

Share this post


Link to post
Share on other sites

Hi, ptrex!

Sorry, it's little different: it's a true COM-server, with a bridge to a AutoIt-window.

The communication ways of the bridge are : message(WM-COPYDATA) for call & Memory-File-Mapped (with a DLL) for get return-values.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×
×
  • Create New...