iinspectable_windows.go 1.4 KB

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