当前位置: 首页>>代码示例>>Golang>>正文


Golang oleutil.CreateObject函数代码示例

本文整理汇总了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
}
开发者ID:kleopatra999,项目名称:go-adodb,代码行数:31,代码来源:adodb.go

示例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
}
开发者ID:homingway,项目名称:hickwall,代码行数:27,代码来源:wmi_windows.go

示例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()
}
开发者ID:xushiwei,项目名称:go-ole,代码行数:31,代码来源:rssreader.go

示例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)
	}
}
开发者ID:piaobocpp,项目名称:doc2pdf-go,代码行数:30,代码来源:winsock.go

示例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
}
开发者ID:ArseneXie,项目名称:excel,代码行数:20,代码来源:excel.go

示例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
}
开发者ID:nzheyuti,项目名称:doc2pdf-nodejs,代码行数:33,代码来源:powerpoint_windows.go

示例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
}
开发者ID:BOHICAMAN,项目名称:serial-port-json-server,代码行数:52,代码来源:seriallist_windows.go

示例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)
}
开发者ID:xushiwei,项目名称:go-ole,代码行数:13,代码来源:msagent.go

示例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
}
开发者ID:hinike,项目名称:go-adodb,代码行数:15,代码来源:mdb.go

示例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
}
开发者ID:kleopatra999,项目名称:go-adodb,代码行数:16,代码来源:adodb.go

示例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()
}
开发者ID:xushiwei,项目名称:go-ole,代码行数:17,代码来源:excel.go

示例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)
	}
}
开发者ID:piaobocpp,项目名称:doc2pdf-go,代码行数:17,代码来源:mediaplayer.go

示例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")
}
开发者ID:xushiwei,项目名称:go-ole,代码行数:22,代码来源:ie.go

示例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
}
开发者ID:nzheyuti,项目名称:doc2pdf-nodejs,代码行数:38,代码来源:word_windows.go

示例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()
}
开发者ID:homingway,项目名称:hickwall,代码行数:24,代码来源:wmi.go


注:本文中的github.com/mattn/go-ole/oleutil.CreateObject函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。