OLE automation: Difference between revisions

Content added Content deleted
(Added Wren)
m (syntax highlighting fixup automation)
Line 15: Line 15:


client: using the ahk ole server as well as the python ole server implemented below
client: using the ahk ole server as well as the python ole server implemented below
<lang autohotkey>ahk := comobjactive("ahkdemo.ahk")
<syntaxhighlight lang="autohotkey">ahk := comobjactive("ahkdemo.ahk")
ahk.hello("hello world")
ahk.hello("hello world")
py := ComObjActive("python.server")
py := ComObjActive("python.server")
py.write("hello")
py.write("hello")
return</lang>
return</syntaxhighlight>
server:
server:
<lang autohotkey>#Persistent
<syntaxhighlight lang="autohotkey">#Persistent
CLSID_ThisScript := "{38A3EB13-D0C4-478b-9720-4D0B2D361DB9}"
CLSID_ThisScript := "{38A3EB13-D0C4-478b-9720-4D0B2D361DB9}"
APPID_ThisScript := "ahkdemo.ahk"
APPID_ThisScript := "ahkdemo.ahk"
Line 76: Line 76:
#include lib\ComDispTable.ahk
#include lib\ComDispTable.ahk
#include lib\ComDispatch.ahk
#include lib\ComDispatch.ahk
#include lib\ComVar.ahk</lang>
#include lib\ComVar.ahk</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
Line 83: Line 83:
<br>
<br>
This uses OLE automation to create a new Microsoft Word document, write some text to it and after 10 seconds close the document without saving and quit Word.
This uses OLE automation to create a new Microsoft Word document, write some text to it and after 10 seconds close the document without saving and quit Word.
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 112: Line 112:


ole.CoUninitialize()
ole.CoUninitialize()
}</lang>
}</syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
Line 118: Line 118:


We can use Events, from declared objects and from objects that we get as result from methods, using WithEvents.
We can use Events, from declared objects and from objects that we get as result from methods, using WithEvents.
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckAutomation {
Module CheckAutomation {
ExitNow=false
ExitNow=false
Line 150: Line 150:
}
}
CheckAutomation
CheckAutomation
</syntaxhighlight>
</lang>


=={{header|Phix}}==
=={{header|Phix}}==
Line 160: Line 160:
Server uses a client of the ahk server above to register the clsid in the windows registry.
Server uses a client of the ahk server above to register the clsid in the windows registry.
Translated from <tt>win32com/test/testDynamic.py</tt>
Translated from <tt>win32com/test/testDynamic.py</tt>
<lang python>#!/usr/bin/env python
<syntaxhighlight lang="python">#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import win32com.client
import win32com.client
Line 215: Line 215:
# autohotkey.exe ahkside.ahk
# autohotkey.exe ahkside.ahk
# python /c/Python26/Scripts/ipython.py -wthread -i pythonside.py
# python /c/Python26/Scripts/ipython.py -wthread -i pythonside.py
# must use -wthread otherwise calling com client hangs</lang>
# must use -wthread otherwise calling com client hangs</syntaxhighlight>
client
client
<lang Python>import win32com.client
<syntaxhighlight lang="python">import win32com.client
client = win32com.client.Dispatch("python.server")
client = win32com.client.Dispatch("python.server")
client.write("hello world")</lang>
client.write("hello world")</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
Line 227: Line 227:
{{works with|Windows 10}}
{{works with|Windows 10}}
An embedded application with a Go host so we can use the Go OLE library.
An embedded application with a Go host so we can use the Go OLE library.
<lang ecmascript>/* OLE_automation.wren */
<syntaxhighlight lang="ecmascript">/* OLE_automation.wren */


class Ole {
class Ole {
Line 282: Line 282:
IUnknown.release(word)
IUnknown.release(word)


Ole.coUninitialize()</lang>
Ole.coUninitialize()</syntaxhighlight>
<br>
<br>
We now embed this script in the following Go program and run it.
We now embed this script in the following Go program and run it.
<lang go>/* go run OLE_automation.go */
<syntaxhighlight lang="go">/* go run OLE_automation.go */


package main
package main
Line 424: Line 424:
vm.InterpretFile(fileName)
vm.InterpretFile(fileName)
vm.Free()
vm.Free()
}</lang>
}</syntaxhighlight>


{{omit from|Ada|Too involved to implement from scratch, and OS specific}}
{{omit from|Ada|Too involved to implement from scratch, and OS specific}}