當前位置: 首頁>>代碼示例>>Golang>>正文


Golang oleutil.CreateObject函數代碼示例

本文整理匯總了Golang中github.com/go-ole/go-ole/oleutil.CreateObject函數的典型用法代碼示例。如果您正苦於以下問題:Golang CreateObject函數的具體用法?Golang CreateObject怎麽用?Golang CreateObject使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了CreateObject函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

// This example creates a new spreadsheet, reads and modifies cell values and style.
func main() {
	ole.CoInitialize(0)
	unknown, errCreate := oleutil.CreateObject("com.sun.star.ServiceManager")
	checkError(errCreate, "Couldn't create a OLE connection to LibreOffice")
	ServiceManager, errSM := unknown.QueryInterface(ole.IID_IDispatch)
	checkError(errSM, "Couldn't start a LibreOffice instance")
	desktop := oleutil.MustCallMethod(ServiceManager,
		"createInstance", "com.sun.star.frame.Desktop").ToIDispatch()

	document := LONewSpreadsheet(desktop)
	sheet0 := LOGetWorksheet(document, 0)

	cell1_1 := LOGetCell(sheet0, 1, 1) // cell B2
	cell1_2 := LOGetCell(sheet0, 1, 2) // cell B3
	cell1_3 := LOGetCell(sheet0, 1, 3) // cell B4
	cell1_4 := LOGetCell(sheet0, 1, 4) // cell B5
	LOSetCellString(cell1_1, "Hello World")
	LOSetCellValue(cell1_2, 33.45)
	LOSetCellFormula(cell1_3, "=B3+5")
	b4Value := LOGetCellString(cell1_3)
	LOSetCellString(cell1_4, b4Value)
	// set background color yellow:
	oleutil.MustPutProperty(cell1_1, "cellbackcolor", 0xFFFF00)

	fmt.Printf("Press [ENTER] to exit")
	fmt.Scanf("%s")
	ServiceManager.Release()
	ole.CoUninitialize()
}
開發者ID:go-ole,項目名稱:go-ole,代碼行數:30,代碼來源:libreoffice.go

示例2: prepare

func (c *AdodbConn) prepare(ctx context.Context, 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:mattn,項目名稱:go-adodb,代碼行數:31,代碼來源:adodb.go

示例3: main

func main() {
	ole.CoInitialize(0)

	unknown, err := oleutil.CreateObject("{248DD896-BB45-11CF-9ABC-0080C7E7B78D}")
	if err != nil {
		panic(err.Error())
	}
	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:ChongFeng,項目名稱:beats,代碼行數:33,代碼來源:winsock.go

示例4: main

func main() {
	cwd, _ := os.Getwd()
	artworkjpg := filepath.Join(cwd, "artwork.jpg")

	gc := gntp.NewClient()
	gc.AppName = "nowplaying"
	gc.Register([]gntp.Notification{{"default", "", true}})

	ole.CoInitialize(0)
	unk, err := oleutil.CreateObject("iTunes.Application")
	if err != nil {
		log.Fatal(err)
	}
	unk.AddRef()
	dsp := unk.MustQueryInterface(ole.IID_IDispatch)

	prev := ""
	for {
		func() {
			defer func() {
				recover()
			}()
			track := oleutil.MustGetProperty(dsp, "CurrentTrack").ToIDispatch()
			if track != nil {
				name := oleutil.MustGetProperty(track, "Name").ToString()
				artist := oleutil.MustGetProperty(track, "artist").ToString()
				album := oleutil.MustGetProperty(track, "Album").ToString()
				curr := fmt.Sprintf("%s/%s\n%s", name, artist, album)
				if curr != prev {
					prev = curr
					artwork := oleutil.MustGetProperty(track, "Artwork").ToIDispatch()
					item := oleutil.MustGetProperty(artwork, "Item", 1).ToIDispatch()
					icon := ""
					if item != nil {
						_, err = oleutil.CallMethod(item, "SaveArtworkToFile", artworkjpg)
						if err != nil {
							log.Print(err)
						} else {
							icon = artworkjpg
						}
					}
					log.Print(curr)
					err = gc.Notify(&gntp.Message{
						Event: "default",
						Title: "iTunes",
						Text:  curr,
						Icon:  icon,
					})
					if err != nil {
						log.Print(err)
					}
				}
			}
		}()
		time.Sleep(3 * time.Second)
	}
}
開發者ID:mattn,項目名稱:nowplaying,代碼行數:57,代碼來源:nowplaying.go

示例5: iTunes

func iTunes() *ole.IDispatch {
	ole.CoInitialize(0)
	unknown, err := oleutil.CreateObject("iTunes.Application")
	if err != nil {
		log.Fatal(err)
	}
	itunes, err := unknown.QueryInterface(ole.IID_IDispatch)
	if err != nil {
		log.Fatal(err)
	}
	return itunes
}
開發者ID:ChongFeng,項目名稱:beats,代碼行數:12,代碼來源:itunes.go

示例6: 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:fmoliveira,項目名稱:serial-port-json-server,代碼行數:52,代碼來源:seriallist_windows.go

示例7: 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:ChongFeng,項目名稱:beats,代碼行數:13,代碼來源:msagent.go

示例8: 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:mattn,項目名稱:go-adodb,代碼行數:15,代碼來源:mdb.go

示例9: 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:mattn,項目名稱:go-adodb,代碼行數:16,代碼來源:adodb.go

示例10: Initialize

func Initialize(opt ...Option) (mso *MSO) {
	ole.CoInitialize(0)
	app, _ := oleutil.CreateObject("Excel.Application")
	excel, _ := app.QueryInterface(ole.IID_IDispatch)
	wbs := oleutil.MustGetProperty(excel, "WorkBooks").ToIDispatch()
	ver, _ := strconv.ParseFloat(oleutil.MustGetProperty(excel, "Version").ToString(), 64)

	if len(opt) == 0 {
		opt = []Option{{"Visible": true, "DisplayAlerts": true, "ScreenUpdating": true}}
	}
	mso = &MSO{Option: opt[0], IuApp: app, IdExcel: excel, IdWorkBooks: wbs, Version: ver}
	mso.SetOption(1)

	//XlFileFormat Enumeration: http://msdn.microsoft.com/en-us/library/office/ff198017%28v=office.15%29.aspx
	mso.FILEFORMAT = map[string]int{"txt": -4158, "csv": 6, "html": 44}
	return
}
開發者ID:gitdlam,項目名稱:excel,代碼行數:17,代碼來源:excel.go

示例11: 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:ChongFeng,項目名稱:beats,代碼行數:17,代碼來源:mediaplayer.go

示例12: main

func main() {
	log.SetFlags(log.Flags() | log.Lshortfile)
	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()
	cwd, _ := os.Getwd()
	writeExample(excel, workbooks, cwd+"\\write.xls")
	readExample(cwd+"\\excel97-2003.xls", excel, workbooks)
	showMethodsAndProperties(workbooks)
	workbooks.Release()
	// oleutil.CallMethod(excel, "Quit")
	excel.Release()
	ole.CoUninitialize()
}
開發者ID:dlintw,項目名稱:go-ole,代碼行數:17,代碼來源:excel.go

示例13: main

func main() {
	ole.CoInitialize(0)
	unknown, _ := oleutil.CreateObject("Outlook.Application")
	outlook, _ := unknown.QueryInterface(ole.IID_IDispatch)
	ns := oleutil.MustCallMethod(outlook, "GetNamespace", "MAPI").ToIDispatch()
	folder := oleutil.MustCallMethod(ns, "GetDefaultFolder", 10).ToIDispatch()
	contacts := oleutil.MustCallMethod(folder, "Items").ToIDispatch()
	count := oleutil.MustGetProperty(contacts, "Count").Value().(int32)
	for i := 1; i <= int(count); i++ {
		item, err := oleutil.GetProperty(contacts, "Item", i)
		if err == nil && item.VT == ole.VT_DISPATCH {
			if value, err := oleutil.GetProperty(item.ToIDispatch(), "FullName"); err == nil {
				fmt.Println(value.Value())
			}
		}
	}
	oleutil.MustCallMethod(outlook, "Quit")
}
開發者ID:ChongFeng,項目名稱:beats,代碼行數:18,代碼來源:outlook.go

示例14: 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()
	worksheet := oleutil.MustGetProperty(workbook, "Worksheets", 1).ToIDispatch()
	cell := oleutil.MustGetProperty(worksheet, "Cells", 1, 1).ToIDispatch()
	oleutil.PutProperty(cell, "Value", 12345)

	time.Sleep(2000000000)

	oleutil.PutProperty(workbook, "Saved", true)
	oleutil.CallMethod(workbook, "Close", false)
	oleutil.CallMethod(excel, "Quit")
	excel.Release()

	ole.CoUninitialize()
}
開發者ID:ChongFeng,項目名稱:beats,代碼行數:20,代碼來源:excel.go

示例15: 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:ChongFeng,項目名稱:beats,代碼行數:22,代碼來源:ie.go


注:本文中的github.com/go-ole/go-ole/oleutil.CreateObject函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。