-
Notifications
You must be signed in to change notification settings - Fork 56
/
iclrruntimehost.go
101 lines (91 loc) · 2.44 KB
/
iclrruntimehost.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
// +build windows
package clr
import (
"syscall"
"unsafe"
)
type ICLRRuntimeHost struct {
vtbl *ICLRRuntimeHostVtbl
}
type ICLRRuntimeHostVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
Start uintptr
Stop uintptr
SetHostControl uintptr
GetCLRControl uintptr
UnloadAppDomain uintptr
ExecuteInAppDomain uintptr
GetCurrentAppDomainId uintptr
ExecuteApplication uintptr
ExecuteInDefaultAppDomain uintptr
}
// GetICLRRuntimeHost is a wrapper function that takes an ICLRRuntimeInfo object and
// returns an ICLRRuntimeHost and loads it into the current process
func GetICLRRuntimeHost(runtimeInfo *ICLRRuntimeInfo) (*ICLRRuntimeHost, error) {
var pRuntimeHost uintptr
hr := runtimeInfo.GetInterface(&CLSID_CLRRuntimeHost, &IID_ICLRRuntimeHost, &pRuntimeHost)
err := checkOK(hr, "runtimeInfo.GetInterface")
if err != nil {
return nil, err
}
runtimeHost := NewICLRRuntimeHostFromPtr(pRuntimeHost)
hr = runtimeHost.Start()
err = checkOK(hr, "runtimeHost.Start")
return runtimeHost, err
}
func NewICLRRuntimeHostFromPtr(ppv uintptr) *ICLRRuntimeHost {
return (*ICLRRuntimeHost)(unsafe.Pointer(ppv))
}
func (obj *ICLRRuntimeHost) AddRef() uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.AddRef,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
func (obj *ICLRRuntimeHost) Release() uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.Release,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
func (obj *ICLRRuntimeHost) Start() uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.Start,
1,
uintptr(unsafe.Pointer(obj)),
0,
0)
return ret
}
func (obj *ICLRRuntimeHost) ExecuteInDefaultAppDomain(pwzAssemblyPath, pwzTypeName, pwzMethodName, pwzArgument, pReturnValue *uint16) uintptr {
ret, _, _ := syscall.Syscall9(
obj.vtbl.ExecuteInDefaultAppDomain,
6,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(pwzAssemblyPath)),
uintptr(unsafe.Pointer(pwzTypeName)),
uintptr(unsafe.Pointer(pwzMethodName)),
uintptr(unsafe.Pointer(pwzArgument)),
uintptr(unsafe.Pointer(pReturnValue)),
0,
0,
0)
return ret
}
func (obj *ICLRRuntimeHost) GetCurrentAppDomainID(pdwAppDomainId *uint16) uintptr {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetCurrentAppDomainId,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(pdwAppDomainId)),
0)
return ret
}