ole

package module
v1.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 5 Imported by: 1

README

Go OLE

Build status Build Status GoDoc

Go bindings for Windows COM using shared libraries instead of cgo.

By Yasuhiro Matsumoto.

Install

To experiment with go-ole, you can just compile and run the example program:

go get github.com/go-ole/go-ole
cd /path/to/go-ole/
go test

cd /path/to/go-ole/example/excel
go run excel.go

Continuous Integration

Continuous integration configuration has been added for both Travis-CI and AppVeyor. You will have to add these to your own account for your fork in order for it to run.

Travis-CI

Travis-CI was added to check builds on Linux to ensure that go get works when cross building. Currently, Travis-CI is not used to test cross-building, but this may be changed in the future. It is also not currently possible to test the library on Linux, since COM API is specific to Windows and it is not currently possible to run a COM server on Linux or even connect to a remote COM server.

AppVeyor

AppVeyor is used to build on Windows using the (in-development) test COM server. It is currently only used to test the build and ensure that the code works on Windows. It will be used to register a COM server and then run the test cases based on the test COM server.

The tests currently do run and do pass and this should be maintained with commits.

Versioning

Go OLE uses semantic versioning for version numbers, which is similar to the version contract of the Go language. Which means that the major version will always maintain backwards compatibility with minor versions. Minor versions will only add new additions and changes. Fixes will always be in patch.

This contract should allow you to upgrade to new minor and patch versions without breakage or modifications to your existing code. Leave a ticket, if there is breakage, so that it could be fixed.

LICENSE

Under the MIT License: http://mattn.mit-license.org/2013

Documentation

Overview

Example (Quickbooks)
var err error

connection := &Connection{nil}

err = connection.Initialize()
if err != nil {
	return
}
defer connection.Uninitialize()

err = connection.Create("QBXMLRP2.RequestProcessor.1")
if err != nil {
	if err.(*OleError).Code() == CO_E_CLASSSTRING {
		return
	}
}
defer connection.Release()

dispatch, err := connection.Dispatch()
if err != nil {
	return
}
defer dispatch.Release()
Output:

Example (SafeArrayGetElementString)

This tests more than one function. It tests all of the functions needed in order to retrieve an SafeArray populated with Strings.

CoInitialize(0)
defer CoUninitialize()

clsid, err := CLSIDFromProgID("QBXMLRP2.RequestProcessor.1")
if err != nil {
	if err.(*OleError).Code() == CO_E_CLASSSTRING {
		return
	}
}

unknown, err := CreateInstance(clsid, IID_IUnknown)
if err != nil {
	return
}
defer unknown.Release()

dispatch, err := unknown.QueryInterface(IID_IDispatch)
if err != nil {
	return
}

var dispid []int32
dispid, err = dispatch.GetIDsOfName([]string{"OpenConnection2"})
if err != nil {
	return
}

var result *VARIANT
_, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", "Test Application 1", 1)
if err != nil {
	return
}

dispid, err = dispatch.GetIDsOfName([]string{"BeginSession"})
if err != nil {
	return
}

result, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", 2)
if err != nil {
	return
}

ticket := result.ToString()

dispid, err = dispatch.GetIDsOfName([]string{"QBXMLVersionsForSession"})
if err != nil {
	return
}

result, err = dispatch.Invoke(dispid[0], DISPATCH_PROPERTYGET, ticket)
if err != nil {
	return
}

// Where the real tests begin.
var qbXMLVersions *SafeArray
var qbXmlVersionStrings []string
qbXMLVersions = result.ToArray().Array

// Get array bounds
var LowerBounds int32
var UpperBounds int32
LowerBounds, err = safeArrayGetLBound(qbXMLVersions, 1)
if err != nil {
	return
}

UpperBounds, err = safeArrayGetUBound(qbXMLVersions, 1)
if err != nil {
	return
}

totalElements := UpperBounds - LowerBounds + 1
qbXmlVersionStrings = make([]string, totalElements)

for i := int32(0); i < totalElements; i++ {
	qbXmlVersionStrings[i], _ = safeArrayGetElementString(qbXMLVersions, i)
}

// Release Safe Array memory
safeArrayDestroy(qbXMLVersions)

dispid, err = dispatch.GetIDsOfName([]string{"EndSession"})
if err != nil {
	return
}

_, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, ticket)
if err != nil {
	return
}

dispid, err = dispatch.GetIDsOfName([]string{"CloseConnection"})
if err != nil {
	return
}

_, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD)
if err != nil {
	return
}
Output:

Index

Examples

Constants

View Source
const (
	CLSCTX_INPROC_SERVER   = 1
	CLSCTX_INPROC_HANDLER  = 2
	CLSCTX_LOCAL_SERVER    = 4
	CLSCTX_INPROC_SERVER16 = 8
	CLSCTX_REMOTE_SERVER   = 16
	CLSCTX_ALL             = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER
	CLSCTX_INPROC          = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER
	CLSCTX_SERVER          = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER
)
View Source
const (
	COINIT_APARTMENTTHREADED = 0x2
	COINIT_MULTITHREADED     = 0x0
	COINIT_DISABLE_OLE1DDE   = 0x4
	COINIT_SPEED_OVER_MEMORY = 0x8
)
View Source
const (
	DISPATCH_METHOD         = 1
	DISPATCH_PROPERTYGET    = 2
	DISPATCH_PROPERTYPUT    = 4
	DISPATCH_PROPERTYPUTREF = 8
)
View Source
const (
	S_OK           = 0x00000000
	E_UNEXPECTED   = 0x8000FFFF
	E_NOTIMPL      = 0x80004001
	E_OUTOFMEMORY  = 0x8007000E
	E_INVALIDARG   = 0x80070057
	E_NOINTERFACE  = 0x80004002
	E_POINTER      = 0x80004003
	E_HANDLE       = 0x80070006
	E_ABORT        = 0x80004004
	E_FAIL         = 0x80004005
	E_ACCESSDENIED = 0x80070005
	E_PENDING      = 0x8000000A

	CO_E_CLASSSTRING = 0x800401F3
)
View Source
const (
	CC_FASTCALL = iota
	CC_CDECL
	CC_MSCPASCAL
	CC_PASCAL = CC_MSCPASCAL
	CC_MACPASCAL
	CC_STDCALL
	CC_FPFASTCALL
	CC_SYSCALL
	CC_MPWCDECL
	CC_MPWPASCAL
	CC_MAX = CC_MPWPASCAL
)
View Source
const (
	DISPID_UNKNOWN     = -1
	DISPID_VALUE       = 0
	DISPID_PROPERTYPUT = -3
	DISPID_NEWENUM     = -4
	DISPID_EVALUATE    = -5
	DISPID_CONSTRUCTOR = -6
	DISPID_DESTRUCTOR  = -7
	DISPID_COLLECT     = -8
)
View Source
const (
	TKIND_ENUM      = 1
	TKIND_RECORD    = 2
	TKIND_MODULE    = 3
	TKIND_INTERFACE = 4
	TKIND_DISPATCH  = 5
	TKIND_COCLASS   = 6
	TKIND_ALIAS     = 7
	TKIND_UNION     = 8
	TKIND_MAX       = 9
)
View Source
const (
	FADF_AUTO        = 0x0001
	FADF_STATIC      = 0x0002
	FADF_EMBEDDED    = 0x0004
	FADF_FIXEDSIZE   = 0x0010
	FADF_RECORD      = 0x0020
	FADF_HAVEIID     = 0x0040
	FADF_HAVEVARTYPE = 0x0080
	FADF_BSTR        = 0x0100
	FADF_UNKNOWN     = 0x0200
	FADF_DISPATCH    = 0x0400
	FADF_VARIANT     = 0x0800
	FADF_RESERVED    = 0xF008
)

Variables

View Source
var (
	// IID_NULL is null Interface ID, used when no other Interface ID is known.
	IID_NULL = NewGUID("{00000000-0000-0000-0000-000000000000}")

	// IID_IUnknown is for IUnknown interfaces.
	IID_IUnknown = NewGUID("{00000000-0000-0000-C000-000000000046}")

	// IID_IDispatch is for IDispatch interfaces.
	IID_IDispatch = NewGUID("{00020400-0000-0000-C000-000000000046}")

	// IID_IEnumVariant is for IEnumVariant interfaces
	IID_IEnumVariant = NewGUID("{00020404-0000-0000-C000-000000000046}")

	// IID_IConnectionPointContainer is for IConnectionPointContainer interfaces.
	IID_IConnectionPointContainer = NewGUID("{B196B284-BAB4-101A-B69C-00AA00341D07}")

	// IID_IConnectionPoint is for IConnectionPoint interfaces.
	IID_IConnectionPoint = NewGUID("{B196B286-BAB4-101A-B69C-00AA00341D07}")

	// IID_IInspectable is for IInspectable interfaces.
	IID_IInspectable = NewGUID("{AF86E2E0-B12D-4C6A-9C5A-D7AA65101E90}")

	// IID_IProvideClassInfo is for IProvideClassInfo interfaces.
	IID_IProvideClassInfo = NewGUID("{B196B283-BAB4-101A-B69C-00AA00341D07}")
)
View Source
var (
	// IID_ICOMTestString is for ICOMTestString interfaces.
	//
	// {E0133EB4-C36F-469A-9D3D-C66B84BE19ED}
	IID_ICOMTestString = NewGUID("{E0133EB4-C36F-469A-9D3D-C66B84BE19ED}")

	// IID_ICOMTestInt8 is for ICOMTestInt8 interfaces.
	//
	// {BEB06610-EB84-4155-AF58-E2BFF53680B4}
	IID_ICOMTestInt8 = NewGUID("{BEB06610-EB84-4155-AF58-E2BFF53680B4}")

	// IID_ICOMTestInt16 is for ICOMTestInt16 interfaces.
	//
	// {DAA3F9FA-761E-4976-A860-8364CE55F6FC}
	IID_ICOMTestInt16 = NewGUID("{DAA3F9FA-761E-4976-A860-8364CE55F6FC}")

	// IID_ICOMTestInt32 is for ICOMTestInt32 interfaces.
	//
	// {E3DEDEE7-38A2-4540-91D1-2EEF1D8891B0}
	IID_ICOMTestInt32 = NewGUID("{E3DEDEE7-38A2-4540-91D1-2EEF1D8891B0}")

	// IID_ICOMTestInt64 is for ICOMTestInt64 interfaces.
	//
	// {8D437CBC-B3ED-485C-BC32-C336432A1623}
	IID_ICOMTestInt64 = NewGUID("{8D437CBC-B3ED-485C-BC32-C336432A1623}")

	// IID_ICOMTestFloat is for ICOMTestFloat interfaces.
	//
	// {BF1ED004-EA02-456A-AA55-2AC8AC6B054C}
	IID_ICOMTestFloat = NewGUID("{BF1ED004-EA02-456A-AA55-2AC8AC6B054C}")

	// IID_ICOMTestDouble is for ICOMTestDouble interfaces.
	//
	// {BF908A81-8687-4E93-999F-D86FAB284BA0}
	IID_ICOMTestDouble = NewGUID("{BF908A81-8687-4E93-999F-D86FAB284BA0}")

	// IID_ICOMTestBoolean is for ICOMTestBoolean interfaces.
	//
	// {D530E7A6-4EE8-40D1-8931-3D63B8605010}
	IID_ICOMTestBoolean = NewGUID("{D530E7A6-4EE8-40D1-8931-3D63B8605010}")

	// IID_ICOMEchoTestObject is for ICOMEchoTestObject interfaces.
	//
	// {6485B1EF-D780-4834-A4FE-1EBB51746CA3}
	IID_ICOMEchoTestObject = NewGUID("{6485B1EF-D780-4834-A4FE-1EBB51746CA3}")

	// IID_ICOMTestTypes is for ICOMTestTypes interfaces.
	//
	// {CCA8D7AE-91C0-4277-A8B3-FF4EDF28D3C0}
	IID_ICOMTestTypes = NewGUID("{CCA8D7AE-91C0-4277-A8B3-FF4EDF28D3C0}")

	// CLSID_COMEchoTestObject is for COMEchoTestObject class.
	//
	// {3C24506A-AE9E-4D50-9157-EF317281F1B0}
	CLSID_COMEchoTestObject = NewGUID("{3C24506A-AE9E-4D50-9157-EF317281F1B0}")

	// CLSID_COMTestScalarClass is for COMTestScalarClass class.
	//
	// {865B85C5-0334-4AC6-9EF6-AACEC8FC5E86}
	CLSID_COMTestScalarClass = NewGUID("{865B85C5-0334-4AC6-9EF6-AACEC8FC5E86}")
)

These are for testing and not part of any library.

Functions

func BstrToString

func BstrToString(p *uint16) string

BstrToString converts COM binary string to Go string.

func BytePtrToString

func BytePtrToString(p *byte) string

BytePtrToString converts byte pointer to a Go string.

func CoInitialize

func CoInitialize(p uintptr) (err error)

CoInitialize initializes COM library on current thread.

MSDN documentation suggests that this function should not be called. Call CoInitializeEx() instead. The reason has to do with threading and this function is only for single-threaded apartments.

That said, most users of the library have gotten away with just this function. If you are experiencing threading issues, then use CoInitializeEx().

func CoInitializeEx

func CoInitializeEx(p uintptr, coinit uint32) (err error)

CoInitializeEx initializes COM library with concurrency model.

func CoTaskMemFree

func CoTaskMemFree(memptr uintptr)

CoTaskMemFree frees memory pointer.

func CoUninitialize

func CoUninitialize()

CoUninitialize uninitializes COM Library.

func DeleteHString

func DeleteHString(hstring HString) (err error)

DeleteHString deletes HString.

func DispatchMessage

func DispatchMessage(msg *Msg) (ret int32)

DispatchMessage to window procedure.

func GetMessage

func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error)

GetMessage in message queue from runtime.

This function appears to block. PeekMessage does not block.

func GetUserDefaultLCID

func GetUserDefaultLCID() (lcid uint32)

GetUserDefaultLCID retrieves current user default locale.

func GetVariantDate

func GetVariantDate(value uint64) (time.Time, error)

GetVariantDate converts COM Variant Time value to Go time.Time.

func IsEqualGUID

func IsEqualGUID(guid1 *GUID, guid2 *GUID) bool

IsEqualGUID compares two GUID.

Not constant time comparison.

func LpOleStrToString

func LpOleStrToString(p *uint16) string

LpOleStrToString converts COM Unicode to Go string.

func RoInitialize

func RoInitialize(thread_type uint32) (err error)

func StringFromCLSID

func StringFromCLSID(clsid *GUID) (str string, err error)

StringFromCLSID returns GUID formated string from GUID object.

func StringFromIID

func StringFromIID(iid *GUID) (str string, err error)

StringFromIID returns GUID formatted string from GUID object.

func SysAllocString

func SysAllocString(v string) (ss *int16)

SysAllocString allocates memory for string and copies string into memory.

func SysAllocStringLen

func SysAllocStringLen(v string) (ss *int16)

SysAllocStringLen copies up to length of given string returning pointer.

func SysFreeString

func SysFreeString(v *int16) (err error)

SysFreeString frees string system memory. This must be called with SysAllocString.

func SysStringLen

func SysStringLen(v *int16) uint32

SysStringLen is the length of the system allocated string.

func UTF16PtrToString

func UTF16PtrToString(p *uint16) string

UTF16PtrToString is alias for LpOleStrToString.

Kept for compatibility reasons.

func VariantClear

func VariantClear(v *VARIANT) (err error)

VariantClear clears value in Variant settings to VT_EMPTY.

func VariantInit

func VariantInit(v *VARIANT) (err error)

VariantInit initializes variant.

Types

type BindOpts added in v1.2.6

type BindOpts struct {
	CbStruct          uint32
	GrfFlags          uint32
	GrfMode           uint32
	TickCountDeadline uint32
}

type Connection

type Connection struct {
	Object *IUnknown // Access COM
}

Connection contains IUnknown for fluent interface interaction.

Deprecated. Use oleutil package instead.

func Connect

func Connect(names ...string) (connection *Connection)

Connect initializes COM and attempts to load IUnknown based on given names.

func (*Connection) Create

func (c *Connection) Create(progId string) (err error)

Create IUnknown object based first on ProgId and then from String.

func (*Connection) Dispatch

func (c *Connection) Dispatch() (object *Dispatch, err error)

Dispatch returns Dispatch object.

func (*Connection) Initialize

func (*Connection) Initialize() (err error)

Initialize COM.

func (*Connection) Load

func (c *Connection) Load(names ...string) (errors []error)

Load COM object from list of programIDs or strings.

func (*Connection) Release

func (c *Connection) Release()

Release IUnknown object.

func (*Connection) Uninitialize

func (*Connection) Uninitialize()

Uninitialize COM.

type DISPPARAMS

type DISPPARAMS struct {
	// contains filtered or unexported fields
}

DISPPARAMS are the arguments that passed to methods or property.

type Dispatch

type Dispatch struct {
	Object *IDispatch // Dispatch object.
}

Dispatch stores IDispatch object.

func (*Dispatch) Call

func (d *Dispatch) Call(method string, params ...interface{}) (result *VARIANT, err error)

Call method on IDispatch with parameters.

func (*Dispatch) Get

func (d *Dispatch) Get(name string, params ...interface{}) (result *VARIANT, err error)

Get property on IDispatch with parameters.

func (*Dispatch) GetId

func (d *Dispatch) GetId(name string) (id int32, err error)

GetId retrieves ID of name on IDispatch.

func (*Dispatch) GetIds

func (d *Dispatch) GetIds(names ...string) (dispid []int32, err error)

GetIds retrieves all IDs of names on IDispatch.

func (*Dispatch) Invoke

func (d *Dispatch) Invoke(id int32, dispatch int16, params []interface{}) (result *VARIANT, err error)

Invoke IDispatch on DisplayID of dispatch type with parameters.

There have been problems where if send cascading params..., it would error out because the parameters would be empty.

func (*Dispatch) MustCall

func (d *Dispatch) MustCall(method string, params ...interface{}) (result *VARIANT)

MustCall method on IDispatch with parameters.

func (*Dispatch) MustGet

func (d *Dispatch) MustGet(name string, params ...interface{}) (result *VARIANT)

MustGet property on IDispatch with parameters.

func (*Dispatch) MustSet

func (d *Dispatch) MustSet(name string, params ...interface{}) (result *VARIANT)

MustSet property on IDispatch with parameters.

func (*Dispatch) Release

func (d *Dispatch) Release()

Release IDispatch object.

func (*Dispatch) Set

func (d *Dispatch) Set(name string, params ...interface{}) (result *VARIANT, err error)

Set property on IDispatch with parameters.

type EXCEPINFO

type EXCEPINFO struct {
	// contains filtered or unexported fields
}

EXCEPINFO defines exception info.

func (*EXCEPINFO) Clear added in v1.2.6

func (e *EXCEPINFO) Clear()

Clear frees BSTR strings inside an EXCEPINFO and set it to NULL.

func (EXCEPINFO) Error

func (e EXCEPINFO) Error() string

Error implements error interface and returns error string.

func (EXCEPINFO) SCODE

func (e EXCEPINFO) SCODE() uint32

SCODE return scode in EXCEPINFO.

func (EXCEPINFO) String

func (e EXCEPINFO) String() string

String convert EXCEPINFO to string.

func (EXCEPINFO) WCode

func (e EXCEPINFO) WCode() uint16

WCode return wCode in EXCEPINFO.

type GUID

type GUID struct {
	Data1 uint32
	Data2 uint16
	Data3 uint16
	Data4 [8]byte
}

GUID is Windows API specific GUID type.

This exists to match Windows GUID type for direct passing for COM. Format is in xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx.

func CLSIDFromProgID

func CLSIDFromProgID(progId string) (clsid *GUID, err error)

CLSIDFromProgID retrieves Class Identifier with the given Program Identifier.

The Programmatic Identifier must be registered, because it will be looked up in the Windows Registry. The registry entry has the following keys: CLSID, Insertable, Protocol and Shell (https://msdn.microsoft.com/en-us/library/dd542719(v=vs.85).aspx).

programID identifies the class id with less precision and is not guaranteed to be unique. These are usually found in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Classes, usually with the format of "Program.Component.Version" with version being optional.

CLSIDFromProgID in Windows API.

func CLSIDFromString

func CLSIDFromString(str string) (clsid *GUID, err error)

CLSIDFromString retrieves Class ID from string representation.

This is technically the string version of the GUID and will convert the string to object.

CLSIDFromString in Windows API.

func ClassIDFrom

func ClassIDFrom(programID string) (classID *GUID, err error)

ClassIDFrom retrieves class ID whether given is program ID or application string.

Helper that provides check against both Class ID from Program ID and Class ID from string. It is faster, if you know which you are using, to use the individual functions, but this will check against available functions for you.

func IIDFromString

func IIDFromString(progId string) (clsid *GUID, err error)

IIDFromString returns GUID from program ID.

func NewGUID

func NewGUID(guid string) *GUID

NewGUID converts the given string into a globally unique identifier that is compliant with the Windows API.

The supplied string may be in any of these formats:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}

The conversion of the supplied string is not case-sensitive.

func (*GUID) String

func (guid *GUID) String() string

String converts the GUID to string form. It will adhere to this pattern:

{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}

If the GUID is nil, the string representation of an empty GUID is returned:

{00000000-0000-0000-0000-000000000000}

type HString

type HString uintptr

HString is handle string for pointers.

func NewHString

func NewHString(s string) (hstring HString, err error)

NewHString returns a new HString for Go string.

func (HString) String

func (h HString) String() string

String returns Go string value of HString.

type IConnectionPoint

type IConnectionPoint struct {
	IUnknown
}

func (*IConnectionPoint) Advise

func (v *IConnectionPoint) Advise(unknown *IUnknown) (cookie uint32, err error)

func (*IConnectionPoint) EnumConnections

func (v *IConnectionPoint) EnumConnections(p *unsafe.Pointer) error

func (*IConnectionPoint) GetConnectionInterface

func (v *IConnectionPoint) GetConnectionInterface(piid **GUID) int32

func (*IConnectionPoint) Unadvise

func (v *IConnectionPoint) Unadvise(cookie uint32) (err error)

func (*IConnectionPoint) VTable

type IConnectionPointContainer

type IConnectionPointContainer struct {
	IUnknown
}

func (*IConnectionPointContainer) EnumConnectionPoints

func (v *IConnectionPointContainer) EnumConnectionPoints(points interface{}) error

func (*IConnectionPointContainer) FindConnectionPoint

func (v *IConnectionPointContainer) FindConnectionPoint(iid *GUID, point **IConnectionPoint) (err error)

func (*IConnectionPointContainer) VTable

type IConnectionPointContainerVtbl

type IConnectionPointContainerVtbl struct {
	IUnknownVtbl
	EnumConnectionPoints uintptr
	FindConnectionPoint  uintptr
}

type IConnectionPointVtbl

type IConnectionPointVtbl struct {
	IUnknownVtbl
	GetConnectionInterface      uintptr
	GetConnectionPointContainer uintptr
	Advise                      uintptr
	Unadvise                    uintptr
	EnumConnections             uintptr
}

type IDLDESC

type IDLDESC struct {
	DwReserved uint32
	WIDLFlags  uint16
}

IDLDESC defines IDL info.

type IDispatch

type IDispatch struct {
	IUnknown
}

func CreateStdDispatch

func CreateStdDispatch(unk *IUnknown, v uintptr, ptinfo *IUnknown) (disp *IDispatch, err error)

CreateStdDispatch provides default IDispatch implementation for IUnknown.

This handles default IDispatch implementation for objects. It haves a few limitations with only supporting one language. It will also only return default exception codes.

func (*IDispatch) CallMethod

func (v *IDispatch) CallMethod(name string, params ...interface{}) (*VARIANT, error)

CallMethod invokes named function with arguments on object.

func (*IDispatch) GetIDsOfName

func (v *IDispatch) GetIDsOfName(names []string) (dispid []int32, err error)

func (*IDispatch) GetProperty

func (v *IDispatch) GetProperty(name string, params ...interface{}) (*VARIANT, error)

GetProperty retrieves the property with the name with the ability to pass arguments.

Most of the time you will not need to pass arguments as most objects do not allow for this feature. Or at least, should not allow for this feature. Some servers don't follow best practices and this is provided for those edge cases.

func (*IDispatch) GetSingleIDOfName

func (v *IDispatch) GetSingleIDOfName(name string) (displayID int32, err error)

GetSingleIDOfName is a helper that returns single display ID for IDispatch name.

This replaces the common pattern of attempting to get a single name from the list of available IDs. It gives the first ID, if it is available.

func (*IDispatch) GetTypeInfo

func (v *IDispatch) GetTypeInfo() (tinfo *ITypeInfo, err error)

func (*IDispatch) GetTypeInfoCount

func (v *IDispatch) GetTypeInfoCount() (c uint32, err error)

func (*IDispatch) Invoke

func (v *IDispatch) Invoke(dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error)

func (*IDispatch) InvokeWithOptionalArgs

func (v *IDispatch) InvokeWithOptionalArgs(name string, dispatch int16, params []interface{}) (result *VARIANT, err error)

InvokeWithOptionalArgs accepts arguments as an array, works like Invoke.

Accepts name and will attempt to retrieve Display ID to pass to Invoke.

Passing params as an array is a workaround that could be fixed in later versions of Go that prevent passing empty params. During testing it was discovered that this is an acceptable way of getting around not being able to pass params normally.

func (*IDispatch) PutProperty

func (v *IDispatch) PutProperty(name string, params ...interface{}) (*VARIANT, error)

PutProperty attempts to mutate a property in the object.

func (*IDispatch) VTable

func (v *IDispatch) VTable() *IDispatchVtbl

type IDispatchVtbl

type IDispatchVtbl struct {
	IUnknownVtbl
	GetTypeInfoCount uintptr
	GetTypeInfo      uintptr
	GetIDsOfNames    uintptr
	Invoke           uintptr
}

type IEnumVARIANT

type IEnumVARIANT struct {
	IUnknown
}

func (*IEnumVARIANT) Clone

func (enum *IEnumVARIANT) Clone() (cloned *IEnumVARIANT, err error)

func (*IEnumVARIANT) Next

func (enum *IEnumVARIANT) Next(celt uint) (array VARIANT, length uint, err error)

func (*IEnumVARIANT) Reset

func (enum *IEnumVARIANT) Reset() (err error)

func (*IEnumVARIANT) Skip

func (enum *IEnumVARIANT) Skip(celt uint) (err error)

func (*IEnumVARIANT) VTable

func (v *IEnumVARIANT) VTable() *IEnumVARIANTVtbl

type IEnumVARIANTVtbl

type IEnumVARIANTVtbl struct {
	IUnknownVtbl
	Next  uintptr
	Skip  uintptr
	Reset uintptr
	Clone uintptr
}

type IInspectable

type IInspectable struct {
	IUnknown
}

func RoActivateInstance

func RoActivateInstance(clsid string) (ins *IInspectable, err error)

func RoGetActivationFactory

func RoGetActivationFactory(clsid string, iid *GUID) (ins *IInspectable, err error)

func (*IInspectable) GetIids

func (v *IInspectable) GetIids() (iids []*GUID, err error)

func (*IInspectable) GetRuntimeClassName

func (v *IInspectable) GetRuntimeClassName() (s string, err error)

func (*IInspectable) GetTrustLevel

func (v *IInspectable) GetTrustLevel() (level uint32, err error)

func (*IInspectable) VTable

func (v *IInspectable) VTable() *IInspectableVtbl

type IInspectableVtbl

type IInspectableVtbl struct {
	IUnknownVtbl
	GetIIds             uintptr
	GetRuntimeClassName uintptr
	GetTrustLevel       uintptr
}

type INTERFACEDATA

type INTERFACEDATA struct {
	MethodData *METHODDATA
	CMembers   uint32
}

INTERFACEDATA defines interface info.

type IProvideClassInfo

type IProvideClassInfo struct {
	IUnknown
}

func (*IProvideClassInfo) GetClassInfo

func (v *IProvideClassInfo) GetClassInfo() (cinfo *ITypeInfo, err error)

func (*IProvideClassInfo) VTable

type IProvideClassInfoVtbl

type IProvideClassInfoVtbl struct {
	IUnknownVtbl
	GetClassInfo uintptr
}

type ITypeInfo

type ITypeInfo struct {
	IUnknown
}

func (*ITypeInfo) GetTypeAttr

func (v *ITypeInfo) GetTypeAttr() (tattr *TYPEATTR, err error)

func (*ITypeInfo) VTable

func (v *ITypeInfo) VTable() *ITypeInfoVtbl

type ITypeInfoVtbl

type ITypeInfoVtbl struct {
	IUnknownVtbl
	GetTypeAttr          uintptr
	GetTypeComp          uintptr
	GetFuncDesc          uintptr
	GetVarDesc           uintptr
	GetNames             uintptr
	GetRefTypeOfImplType uintptr
	GetImplTypeFlags     uintptr
	GetIDsOfNames        uintptr
	Invoke               uintptr
	GetDocumentation     uintptr
	GetDllEntry          uintptr
	GetRefTypeInfo       uintptr
	AddressOfMember      uintptr
	CreateInstance       uintptr
	GetMops              uintptr
	GetContainingTypeLib uintptr
	ReleaseTypeAttr      uintptr
	ReleaseFuncDesc      uintptr
	ReleaseVarDesc       uintptr
}

type IUnknown

type IUnknown struct {
	RawVTable *interface{}
}

func CreateDispTypeInfo

func CreateDispTypeInfo(idata *INTERFACEDATA) (pptinfo *IUnknown, err error)

CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch.

This will not handle the full implementation of the interface.

func CreateInstance

func CreateInstance(clsid *GUID, iid *GUID) (unk *IUnknown, err error)

CreateInstance of single uninitialized object with GUID.

func GetActiveObject

func GetActiveObject(clsid *GUID, iid *GUID) (unk *IUnknown, err error)

GetActiveObject retrieves pointer to active object.

func GetObject added in v1.2.6

func GetObject(programID string, bindOpts *BindOpts, iid *GUID) (unk *IUnknown, err error)

GetObject retrieves pointer to active object.

func (*IUnknown) AddRef

func (v *IUnknown) AddRef() int32

func (*IUnknown) IDispatch

func (v *IUnknown) IDispatch(interfaceID *GUID) (dispatch *IDispatch, err error)

func (*IUnknown) IEnumVARIANT

func (v *IUnknown) IEnumVARIANT(interfaceID *GUID) (enum *IEnumVARIANT, err error)

func (*IUnknown) MustQueryInterface

func (v *IUnknown) MustQueryInterface(iid *GUID) (disp *IDispatch)

func (*IUnknown) PutQueryInterface

func (v *IUnknown) PutQueryInterface(interfaceID *GUID, obj interface{}) error

func (*IUnknown) QueryInterface

func (v *IUnknown) QueryInterface(iid *GUID) (*IDispatch, error)

func (*IUnknown) Release

func (v *IUnknown) Release() int32

func (*IUnknown) VTable

func (v *IUnknown) VTable() *IUnknownVtbl

type IUnknownVtbl

type IUnknownVtbl struct {
	QueryInterface uintptr
	AddRef         uintptr
	Release        uintptr
}

type METHODDATA

type METHODDATA struct {
	Name     *uint16
	Data     *PARAMDATA
	Dispid   int32
	Meth     uint32
	CC       int32
	CArgs    uint32
	Flags    uint16
	VtReturn uint32
}

METHODDATA defines method info.

type Msg

type Msg struct {
	Hwnd    uint32
	Message uint32
	Wparam  int32
	Lparam  int32
	Time    uint32
	Pt      Point
}

Msg is message between processes.

type OleError

type OleError struct {
	// contains filtered or unexported fields
}

OleError stores COM errors.

func NewError

func NewError(hr uintptr) *OleError

NewError creates new error with HResult.

func NewErrorWithDescription

func NewErrorWithDescription(hr uintptr, description string) *OleError

NewErrorWithDescription creates new COM error with HResult and description.

func NewErrorWithSubError

func NewErrorWithSubError(hr uintptr, description string, err error) *OleError

NewErrorWithSubError creates new COM error with parent error.

func (*OleError) Code

func (v *OleError) Code() uintptr

Code is the HResult.

func (*OleError) Description

func (v *OleError) Description() string

Description retrieves error summary, if there is one.

func (*OleError) Error

func (v *OleError) Error() string

Error implements error interface.

func (*OleError) String

func (v *OleError) String() string

String description, either manually set or format message with error code.

func (*OleError) SubError

func (v *OleError) SubError() error

SubError returns parent error, if there is one.

type PARAMDATA

type PARAMDATA struct {
	Name *int16
	Vt   uint16
}

PARAMDATA defines parameter data type.

type Point

type Point struct {
	X int32
	Y int32
}

Point is 2D vector type.

type SAFEARRAY

type SAFEARRAY SafeArray

SAFEARRAY is obsolete, exists for backwards compatibility. Use SafeArray

type SAFEARRAYBOUND

type SAFEARRAYBOUND SafeArrayBound

SAFEARRAYBOUND is obsolete, exists for backwards compatibility. Use SafeArrayBound

type SafeArray

type SafeArray struct {
	Dimensions   uint16
	FeaturesFlag uint16
	ElementsSize uint32
	LocksAmount  uint32
	Data         uint32
	Bounds       [16]byte
}

SafeArray is how COM handles arrays.

type SafeArrayBound

type SafeArrayBound struct {
	Elements   uint32
	LowerBound int32
}

SafeArrayBound defines the SafeArray boundaries.

type SafeArrayConversion

type SafeArrayConversion struct {
	Array *SafeArray
}

func (*SafeArrayConversion) GetDimensions

func (sac *SafeArrayConversion) GetDimensions() (dimensions *uint32, err error)

func (*SafeArrayConversion) GetSize

func (sac *SafeArrayConversion) GetSize() (length *uint32, err error)

func (*SafeArrayConversion) GetType

func (sac *SafeArrayConversion) GetType() (varType uint16, err error)

func (*SafeArrayConversion) Release

func (sac *SafeArrayConversion) Release()

Release Safe Array memory

func (*SafeArrayConversion) ToByteArray

func (sac *SafeArrayConversion) ToByteArray() (bytes []byte)

func (*SafeArrayConversion) ToStringArray

func (sac *SafeArrayConversion) ToStringArray() (strings []string)

func (*SafeArrayConversion) ToValueArray

func (sac *SafeArrayConversion) ToValueArray() (values []interface{})

func (*SafeArrayConversion) TotalElements

func (sac *SafeArrayConversion) TotalElements(index uint32) (totalElements int32, err error)

type TYPEATTR

type TYPEATTR struct {
	Guid GUID
	Lcid uint32

	MemidConstructor int32
	MemidDestructor  int32
	LpstrSchema      *uint16
	CbSizeInstance   uint32
	Typekind         int32
	CFuncs           uint16
	CVars            uint16
	CImplTypes       uint16
	CbSizeVft        uint16
	CbAlignment      uint16
	WTypeFlags       uint16
	WMajorVerNum     uint16
	WMinorVerNum     uint16
	TdescAlias       TYPEDESC
	IdldescType      IDLDESC
	// contains filtered or unexported fields
}

TYPEATTR defines type info.

type TYPEDESC

type TYPEDESC struct {
	Hreftype uint32
	VT       uint16
}

TYPEDESC defines data type.

type UnknownLike

type UnknownLike interface {
	QueryInterface(iid *GUID) (disp *IDispatch, err error)
	AddRef() int32
	Release() int32
}

type VARIANT

type VARIANT struct {
	VT VT //  2

	Val int64 // 16
	// contains filtered or unexported fields
}

func NewVariant

func NewVariant(vt VT, val int64) VARIANT

NewVariant returns new variant based on type and value.

func (*VARIANT) Clear

func (v *VARIANT) Clear() error

Clear the memory of variant object.

func (*VARIANT) ToArray

func (v *VARIANT) ToArray() *SafeArrayConversion

ToArray converts variant to SafeArray helper.

func (*VARIANT) ToIDispatch

func (v *VARIANT) ToIDispatch() *IDispatch

ToIDispatch converts variant to dispatch object.

func (*VARIANT) ToIUnknown

func (v *VARIANT) ToIUnknown() *IUnknown

ToIUnknown converts Variant to Unknown object.

func (*VARIANT) ToString

func (v *VARIANT) ToString() string

ToString converts variant to Go string.

func (*VARIANT) Value

func (v *VARIANT) Value() interface{}

Value returns variant value based on its type.

Currently supported types: 2- and 4-byte integers, strings, bools. Note that 64-bit integers, datetimes, and other types are stored as strings and will be returned as strings.

Needs to be further converted, because this returns an interface{}.

type VT

type VT uint16
const (
	VT_EMPTY           VT = 0x0
	VT_NULL            VT = 0x1
	VT_I2              VT = 0x2
	VT_I4              VT = 0x3
	VT_R4              VT = 0x4
	VT_R8              VT = 0x5
	VT_CY              VT = 0x6
	VT_DATE            VT = 0x7
	VT_BSTR            VT = 0x8
	VT_DISPATCH        VT = 0x9
	VT_ERROR           VT = 0xa
	VT_BOOL            VT = 0xb
	VT_VARIANT         VT = 0xc
	VT_UNKNOWN         VT = 0xd
	VT_DECIMAL         VT = 0xe
	VT_I1              VT = 0x10
	VT_UI1             VT = 0x11
	VT_UI2             VT = 0x12
	VT_UI4             VT = 0x13
	VT_I8              VT = 0x14
	VT_UI8             VT = 0x15
	VT_INT             VT = 0x16
	VT_UINT            VT = 0x17
	VT_VOID            VT = 0x18
	VT_HRESULT         VT = 0x19
	VT_PTR             VT = 0x1a
	VT_SAFEARRAY       VT = 0x1b
	VT_CARRAY          VT = 0x1c
	VT_USERDEFINED     VT = 0x1d
	VT_LPSTR           VT = 0x1e
	VT_LPWSTR          VT = 0x1f
	VT_RECORD          VT = 0x24
	VT_INT_PTR         VT = 0x25
	VT_UINT_PTR        VT = 0x26
	VT_FILETIME        VT = 0x40
	VT_BLOB            VT = 0x41
	VT_STREAM          VT = 0x42
	VT_STORAGE         VT = 0x43
	VT_STREAMED_OBJECT VT = 0x44
	VT_STORED_OBJECT   VT = 0x45
	VT_BLOB_OBJECT     VT = 0x46
	VT_CF              VT = 0x47
	VT_CLSID           VT = 0x48
	VT_BSTR_BLOB       VT = 0xfff
	VT_VECTOR          VT = 0x1000
	VT_ARRAY           VT = 0x2000
	VT_BYREF           VT = 0x4000
	VT_RESERVED        VT = 0x8000
	VT_ILLEGAL         VT = 0xffff
	VT_ILLEGALMASKED   VT = 0xfff
	VT_TYPEMASK        VT = 0xfff
)

func (VT) String

func (i VT) String() string

Directories

Path Synopsis
_example
ie

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL