ole

package
v0.0.0-...-7afe134 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2014 License: MIT Imports: 4 Imported by: 0

README

go-ole

WHATS:

Go bindings for Windows COM.

INSTALL:

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

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

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

LICENSE:

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

AUTHOR:

  • Yasuhiro Matsumoto
  • Jacob Santos

Documentation

Overview

Helpers for COM

Package is meant to retrieve and process safe array data returned from COM.

Helper for converting SafeArray to array of objects.

Index

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 (
	VT_EMPTY           = 0x0
	VT_NULL            = 0x1
	VT_I2              = 0x2
	VT_I4              = 0x3
	VT_R4              = 0x4
	VT_R8              = 0x5
	VT_CY              = 0x6
	VT_DATE            = 0x7
	VT_BSTR            = 0x8
	VT_DISPATCH        = 0x9
	VT_ERROR           = 0xa
	VT_BOOL            = 0xb
	VT_VARIANT         = 0xc
	VT_UNKNOWN         = 0xd
	VT_DECIMAL         = 0xe
	VT_I1              = 0x10
	VT_UI1             = 0x11
	VT_UI2             = 0x12
	VT_UI4             = 0x13
	VT_I8              = 0x14
	VT_UI8             = 0x15
	VT_INT             = 0x16
	VT_UINT            = 0x17
	VT_VOID            = 0x18
	VT_HRESULT         = 0x19
	VT_PTR             = 0x1a
	VT_SAFEARRAY       = 0x1b
	VT_CARRAY          = 0x1c
	VT_USERDEFINED     = 0x1d
	VT_LPSTR           = 0x1e
	VT_LPWSTR          = 0x1f
	VT_RECORD          = 0x24
	VT_INT_PTR         = 0x25
	VT_UINT_PTR        = 0x26
	VT_FILETIME        = 0x40
	VT_BLOB            = 0x41
	VT_STREAM          = 0x42
	VT_STORAGE         = 0x43
	VT_STREAMED_OBJECT = 0x44
	VT_STORED_OBJECT   = 0x45
	VT_BLOB_OBJECT     = 0x46
	VT_CF              = 0x47
	VT_CLSID           = 0x48
	VT_BSTR_BLOB       = 0xfff
	VT_VECTOR          = 0x1000
	VT_ARRAY           = 0x2000
	VT_BYREF           = 0x4000
	VT_RESERVED        = 0x8000
	VT_ILLEGAL         = 0xffff
	VT_ILLEGALMASKED   = 0xfff
	VT_TYPEMASK        = 0xfff
)
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                      = &GUID{0x00000000, 0x0000, 0x0000, [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
	IID_IUnknown                  = &GUID{0x00000000, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}
	IID_IDispatch                 = &GUID{0x00020400, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}
	IID_IConnectionPointContainer = &GUID{0xB196B284, 0xBAB4, 0x101A, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}}
	IID_IConnectionPoint          = &GUID{0xB196B286, 0xBAB4, 0x101A, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}}
	IID_IProvideClassInfo         = &GUID{0xb196b283, 0xbab4, 0x101a, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}}
)

Functions

func BytePtrToString

func BytePtrToString(p *byte) string

func CoInitialize

func CoInitialize(p uintptr) (err error)

func CoInitializeEx

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

func CoUninitialize

func CoUninitialize()

func DispatchMessage

func DispatchMessage(msg *Msg) (ret int32)

func GetMessage

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

func GetUserDefaultLCID

func GetUserDefaultLCID() (lcid uint32)

func IsEqualGUID

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

func StringFromCLSID

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

func StringFromIID

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

func SysAllocString

func SysAllocString(v string) (ss *int16)

func SysFreeString

func SysFreeString(v *int16) (err error)

func SysStringLen

func SysStringLen(v *int16) uint32

func UTF16PtrToString

func UTF16PtrToString(p *uint16) string

func VariantClear

func VariantClear(v *VARIANT) (err error)

func VariantInit

func VariantInit(v *VARIANT) (err error)

Types

type Connection

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

func Connect

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

func (*Connection) Create

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

Creates Unknown object based first on ProgId and then from String.

func (*Connection) Dispatch

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

func (*Connection) Initialize

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

func (*Connection) Load

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

Loads COM object if in list

func (*Connection) Release

func (c *Connection) Release()

func (*Connection) Uninitialize

func (*Connection) Uninitialize()

type DISPPARAMS

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

type Dispatch

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

func (*Dispatch) Call

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

func (*Dispatch) Get

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

func (*Dispatch) GetId

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

func (*Dispatch) GetIds

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

func (*Dispatch) Invoke

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

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)

func (*Dispatch) MustGet

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

func (*Dispatch) MustSet

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

func (*Dispatch) Release

func (d *Dispatch) Release()

func (*Dispatch) Set

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

type EXCEPINFO

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

type GUID

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

func CLSIDFromProgID

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

func CLSIDFromString

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

func IIDFromString

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

type IConnectionPoint

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

func (*IConnectionPoint) AddRef

func (v *IConnectionPoint) AddRef() int32

func (*IConnectionPoint) Advise

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

func (*IConnectionPoint) EnumConnections

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

func (*IConnectionPoint) GetConnectionInterface

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

func (*IConnectionPoint) QueryInterface

func (v *IConnectionPoint) QueryInterface(iid *GUID) (disp *IDispatch, err error)

func (*IConnectionPoint) Release

func (v *IConnectionPoint) Release() int32

func (*IConnectionPoint) Unadvise

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

type IConnectionPointContainer

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

func (*IConnectionPointContainer) AddRef

func (v *IConnectionPointContainer) AddRef() int32

func (*IConnectionPointContainer) EnumConnectionPoints

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

func (*IConnectionPointContainer) FindConnectionPoint

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

func (*IConnectionPointContainer) QueryInterface

func (v *IConnectionPointContainer) QueryInterface(iid *GUID) (disp *IDispatch, err error)

func (*IConnectionPointContainer) Release

func (v *IConnectionPointContainer) Release() int32

type IDLDESC

type IDLDESC struct {
	DwReserved uint32
	WIDLFlags  uint16
}

type IDispatch

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

func CreateStdDispatch

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

func (*IDispatch) AddRef

func (v *IDispatch) AddRef() int32

func (*IDispatch) GetIDsOfName

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

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) MustQueryInterface

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

func (*IDispatch) QueryInterface

func (v *IDispatch) QueryInterface(iid *GUID) (disp *IDispatch, err error)

func (*IDispatch) Release

func (v *IDispatch) Release() int32

type INTERFACEDATA

type INTERFACEDATA struct {
	MethodData *METHODDATA
	CMembers   uint32
}

type IProvideClassInfo

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

func (*IProvideClassInfo) AddRef

func (v *IProvideClassInfo) AddRef() int32

func (*IProvideClassInfo) GetClassInfo

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

func (*IProvideClassInfo) QueryInterface

func (v *IProvideClassInfo) QueryInterface(iid *GUID) (disp *IDispatch, err error)

func (*IProvideClassInfo) Release

func (v *IProvideClassInfo) Release() int32

type ITypeInfo

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

func (*ITypeInfo) AddRef

func (v *ITypeInfo) AddRef() int32

func (*ITypeInfo) GetTypeAttr

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

func (*ITypeInfo) QueryInterface

func (v *ITypeInfo) QueryInterface(iid *GUID) (disp *IDispatch, err error)

func (*ITypeInfo) Release

func (v *ITypeInfo) Release() int32

type IUnknown

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

func CreateDispTypeInfo

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

func CreateInstance

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

func GetActiveObject

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

func (*IUnknown) AddRef

func (v *IUnknown) AddRef() int32

func (*IUnknown) MustQueryInterface

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

func (*IUnknown) QueryInterface

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

func (*IUnknown) Release

func (v *IUnknown) Release() int32

type METHODDATA

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

type Msg

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

type OleError

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

func NewError

func NewError(hr uintptr) *OleError

func NewErrorWithDescription

func NewErrorWithDescription(hr uintptr, description string) *OleError

func (*OleError) Code

func (v *OleError) Code() uintptr

func (*OleError) Description

func (v *OleError) Description() string

func (*OleError) Error

func (v *OleError) Error() string

func (*OleError) String

func (v *OleError) String() string

type PARAMDATA

type PARAMDATA struct {
	Name *int16
	Vt   uint16
}

type Point

type Point struct {
	X int32
	Y int32
}

type SAFEARRAY

type SAFEARRAY SafeArray

Obsolete, exists for backwards compatibility. Use SafeArray

type SAFEARRAYBOUND

type SAFEARRAYBOUND SafeArrayBound

Obsolete, exists for backwards compatibility. Use SafeArrayBound

type SafeArray

type SafeArray struct {
	Dimensions   uint16
	FeaturesFlag uint16
	ElementsSize uint32
	LocksAmount  uint32
	Data         uint32
	Bounds       SafeArrayBound
}

type SafeArrayBound

type SafeArrayBound struct {
	Elements   uint32
	LowerBound int32
}

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) ToStringArray

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

func (*SafeArrayConversion) TotalElements

func (sac *SafeArrayConversion) TotalElements(index uint32) (totalElements int64, 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
}

type TYPEDESC

type TYPEDESC struct {
	Hreftype uint32
	VT       uint16
}

type UnknownLike

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

type VARIANT

type VARIANT struct {
	VT uint16 //  2

	// On 32-bit windows, sizeof(VARIANT) is 16. 64-bit is 24. Although an int would
	// be that size, stick with int64 due to conversions in invoke. 32-bit machines
	// will thus have 8-bytes of unused space.
	Val  int64
	Val2 int64
	// contains filtered or unexported fields
}

func (*VARIANT) Clear

func (v *VARIANT) Clear() error

func (*VARIANT) ToArray

func (v *VARIANT) ToArray() *SafeArrayConversion

func (*VARIANT) ToIDispatch

func (v *VARIANT) ToIDispatch() *IDispatch

func (*VARIANT) ToIUnknown

func (v *VARIANT) ToIUnknown() *IUnknown

func (*VARIANT) ToString

func (v *VARIANT) ToString() string

func (*VARIANT) Value

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

Returns v's value based on its VALTYPE. 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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