github.com/hspan/go-ole@v0.0.0/iunknown.go (about)

     1  package ole
     2  
     3  import "unsafe"
     4  
     5  type IUnknown struct {
     6  	RawVTable *interface{}
     7  }
     8  
     9  type IUnknownVtbl struct {
    10  	QueryInterface uintptr
    11  	AddRef         uintptr
    12  	Release        uintptr
    13  }
    14  
    15  type UnknownLike interface {
    16  	QueryInterface(iid *GUID) (disp *IDispatch, err error)
    17  	AddRef() int32
    18  	Release() int32
    19  }
    20  
    21  func (v *IUnknown) VTable() *IUnknownVtbl {
    22  	return (*IUnknownVtbl)(unsafe.Pointer(v.RawVTable))
    23  }
    24  
    25  func (v *IUnknown) PutQueryInterface(interfaceID *GUID, obj interface{}) error {
    26  	return reflectQueryInterface(v, v.VTable().QueryInterface, interfaceID, obj)
    27  }
    28  
    29  func (v *IUnknown) IDispatch(interfaceID *GUID) (dispatch *IDispatch, err error) {
    30  	err = v.PutQueryInterface(interfaceID, &dispatch)
    31  	return
    32  }
    33  
    34  func (v *IUnknown) IEnumVARIANT(interfaceID *GUID) (enum *IEnumVARIANT, err error) {
    35  	err = v.PutQueryInterface(interfaceID, &enum)
    36  	return
    37  }
    38  
    39  func (v *IUnknown) QueryInterface(iid *GUID) (*IDispatch, error) {
    40  	return queryInterface(v, iid)
    41  }
    42  
    43  func (v *IUnknown) MustQueryInterface(iid *GUID) (disp *IDispatch) {
    44  	unk, err := queryInterface(v, iid)
    45  	if err != nil {
    46  		panic(err)
    47  	}
    48  	return unk
    49  }
    50  
    51  func (v *IUnknown) AddRef() int32 {
    52  	return addRef(v)
    53  }
    54  
    55  func (v *IUnknown) Release() int32 {
    56  	return release(v)
    57  }