github.com/hspan/go-ole@v0.0.0/iinspectable_windows.go (about) 1 // +build windows 2 3 package ole 4 5 import ( 6 "bytes" 7 "encoding/binary" 8 "reflect" 9 "syscall" 10 "unsafe" 11 ) 12 13 func (v *IInspectable) GetIids() (iids []*GUID, err error) { 14 var count uint32 15 var array uintptr 16 hr, _, _ := syscall.Syscall( 17 v.VTable().GetIIds, 18 3, 19 uintptr(unsafe.Pointer(v)), 20 uintptr(unsafe.Pointer(&count)), 21 uintptr(unsafe.Pointer(&array))) 22 if hr != 0 { 23 err = NewError(hr) 24 return 25 } 26 defer CoTaskMemFree(array) 27 28 iids = make([]*GUID, count) 29 byteCount := count * uint32(unsafe.Sizeof(GUID{})) 30 slicehdr := reflect.SliceHeader{Data: array, Len: int(byteCount), Cap: int(byteCount)} 31 byteSlice := *(*[]byte)(unsafe.Pointer(&slicehdr)) 32 reader := bytes.NewReader(byteSlice) 33 for i := range iids { 34 guid := GUID{} 35 err = binary.Read(reader, binary.LittleEndian, &guid) 36 if err != nil { 37 return 38 } 39 iids[i] = &guid 40 } 41 return 42 } 43 44 func (v *IInspectable) GetRuntimeClassName() (s string, err error) { 45 var hstring HString 46 hr, _, _ := syscall.Syscall( 47 v.VTable().GetRuntimeClassName, 48 2, 49 uintptr(unsafe.Pointer(v)), 50 uintptr(unsafe.Pointer(&hstring)), 51 0) 52 if hr != 0 { 53 err = NewError(hr) 54 return 55 } 56 s = hstring.String() 57 DeleteHString(hstring) 58 return 59 } 60 61 func (v *IInspectable) GetTrustLevel() (level uint32, err error) { 62 hr, _, _ := syscall.Syscall( 63 v.VTable().GetTrustLevel, 64 2, 65 uintptr(unsafe.Pointer(v)), 66 uintptr(unsafe.Pointer(&level)), 67 0) 68 if hr != 0 { 69 err = NewError(hr) 70 } 71 return 72 }