本文整理汇总了Golang中github.com/mattn/go-ole/oleutil.CreateObject函数的典型用法代码示例。如果您正苦于以下问题:Golang CreateObject函数的具体用法?Golang CreateObject怎么用?Golang CreateObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Prepare
func (c *AdodbConn) Prepare(query string) (driver.Stmt, error) {
unknown, err := oleutil.CreateObject("ADODB.Command")
if err != nil {
return nil, err
}
s, err := unknown.QueryInterface(ole.IID_IDispatch)
if err != nil {
return nil, err
}
_, err = oleutil.PutProperty(s, "ActiveConnection", c.db)
if err != nil {
return nil, err
}
_, err = oleutil.PutProperty(s, "CommandText", query)
if err != nil {
return nil, err
}
_, err = oleutil.PutProperty(s, "CommandType", 1)
if err != nil {
return nil, err
}
_, err = oleutil.PutProperty(s, "Prepared", true)
if err != nil {
return nil, err
}
val, err := oleutil.GetProperty(s, "Parameters")
if err != nil {
return nil, err
}
return &AdodbStmt{c, s, val.ToIDispatch(), nil}, nil
}
示例2: connect
func (c *win_wmi_collector) connect() (err error) {
// use COINIT_MULTITHREADED model
ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator")
if err != nil {
logging.Critical("oleutil.CreateObject Failed: ", err)
return err
}
defer unknown.Release()
wmi, err := unknown.QueryInterface(ole.IID_IDispatch)
if err != nil {
logging.Critical("QueryInterface Failed: ", err)
return err
}
defer wmi.Release()
serviceRaw, err := oleutil.CallMethod(wmi, "ConnectServer")
if err != nil {
logging.Critical("Connect to Server Failed", err)
return err
}
c.service = serviceRaw.ToIDispatch()
return nil
}
示例3: main
func main() {
ole.CoInitialize(0)
unknown, _ := oleutil.CreateObject("Microsoft.XMLHTTP")
xmlhttp, _ := unknown.QueryInterface(ole.IID_IDispatch)
oleutil.CallMethod(xmlhttp, "open", "GET", "http://rss.slashdot.org/Slashdot/slashdot", false)
oleutil.CallMethod(xmlhttp, "send", nil)
state := -1
for state != 4 {
state = int(oleutil.MustGetProperty(xmlhttp, "readyState").Val)
time.Sleep(10000000)
}
responseXml := oleutil.MustGetProperty(xmlhttp, "responseXml").ToIDispatch()
items := oleutil.MustCallMethod(responseXml, "selectNodes", "rdf:RDF/item").ToIDispatch()
length := int(oleutil.MustGetProperty(items, "length").Val)
for n := 0; n < length; n++ {
item := oleutil.MustGetProperty(items, "item", n).ToIDispatch()
title := oleutil.MustCallMethod(item, "selectSingleNode", "title").ToIDispatch()
println(oleutil.MustGetProperty(title, "text").ToString())
link := oleutil.MustCallMethod(item, "selectSingleNode", "link").ToIDispatch()
println(" " + oleutil.MustGetProperty(link, "text").ToString())
title.Release()
link.Release()
item.Release()
}
items.Release()
xmlhttp.Release()
}
示例4: main
func main() {
ole.CoInitialize(0)
unknown, _ := oleutil.CreateObject("{248DD896-BB45-11CF-9ABC-0080C7E7B78D}")
winsock, _ := unknown.QueryInterface(ole.IID_IDispatch)
iid, _ := ole.CLSIDFromString("{248DD893-BB45-11CF-9ABC-0080C7E7B78D}")
dest := &EventReceiver{}
dest.lpVtbl = &EventReceiverVtbl{}
dest.lpVtbl.pQueryInterface = syscall.NewCallback(QueryInterface)
dest.lpVtbl.pAddRef = syscall.NewCallback(AddRef)
dest.lpVtbl.pRelease = syscall.NewCallback(Release)
dest.lpVtbl.pGetTypeInfoCount = syscall.NewCallback(GetTypeInfoCount)
dest.lpVtbl.pGetTypeInfo = syscall.NewCallback(GetTypeInfo)
dest.lpVtbl.pGetIDsOfNames = syscall.NewCallback(GetIDsOfNames)
dest.lpVtbl.pInvoke = syscall.NewCallback(Invoke)
dest.host = winsock
oleutil.ConnectObject(winsock, iid, (*ole.IUnknown)(unsafe.Pointer(dest)))
_, err := oleutil.CallMethod(winsock, "Connect", "127.0.0.1", 80)
if err != nil {
log.Fatal(err)
}
var m ole.Msg
for dest.ref != 0 {
ole.GetMessage(&m, 0, 0, 0)
ole.DispatchMessage(&m)
}
}
示例5: New
func (this *Excel) New() (e *Excel, err error) {
ole.CoInitialize(0)
this.Excel_obj, _ = oleutil.CreateObject("Excel.Application")
this.Excel, _ = this.Excel_obj.QueryInterface(ole.IID_IDispatch)
if this.Excel == nil {
errors.New("error: Cant't Open excel.")
}
version := oleutil.MustGetProperty(this.Excel, "Version").ToString()
this.Version = version
oleutil.PutProperty(this.Excel, "Visible", this.Visible)
oleutil.PutProperty(this.Excel, "DisplayAlerts", this.DisplayAlerts)
oleutil.PutProperty(this.Excel, "ScreenUpdating", this.ScreenUpdating)
this.Workbooks = oleutil.MustGetProperty(this.Excel, "WorkBooks").ToIDispatch()
oleutil.MustCallMethod(this.Workbooks, "Add").ToIDispatch()
return this, err
}
示例6: open
func (pt *PowerPoint) open(inFile string) (err error) {
ole.CoInitialize(0)
var unknown *ole.IUnknown
unknown, err = oleutil.CreateObject("PowerPoint.Application")
if err != nil {
return
}
pt.app, err = unknown.QueryInterface(ole.IID_IDispatch)
if err != nil {
return
}
_, err = oleutil.PutProperty(pt.app, "DisplayAlerts", 1)
if err != nil {
return
}
pt.presentations, err = oleutil.GetProperty(pt.app, "Presentations")
if err != nil {
return
}
pt.ppt, err = oleutil.CallMethod(pt.presentations.ToIDispatch(), "Open", inFile, -1, 0, 0)
if err != nil {
return
}
return
}
示例7: getFriendlyName
func getFriendlyName(portname string) string {
// this method panics a lot and i'm not sure why, just catch
// the panic and return empty list
defer func() {
if e := recover(); e != nil {
// e is the interface{} typed-value we passed to panic()
log.Println("Got panic: ", e) // Prints "Whoops: boom!"
}
}()
var friendlyName string
// init COM, oh yeah
ole.CoInitialize(0)
defer ole.CoUninitialize()
unknown, _ := oleutil.CreateObject("WbemScripting.SWbemLocator")
defer unknown.Release()
wmi, _ := unknown.QueryInterface(ole.IID_IDispatch)
defer wmi.Release()
// service is a SWbemServices
serviceRaw, _ := oleutil.CallMethod(wmi, "ConnectServer")
service := serviceRaw.ToIDispatch()
defer service.Release()
// result is a SWBemObjectSet
//pname := syscall.StringToUTF16("SELECT * FROM Win32_PnPEntity where Name like '%" + "COM35" + "%'")
pname := "SELECT * FROM Win32_PnPEntity where Name like '%" + portname + "%'"
resultRaw, _ := oleutil.CallMethod(service, "ExecQuery", pname)
result := resultRaw.ToIDispatch()
defer result.Release()
countVar, _ := oleutil.GetProperty(result, "Count")
count := int(countVar.Val)
for i := 0; i < count; i++ {
// item is a SWbemObject, but really a Win32_Process
itemRaw, _ := oleutil.CallMethod(result, "ItemIndex", i)
item := itemRaw.ToIDispatch()
defer item.Release()
asString, _ := oleutil.GetProperty(item, "Name")
println(asString.ToString())
friendlyName = asString.ToString()
}
return friendlyName
}
示例8: main
func main() {
ole.CoInitialize(0)
unknown, _ := oleutil.CreateObject("Agent.Control.1")
agent, _ := unknown.QueryInterface(ole.IID_IDispatch)
oleutil.PutProperty(agent, "Connected", true)
characters := oleutil.MustGetProperty(agent, "Characters").ToIDispatch()
oleutil.CallMethod(characters, "Load", "Merlin", "c:\\windows\\msagent\\chars\\Merlin.acs")
character := oleutil.MustCallMethod(characters, "Character", "Merlin").ToIDispatch()
oleutil.CallMethod(character, "Show")
oleutil.CallMethod(character, "Speak", "こんにちわ世界")
time.Sleep(4000000000)
}
示例9: createMdb
func createMdb(f string) error {
unk, err := oleutil.CreateObject("ADOX.Catalog")
if err != nil {
return err
}
cat, err := unk.QueryInterface(ole.IID_IDispatch)
if err != nil {
return err
}
_, err = oleutil.CallMethod(cat, "Create", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+f+";")
if err != nil {
return err
}
return nil
}
示例10: Open
func (d *AdodbDriver) Open(dsn string) (driver.Conn, error) {
ole.CoInitialize(0)
unknown, err := oleutil.CreateObject("ADODB.Connection")
if err != nil {
return nil, err
}
db, err := unknown.QueryInterface(ole.IID_IDispatch)
if err != nil {
return nil, err
}
_, err = oleutil.CallMethod(db, "Open", dsn)
if err != nil {
return nil, err
}
return &AdodbConn{db}, nil
}
示例11: main
func main() {
ole.CoInitialize(0)
unknown, _ := oleutil.CreateObject("Excel.Application")
excel, _ := unknown.QueryInterface(ole.IID_IDispatch)
oleutil.PutProperty(excel, "Visible", true)
workbooks := oleutil.MustGetProperty(excel, "Workbooks").ToIDispatch()
workbook := oleutil.MustCallMethod(workbooks, "Add", nil).ToIDispatch()
Worksheets := oleutil.MustGetProperty(workbook, "Worksheets", 1).ToIDispatch()
cell := oleutil.MustGetProperty(Worksheets, "Cells", 1, 1).ToIDispatch()
oleutil.PutProperty(cell, "Value", 12345)
time.Sleep(2000000000)
oleutil.PutProperty(workbook, "Saved", true)
oleutil.CallMethod(excel, "Quit")
excel.Release()
}
示例12: main
func main() {
ole.CoInitialize(0)
unknown, err := oleutil.CreateObject("WMPlayer.OCX")
if err != nil {
log.Fatal(err)
}
wmp := unknown.MustQueryInterface(ole.IID_IDispatch)
collection := oleutil.MustGetProperty(wmp, "MediaCollection").ToIDispatch()
list := oleutil.MustCallMethod(collection, "getAll").ToIDispatch()
count := int(oleutil.MustGetProperty(list, "count").Val)
for i := 0; i < count; i++ {
item := oleutil.MustGetProperty(list, "item", i).ToIDispatch()
name := oleutil.MustGetProperty(item, "name").ToString()
sourceURL := oleutil.MustGetProperty(item, "sourceURL").ToString()
fmt.Println(name, sourceURL)
}
}
示例13: main
func main() {
ole.CoInitialize(0)
unknown, _ := oleutil.CreateObject("InternetExplorer.Application")
ie, _ := unknown.QueryInterface(ole.IID_IDispatch)
oleutil.CallMethod(ie, "Navigate", "http://www.google.com")
oleutil.PutProperty(ie, "Visible", true)
for {
if oleutil.MustGetProperty(ie, "Busy").Val == 0 {
break
}
}
time.Sleep(1e9)
document := oleutil.MustGetProperty(ie, "document").ToIDispatch()
window := oleutil.MustGetProperty(document, "parentWindow").ToIDispatch()
// set 'golang' to text box.
oleutil.MustCallMethod(window, "eval", "document.getElementsByName('q')[0].value = 'golang'")
// click btnG.
btnG := oleutil.MustCallMethod(window, "eval", "document.getElementsByName('btnG')[0]").ToIDispatch()
oleutil.MustCallMethod(btnG, "click")
}
示例14: open
func (wd *Word) open(inFile string) (err error) {
ole.CoInitialize(0)
var unknown *ole.IUnknown
unknown, err = oleutil.CreateObject("Word.Application")
if err != nil {
return
}
wd.app, err = unknown.QueryInterface(ole.IID_IDispatch)
if err != nil {
return
}
_, err = oleutil.PutProperty(wd.app, "Visible", false)
if err != nil {
return
}
_, err = oleutil.PutProperty(wd.app, "DisplayAlerts", 0)
if err != nil {
return
}
wd.documents, err = oleutil.GetProperty(wd.app, "Documents")
if err != nil {
return
}
wd.doc, err = oleutil.CallMethod(wd.documents.ToIDispatch(), "Open", inFile)
if err != nil {
return
}
return
}
示例15: init
func init() {
ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator")
if err != nil {
logging.Criticalf("oleutil.CreateObject Failed: %v", err)
panic(err)
}
defer unknown.Release()
wmi, err := unknown.QueryInterface(ole.IID_IDispatch)
if err != nil {
logging.Criticalf("QueryInterface Failed: %v", err)
panic(err)
}
defer wmi.Release()
serviceRaw, err := oleutil.CallMethod(wmi, "ConnectServer")
if err != nil {
logging.Criticalf("Connect to Server Failed: %v", err)
panic(err)
}
wmi_service = serviceRaw.ToIDispatch()
}