Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
56
Task/OLE-automation/Wren/ole-automation-1.wren
Normal file
56
Task/OLE-automation/Wren/ole-automation-1.wren
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* OLE_automation.wren */
|
||||
|
||||
class Ole {
|
||||
foreign static coInitialize(p)
|
||||
foreign static coUninitialize()
|
||||
}
|
||||
|
||||
class OleUtil {
|
||||
static createObject(programID) {
|
||||
return IUnknown.new(programID)
|
||||
}
|
||||
|
||||
foreign static putProperty(disp, name, param)
|
||||
foreign static mustGetProperty(disp, name)
|
||||
foreign static mustCallMethod(disp, name)
|
||||
foreign static mustCallMethod2(disp, name, param)
|
||||
}
|
||||
|
||||
foreign class GUID {
|
||||
construct new(guid) {}
|
||||
}
|
||||
|
||||
var IID_DISPATCH = GUID.new("{00020400-0000-0000-C000-000000000046}")
|
||||
|
||||
foreign class IUnknown {
|
||||
construct new(programID) {}
|
||||
|
||||
foreign queryInterface(iid, name)
|
||||
foreign static release(name)
|
||||
}
|
||||
|
||||
class Time {
|
||||
foreign static sleep(secs)
|
||||
}
|
||||
|
||||
Ole.coInitialize(0)
|
||||
var unknown = OleUtil.createObject("Word.application")
|
||||
var word = unknown.queryInterface(IID_DISPATCH, "word")
|
||||
OleUtil.putProperty(word, "Visible", true)
|
||||
var documents = OleUtil.mustGetProperty(word, "Documents")
|
||||
var document = OleUtil.mustCallMethod(documents, "Add")
|
||||
var content = OleUtil.mustGetProperty(document, "Content")
|
||||
var paragraphs = OleUtil.mustGetProperty(content, "Paragraphs")
|
||||
var paragraph = OleUtil.mustCallMethod(paragraphs, "Add")
|
||||
var range = OleUtil.mustGetProperty(paragraph, "Range")
|
||||
|
||||
OleUtil.putProperty(range, "Text", "This is a Rosetta Code test document.")
|
||||
|
||||
Time.sleep(10)
|
||||
|
||||
OleUtil.putProperty(document, "Saved", true)
|
||||
OleUtil.mustCallMethod2(document, "Close", false)
|
||||
OleUtil.mustCallMethod(word, "Quit")
|
||||
IUnknown.release(word)
|
||||
|
||||
Ole.coUninitialize()
|
||||
140
Task/OLE-automation/Wren/ole-automation-2.wren
Normal file
140
Task/OLE-automation/Wren/ole-automation-2.wren
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/* go run OLE_automation.go */
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
ole "github.com/go-ole/go-ole"
|
||||
"github.com/go-ole/go-ole/oleutil"
|
||||
"strings"
|
||||
"time"
|
||||
wren "github.com/crazyinfin8/WrenGo"
|
||||
)
|
||||
|
||||
type any = interface{}
|
||||
|
||||
var dispMap = make(map[string]*ole.IDispatch)
|
||||
|
||||
func coInitialize(vm *wren.VM, parameters []any) (any, error) {
|
||||
p := uintptr(parameters[1].(float64))
|
||||
ole.CoInitialize(p)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func coUninitialize(vm *wren.VM, parameters []any) (any, error) {
|
||||
ole.CoUninitialize()
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func putProperty(vm *wren.VM, parameters []any) (any, error) {
|
||||
disp := dispMap[parameters[1].(string)]
|
||||
propName := parameters[2].(string)
|
||||
param := parameters[3]
|
||||
oleutil.PutProperty(disp, propName, param)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func mustGetProperty(vm *wren.VM, parameters []any) (any, error) {
|
||||
disp := dispMap[parameters[1].(string)]
|
||||
propName := parameters[2].(string)
|
||||
disp2 := oleutil.MustGetProperty(disp, propName).ToIDispatch()
|
||||
disp2Name := strings.ToLower(propName)
|
||||
dispMap[disp2Name] = disp2
|
||||
return disp2Name, nil
|
||||
}
|
||||
|
||||
func mustCallMethod(vm *wren.VM, parameters []any) (any, error) {
|
||||
dispName := parameters[1].(string)
|
||||
disp := dispMap[dispName]
|
||||
methName := parameters[2].(string)
|
||||
disp2 := oleutil.MustCallMethod(disp, methName).ToIDispatch()
|
||||
disp2Name := dispName[0:len(dispName)-1]
|
||||
dispMap[disp2Name] = disp2
|
||||
return disp2Name, nil
|
||||
}
|
||||
|
||||
func mustCallMethod2(vm *wren.VM, parameters []any) (any, error) {
|
||||
dispName := parameters[1].(string)
|
||||
disp := dispMap[dispName]
|
||||
methName := parameters[2].(string)
|
||||
param := parameters[3]
|
||||
disp2 := oleutil.MustCallMethod(disp, methName, param).ToIDispatch()
|
||||
disp2Name := dispName[0:len(dispName)-1]
|
||||
dispMap[disp2Name] = disp2
|
||||
return disp2Name, nil
|
||||
}
|
||||
|
||||
func newGUID(vm *wren.VM, parameters []any) (any, error) {
|
||||
param := parameters[1].(string)
|
||||
guid := ole.NewGUID(param)
|
||||
return &guid, nil
|
||||
}
|
||||
|
||||
func newIUnknown(vm *wren.VM, parameters []any) (any, error) {
|
||||
programID := parameters[1].(string)
|
||||
unknown, _ := oleutil.CreateObject(programID)
|
||||
return &unknown, nil
|
||||
}
|
||||
|
||||
func queryInterface(vm *wren.VM, parameters []any) (any, error) {
|
||||
handle := parameters[0].(*wren.ForeignHandle)
|
||||
ifc, _ := handle.Get()
|
||||
unknown := ifc.(**ole.IUnknown)
|
||||
handle2 := parameters[1].(*wren.ForeignHandle)
|
||||
ifc2, _ := handle2.Get()
|
||||
guid := ifc2.(**ole.GUID)
|
||||
disp, _ := (*unknown).QueryInterface(*guid)
|
||||
name := parameters[2].(string)
|
||||
dispMap[name] = disp
|
||||
return name, nil
|
||||
}
|
||||
|
||||
func release(vm *wren.VM, parameters []any) (any, error) {
|
||||
unknown := dispMap[parameters[1].(string)]
|
||||
unknown.Release()
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func sleep(vm *wren.VM, parameters []any) (any, error) {
|
||||
secs := time.Duration(parameters[1].(float64))
|
||||
time.Sleep(secs * time.Second)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
vm := wren.NewVM()
|
||||
fileName := "OLE_automation.wren"
|
||||
|
||||
oleMethodMap := wren.MethodMap {
|
||||
"static coInitialize(_)" : coInitialize,
|
||||
"static coUninitialize()": coUninitialize,
|
||||
}
|
||||
|
||||
oleUtilMethodMap := wren.MethodMap {
|
||||
"static putProperty(_,_,_)" : putProperty,
|
||||
"static mustGetProperty(_,_)" : mustGetProperty,
|
||||
"static mustCallMethod(_,_)" : mustCallMethod,
|
||||
"static mustCallMethod2(_,_,_)": mustCallMethod2,
|
||||
}
|
||||
|
||||
iUnknownMethodMap := wren.MethodMap {
|
||||
"queryInterface(_,_)": queryInterface,
|
||||
"static release(_)" : release,
|
||||
}
|
||||
|
||||
timeMethodMap := wren.MethodMap {
|
||||
"static sleep(_)": sleep,
|
||||
}
|
||||
|
||||
classMap := wren.ClassMap {
|
||||
"Ole" : wren.NewClass(nil, nil, oleMethodMap),
|
||||
"OleUtil" : wren.NewClass(nil, nil, oleUtilMethodMap),
|
||||
"GUID" : wren.NewClass(newGUID, nil, nil),
|
||||
"IUnknown" : wren.NewClass(newIUnknown, nil, iUnknownMethodMap),
|
||||
"Time" : wren.NewClass(nil, nil, timeMethodMap),
|
||||
}
|
||||
|
||||
module := wren.NewModule(classMap)
|
||||
vm.SetModule(fileName, module)
|
||||
vm.InterpretFile(fileName)
|
||||
vm.Free()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue