github.com/gofiber/fiber/v2@v2.47.0/internal/go-ole/iinspectable_windows.go (about)

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