forked from ropnop/go-clr
-
Notifications
You must be signed in to change notification settings - Fork 12
/
ienumunknown.go
82 lines (75 loc) · 2.08 KB
/
ienumunknown.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// +build windows
package clr
import (
"fmt"
"syscall"
"unsafe"
)
type IEnumUnknown struct {
vtbl *IEnumUnknownVtbl
}
// IEnumUnknownVtbl Enumerates objects implementing the root COM interface, IUnknown.
// Commonly implemented by a component containing multiple objects. For more information, see IEnumUnknown.
// https://docs.microsoft.com/en-us/windows/win32/api/objidl/nn-objidl-ienumunknown
type IEnumUnknownVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
// Next Retrieves the specified number of items in the enumeration sequence.
Next uintptr
// Skip Skips over the specified number of items in the enumeration sequence.
Skip uintptr
// Reset Resets the enumeration sequence to the beginning.
Reset uintptr
// Clone Creates a new enumerator that contains the same enumeration state as the current one.
Clone uintptr
}
func (obj *IEnumUnknown) AddRef() uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.AddRef,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
func (obj *IEnumUnknown) Release() uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.Release,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
// Next retrieves the specified number of items in the enumeration sequence.
// HRESULT Next(
// ULONG celt,
// IUnknown **rgelt,
// ULONG *pceltFetched
// );
// https://docs.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-ienumunknown-next
func (obj *IEnumUnknown) Next(celt uint32, pEnumRuntime unsafe.Pointer, pceltFetched *uint32) (hresult int, err error) {
debugPrint("Entering into ienumunknown.Next()...")
hr, _, err := syscall.Syscall6(
obj.vtbl.Next,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(celt),
uintptr(pEnumRuntime),
uintptr(unsafe.Pointer(pceltFetched)),
0,
0,
)
if err != syscall.Errno(0) {
err = fmt.Errorf("there was an error calling the IEnumUnknown::Next method:\r\n%s", err)
return
}
if hr != S_OK && hr != S_FALSE {
err = fmt.Errorf("the IEnumUnknown::Next method method returned a non-zero HRESULT: 0x%x", hr)
return
}
err = nil
hresult = int(hr)
return
}