forked from auuunya/go-element
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispatch.go
378 lines (364 loc) · 8.62 KB
/
dispatch.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
package uiautomation
import (
"syscall"
"unsafe"
)
type IDispatch struct {
vtbl *IUnKnown
}
type IDispatchVtbl struct {
IUnKnownVtbl
GetIDsOfNames uintptr
GetTypeInfo uintptr
GetTypeInfoCount uintptr
Invoke uintptr
}
func GetIDsOfNames(v *IDispatch, in *syscall.GUID, in2 uint16, in3, in4 uint32) (int32, error) {
var retVal int32
ret, _, _ := syscall.SyscallN(
(*IDispatchVtbl)(unsafe.Pointer(v.vtbl)).GetIDsOfNames,
uintptr(unsafe.Pointer(v)),
uintptr(unsafe.Pointer(in)),
uintptr(in2),
uintptr(in3),
uintptr(in4),
uintptr(unsafe.Pointer(&retVal)),
)
if ret != 0 {
return -1, HResult(ret)
}
return retVal, nil
}
func GetTypeInfo(v *IDispatch, in, in2 uint32) (*ITypeInfo, error) {
var retVal *ITypeInfo
ret, _, _ := syscall.SyscallN(
(*IDispatchVtbl)(unsafe.Pointer(v.vtbl)).GetTypeInfo,
uintptr(unsafe.Pointer(v)),
uintptr(in),
uintptr(in2),
uintptr(unsafe.Pointer(&retVal)),
)
if ret != 0 {
return nil, HResult(ret)
}
return retVal, nil
}
func GetTypeInfoCount(v *IDispatch) (uint32, error) {
var retVal uint32
ret, _, _ := syscall.SyscallN(
(*IDispatchVtbl)(unsafe.Pointer(v.vtbl)).GetTypeInfoCount,
uintptr(unsafe.Pointer(v)),
uintptr(unsafe.Pointer(&retVal)),
)
if ret != 0 {
return 0, HResult(ret)
}
return retVal, nil
}
type InvokeReq struct {
DispIdMember int32
Riid syscall.GUID
LcId uint32
WFlags uint16
PDispParams *TagDispParams
}
type InvokeResp struct {
PDispParams *TagDispParams
PVarResult *VARIANT
PExcepInfo *TagExcepInfo
PuArgErr uint32
}
func Invoke(v *IDispatch, opt *InvokeReq) (*InvokeResp, error) {
var retVal *InvokeResp
ret, _, _ := syscall.SyscallN(
(*IDispatchVtbl)(unsafe.Pointer(v.vtbl)).Invoke,
uintptr(unsafe.Pointer(v)),
uintptr(opt.DispIdMember),
uintptr(unsafe.Pointer(&opt.Riid)),
uintptr(opt.LcId),
uintptr(opt.WFlags),
uintptr(unsafe.Pointer(opt.PDispParams)),
uintptr(unsafe.Pointer(&retVal.PDispParams)),
uintptr(unsafe.Pointer(&retVal.PVarResult)),
uintptr(unsafe.Pointer(&retVal.PExcepInfo)),
uintptr(unsafe.Pointer(&retVal.PuArgErr)),
)
if ret != 0 {
return nil, HResult(ret)
}
return retVal, nil
}
type ITypeInfo struct {
vtbl *IUnKnown
}
type ITypeInfoVtbl struct {
IUnKnownVtbl
AddressOfMember uintptr
CreateInstance uintptr
GetContainingTypeLib uintptr
GetDllEntry uintptr
GetDocumentation uintptr
GetFuncDesc uintptr
GetIDsOfNames uintptr
GetImplTypeFlags uintptr
GetMops uintptr
GetNames uintptr
GetRefTypeInfo uintptr
GetRefTypeOfImplType uintptr
GetTypeAttr uintptr
GetTypeComp uintptr
GetVarDesc uintptr
Invoke uintptr
ReleaseFuncDesc uintptr
ReleaseTypeAttr uintptr
ReleaseVarDesc uintptr
}
// TODO:: ITypeInfo method
func newITypeInfo(unk *IUnKnown) *ITypeInfo {
return (*ITypeInfo)(unsafe.Pointer(unk))
}
func NewITypeInfo(unk *IUnKnown) *ITypeInfo {
return newITypeInfo(unk)
}
func (v *ITypeInfo) AddressOfMember(in int32, in2 TagInvokeKind) (unsafe.Pointer, error) {
var retVal unsafe.Pointer
ret, _, _ := syscall.SyscallN(
(*ITypeInfoVtbl)(unsafe.Pointer(v.vtbl)).AddressOfMember,
uintptr(unsafe.Pointer(v)),
uintptr(in),
uintptr(in2),
uintptr(unsafe.Pointer(&retVal)),
)
if ret != 0 {
return nil, HResult(ret)
}
return retVal, nil
}
func (v *ITypeInfo) CreateInstance(in *IUnKnown, in2 *syscall.GUID) (unsafe.Pointer, error) {
var retVal unsafe.Pointer
ret, _, _ := syscall.SyscallN(
(*ITypeInfoVtbl)(unsafe.Pointer(v.vtbl)).CreateInstance,
uintptr(unsafe.Pointer(v)),
uintptr(unsafe.Pointer(in)),
uintptr(unsafe.Pointer(in2)),
uintptr(unsafe.Pointer(&retVal)),
)
if ret != 0 {
return nil, HResult(ret)
}
return retVal, nil
}
func (v *ITypeInfo) GetContainingTypeLib() (*ITypeLib, int32, error) {
var retVal *ITypeLib
var retVal2 int32
ret, _, _ := syscall.SyscallN(
(*ITypeInfoVtbl)(unsafe.Pointer(v.vtbl)).GetContainingTypeLib,
uintptr(unsafe.Pointer(v)),
uintptr(unsafe.Pointer(&retVal)),
uintptr(unsafe.Pointer(&retVal2)),
)
if ret != 0 {
return nil, -1, HResult(ret)
}
return retVal, retVal2, nil
}
func (v *ITypeInfo) GetDllEntry(in int32, in2 TagInvokeKind) (string, string, uint16, error) {
var bstr uintptr
var bstr2 uintptr
var retVal3 uint16
ret, _, _ := syscall.SyscallN(
(*ITypeInfoVtbl)(unsafe.Pointer(v.vtbl)).GetDllEntry,
uintptr(unsafe.Pointer(v)),
uintptr(in),
uintptr(in2),
uintptr(unsafe.Pointer(&bstr)),
uintptr(unsafe.Pointer(&bstr2)),
uintptr(unsafe.Pointer(&retVal3)),
)
if ret != 0 {
return "", "", 0, HResult(ret)
}
var retVal string
var retVal2 string
if bstr != 0 {
retVal = bstr2str(bstr)
procSysAllocString.Call(uintptr(bstr))
}
if bstr2 != 0 {
retVal2 = bstr2str(bstr2)
procSysAllocString.Call(uintptr(bstr2))
}
return retVal, retVal2, retVal3, nil
}
func (v *ITypeInfo) GetDocumentation(in int32) (string, string, uint32, string, error) {
var bstr uintptr
var bstr2 uintptr
var retVal3 uint32
var bstr3 uintptr
ret, _, _ := syscall.SyscallN(
(*ITypeInfoVtbl)(unsafe.Pointer(v.vtbl)).GetDocumentation,
uintptr(unsafe.Pointer(v)),
uintptr(in),
uintptr(unsafe.Pointer(&bstr)),
uintptr(unsafe.Pointer(&bstr2)),
uintptr(unsafe.Pointer(&retVal3)),
uintptr(unsafe.Pointer(&bstr3)),
)
if ret != 0 {
return "", "", 0, "", HResult(ret)
}
var retVal string
var retVal2 string
var retVal4 string
if bstr != 0 {
retVal = bstr2str(bstr)
procSysAllocString.Call(uintptr(bstr))
}
if bstr2 != 0 {
retVal2 = bstr2str(bstr2)
procSysAllocString.Call(uintptr(bstr2))
}
if bstr3 != 0 {
retVal4 = bstr2str(bstr2)
procSysAllocString.Call(uintptr(bstr3))
}
return retVal, retVal2, retVal3, retVal4, nil
}
func (v *ITypeInfo) GetFuncDesc(in uint32) (*TagFuncDesc, error) {
var retVal *TagFuncDesc
ret, _, _ := syscall.SyscallN(
(*ITypeInfoVtbl)(unsafe.Pointer(v.vtbl)).GetFuncDesc,
uintptr(unsafe.Pointer(v)),
uintptr(in),
uintptr(unsafe.Pointer(&retVal)),
)
if ret != 0 {
return nil, HResult(ret)
}
return retVal, nil
}
func (v *ITypeInfo) GetIDsOfNames() error {
return nil
}
func (v *ITypeInfo) GetImplTypeFlags(in uint32) (int32, error) {
var retVal int32
ret, _, _ := syscall.SyscallN(
(*ITypeInfoVtbl)(unsafe.Pointer(v.vtbl)).GetImplTypeFlags,
uintptr(unsafe.Pointer(v)),
uintptr(in),
uintptr(unsafe.Pointer(&retVal)),
)
if ret != 0 {
return -1, HResult(ret)
}
return retVal, nil
}
func (v *ITypeInfo) GetMops(in int32) (string, error) {
var bstr uintptr
ret, _, _ := syscall.SyscallN(
(*ITypeInfoVtbl)(unsafe.Pointer(v.vtbl)).GetMops,
uintptr(unsafe.Pointer(v)),
uintptr(in),
uintptr(unsafe.Pointer(&bstr)),
)
if ret != 0 {
return "", HResult(ret)
}
var retVal string
if bstr != 0 {
retVal = bstr2str(bstr)
procSysAllocString.Call(uintptr(bstr))
}
return retVal, nil
}
func (v *ITypeInfo) GetNames(in int32, in2 uint32) (string, uint32, error) {
var bstr uintptr
var retVal2 uint32
ret, _, _ := syscall.SyscallN(
(*ITypeInfoVtbl)(unsafe.Pointer(v.vtbl)).GetNames,
uintptr(unsafe.Pointer(v)),
uintptr(in),
uintptr(unsafe.Pointer(&bstr)),
uintptr(in2),
uintptr(unsafe.Pointer(&retVal2)),
)
if ret != 0 {
return "", 0, HResult(ret)
}
var retVal string
if bstr != 0 {
retVal = bstr2str(bstr)
procSysAllocString.Call(uintptr(bstr))
}
return retVal, retVal2, nil
}
func (v *ITypeInfo) GetRefTypeInfo() error {
return nil
}
func (v *ITypeInfo) GetRefTypeOfImplType() error {
return nil
}
func (v *ITypeInfo) GetTypeAttr() error {
return nil
}
func (v *ITypeInfo) GetTypeComp() error {
return nil
}
func (v *ITypeInfo) GetVarDesc() error {
return nil
}
func (v *ITypeInfo) Invoke() error {
return nil
}
func (v *ITypeInfo) ReleaseFuncDesc() error {
return nil
}
func (v *ITypeInfo) ReleaseTypeAttr() error {
return nil
}
func (v *ITypeInfo) ReleaseVarDesc() error {
return nil
}
type ITypeLib struct {
vtbl *IUnKnown
}
type ITypeLibVtbl struct {
IUnKnownVtbl
}
// TODO:: ITypeLib method
func newITypeLib(unk *IUnKnown) *ITypeLib {
return (*ITypeLib)(unsafe.Pointer(unk))
}
func NewITypeLib(unk *IUnKnown) *ITypeLib {
return newITypeLib(unk)
}
func (v *ITypeLib) FindName() error {
return nil
}
func (v *ITypeLib) GetDocumentation() error {
return nil
}
func (v *ITypeLib) GetLibAttr() error {
return nil
}
func (v *ITypeLib) GetTypeComp() error {
return nil
}
func (v *ITypeLib) GetTypeInfo() error {
return nil
}
func (v *ITypeLib) GetTypeInfoCount() error {
return nil
}
func (v *ITypeLib) GetTypeInfoOfGuid() error {
return nil
}
func (v *ITypeLib) GetTypeInfoType() error {
return nil
}
func (v *ITypeLib) IsName() error {
return nil
}
func (v *ITypeLib) ReleaseTLibAttr() error {
return nil
}