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

     1  // +build windows
     2  
     3  package ole
     4  
     5  import (
     6  	"reflect"
     7  	"syscall"
     8  	"unsafe"
     9  )
    10  
    11  func reflectQueryInterface(self interface{}, method uintptr, interfaceID *GUID, obj interface{}) (err error) {
    12  	selfValue := reflect.ValueOf(self).Elem()
    13  	objValue := reflect.ValueOf(obj).Elem()
    14  
    15  	hr, _, _ := syscall.Syscall(
    16  		method,
    17  		3,
    18  		selfValue.UnsafeAddr(),
    19  		uintptr(unsafe.Pointer(interfaceID)),
    20  		objValue.Addr().Pointer())
    21  	if hr != 0 {
    22  		err = NewError(hr)
    23  	}
    24  	return
    25  }
    26  
    27  func queryInterface(unk *IUnknown, iid *GUID) (disp *IDispatch, err error) {
    28  	hr, _, _ := syscall.Syscall(
    29  		unk.VTable().QueryInterface,
    30  		3,
    31  		uintptr(unsafe.Pointer(unk)),
    32  		uintptr(unsafe.Pointer(iid)),
    33  		uintptr(unsafe.Pointer(&disp)))
    34  	if hr != 0 {
    35  		err = NewError(hr)
    36  	}
    37  	return
    38  }
    39  
    40  func addRef(unk *IUnknown) int32 {
    41  	ret, _, _ := syscall.Syscall(
    42  		unk.VTable().AddRef,
    43  		1,
    44  		uintptr(unsafe.Pointer(unk)),
    45  		0,
    46  		0)
    47  	return int32(ret)
    48  }
    49  
    50  func release(unk *IUnknown) int32 {
    51  	ret, _, _ := syscall.Syscall(
    52  		unk.VTable().Release,
    53  		1,
    54  		uintptr(unsafe.Pointer(unk)),
    55  		0,
    56  		0)
    57  	return int32(ret)
    58  }