Tuesday, July 14, 2020

ການນຳໃຊ້ CreateObject ໃນ Go

ເປັນຕົວຢ່າງການນຳໃຊ້ CreateObject ໃນ Go

Namespace/Package Name: github.com/go-ole/com

func Example_msxml_rssreader() {
	com.CoInitialize()
	defer com.CoUninitialize()
	var unknown *iunknown.Unknown
	var xmlhttp *Dispatch
	err := com.CreateObject("Microsoft.XMLHTTP", &unknown)
	unknown.QueryInterface(com.IDispatchInterfaceID, &xmlhttp)
	defer xmlhttp.Release()
	MustCallMethod(xmlhttp, "open", "GET", "http://rss.slashdot.org/Slashdot/slashdot", false)
	MustCallMethod(xmlhttp, "send", nil)

	state := -1
	for state != 4 {
		state = int(MustGetProperty(xmlhttp, "readyState").Val)
		time.Sleep(10000000)
	}
	responseXml := MustGetProperty(xmlhttp, "responseXml").ToIDispatch()
	items := MustCallMethod(responseXml, "selectNodes", "/rss/channel/item").ToIDispatch()
	defer items.Release()
	length := int(MustGetProperty(items, "length").Val)
	for n := 0; n < length; n++ {
		item := MustGetProperty(items, "item", n).ToIDispatch()
		title := MustCallMethod(item, "selectSingleNode", "title").ToIDispatch()
		link := MustCallMethod(item, "selectSingleNode", "link").ToIDispatch()
		fmt.Println(MustGetProperty(title, "text").ToString())
		fmt.Println("  " + MustGetProperty(link, "text").ToString())
		title.Release()
		link.Release()
		item.Release()
	}
}

Subscribe

  • RSS Atom

ອອນລາຍ: 1 | ມື້ນີ້: 13 | ວານນີ້: 25 | ທິດນີ້: 93 | ເດືອນນີ້: 872 | ປີນີ້: 11832 | ລວມ: 78935