-
Notifications
You must be signed in to change notification settings - Fork 0
/
iclrmetahost.go
112 lines (100 loc) · 2.57 KB
/
iclrmetahost.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package go_net
import (
"fmt"
"golang.org/x/sys/windows"
"syscall"
"unsafe"
)
// ICLRMetaHost ICLRMetaHost 结构实现
type ICLRMetaHost struct {
lpVtbl *ICLRMetaHostVtbl
}
type ICLRMetaHostVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
GetRuntime uintptr
GetVersionFromFile uintptr
EnumerateInstalledRuntimes uintptr
EnumerateLoadedRuntimes uintptr
RequestRuntimeLoadedNotification uintptr
QueryLegacyV2RuntimeBinding uintptr
ExitProcess uintptr
}
// 函数后期无用,不做实例化(甚至可以不声明)
/*
func (obj *ICLRMetaHost)EnumerateLoadedRuntimes(){}
func (obj *ICLRMetaHost)ExitProcess(){}
func (obj *ICLRMetaHost)GetVersionFromFile(){}
func (obj *ICLRMetaHost)RequestRuntimeLoadedNotification(){}
func (obj *ICLRMetaHost)QueryLegacyV2RuntimeBinding(){}
*/
func (obj *ICLRMetaHost) GetRuntime(pwzVersion *uint16, riid windows.GUID) (ppRuntime *ICLRRuntimeInfo, err error) {
hr, _, err := syscall.Syscall6(
obj.lpVtbl.GetRuntime,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(pwzVersion)),
uintptr(unsafe.Pointer(&IID_ICLRRuntimeInfo)),
uintptr(unsafe.Pointer(&ppRuntime)),
0,
0,
)
if err != syscall.Errno(0) {
err = fmt.Errorf("there was an error calling the ICLRMetaHost::GetRuntime method:%s", err)
return
}
if hr != 0x00 {
err = fmt.Errorf("the ICLRMetaHost::GetRuntime method returned a non-zero HRESULT: 0x%x", hr)
return
}
err = nil
return
}
func (obj *ICLRMetaHost)AddRef() uintptr {
ret,_,_ := syscall.Syscall(
obj.lpVtbl.AddRef,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
func (obj *ICLRMetaHost)Release() uintptr {
ret,_,_ := syscall.Syscall(
obj.lpVtbl.Release,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
func (obj *ICLRMetaHost)QueryInterface() uintptr {
ret,_ ,_ := syscall.Syscall(
obj.lpVtbl.QueryInterface,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
//https://docs.microsoft.com/zh-cn/dotnet/framework/unmanaged-api/hosting/iclrmetahost-enumerateinstalledruntimes-method
func (obj *ICLRMetaHost)EnumerateInstalledRuntimes()(ppEnumerator *IEnumUnknown, err error){
hr, _, err := syscall.Syscall(
obj.lpVtbl.EnumerateInstalledRuntimes,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&ppEnumerator)),
0,
)
if err != syscall.Errno(0) {
err = fmt.Errorf("there was an error calling the ICLRMetaHost::EnumerateInstalledRuntimes method:\r\n%s", err)
return
}
if hr != 0x00 {
err = fmt.Errorf("the ICLRMetaHost::EnumerateInstalledRuntimes method returned a non-zero HRESULT: 0x%x", hr)
return
}
err = nil
return
}