forked from auuunya/go-element
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunknown.go
59 lines (51 loc) · 1.21 KB
/
unknown.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package uiautomation
import (
"fmt"
"syscall"
"unsafe"
)
type IUnKnown struct {
Vtbl *IUnKnownVtbl
}
type IUnKnownVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
}
func NewIUnKnown(v unsafe.Pointer) *IUnKnown {
return (*IUnKnown)(unsafe.Pointer(v))
}
func AddRef(v *IUnKnown) uint32 {
ret, _, _ := syscall.SyscallN(
(*IUnKnownVtbl)(unsafe.Pointer(v.Vtbl)).AddRef,
uintptr(unsafe.Pointer(v)),
)
return uint32(ret)
}
func Release(v *IUnKnown) uint32 {
ret, _, _ := syscall.SyscallN(
(*IUnKnownVtbl)(unsafe.Pointer(v.Vtbl)).Release,
uintptr(unsafe.Pointer(v)),
)
return uint32(ret)
}
func QueryInterface(v *IUnKnown, riid *syscall.GUID) (unsafe.Pointer, error) {
var retVal unsafe.Pointer
ret, _, _ := syscall.SyscallN(
(*IUnKnownVtbl)(unsafe.Pointer(v.Vtbl)).QueryInterface,
uintptr(unsafe.Pointer(v)),
uintptr(unsafe.Pointer(riid)),
uintptr(unsafe.Pointer(&retVal)),
)
if ret != 0 {
return nil, HResult(ret)
}
return retVal, nil
}
func HResult(ret uintptr) error {
// error info https://pkg.go.dev/golang.org/x/sys/windows
return fmt.Errorf("COM Error: 0x%x", ret)
}
func UnKnownToUintptr(obj *interface{}) uintptr {
return uintptr(unsafe.Pointer(obj))
}