-
Notifications
You must be signed in to change notification settings - Fork 1
/
safearray_shared.go
354 lines (321 loc) · 12.2 KB
/
safearray_shared.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
// +build windows,!cgo
package com
import "unsafe"
import "github.com/go-ole/com"
var (
procSafeArrayAccessData, _ = modoleaut32.FindProc("SafeArrayAccessData")
procSafeArrayAllocData, _ = modoleaut32.FindProc("SafeArrayAllocData")
procSafeArrayAllocDescriptor, _ = modoleaut32.FindProc("SafeArrayAllocDescriptor")
procSafeArrayAllocDescriptorEx, _ = modoleaut32.FindProc("SafeArrayAllocDescriptorEx")
procSafeArrayCopy, _ = modoleaut32.FindProc("SafeArrayCopy")
procSafeArrayCopyData, _ = modoleaut32.FindProc("SafeArrayCopyData")
procSafeArrayCreate, _ = modoleaut32.FindProc("SafeArrayCreate")
procSafeArrayCreateEx, _ = modoleaut32.FindProc("SafeArrayCreateEx")
procSafeArrayCreateVector, _ = modoleaut32.FindProc("SafeArrayCreateVector")
procSafeArrayCreateVectorEx, _ = modoleaut32.FindProc("SafeArrayCreateVectorEx")
procSafeArrayDestroy, _ = modoleaut32.FindProc("SafeArrayDestroy")
procSafeArrayDestroyData, _ = modoleaut32.FindProc("SafeArrayDestroyData")
procSafeArrayDestroyDescriptor, _ = modoleaut32.FindProc("SafeArrayDestroyDescriptor")
procSafeArrayGetDim, _ = modoleaut32.FindProc("SafeArrayGetDim")
procSafeArrayGetElement, _ = modoleaut32.FindProc("SafeArrayGetElement")
procSafeArrayGetElemsize, _ = modoleaut32.FindProc("SafeArrayGetElemsize")
procSafeArrayGetIID, _ = modoleaut32.FindProc("SafeArrayGetIID")
procSafeArrayGetLBound, _ = modoleaut32.FindProc("SafeArrayGetLBound")
procSafeArrayGetUBound, _ = modoleaut32.FindProc("SafeArrayGetUBound")
procSafeArrayGetVartype, _ = modoleaut32.FindProc("SafeArrayGetVartype")
procSafeArrayLock, _ = modoleaut32.FindProc("SafeArrayLock")
procSafeArrayPtrOfIndex, _ = modoleaut32.FindProc("SafeArrayPtrOfIndex")
procSafeArrayUnaccessData, _ = modoleaut32.FindProc("SafeArrayUnaccessData")
procSafeArrayUnlock, _ = modoleaut32.FindProc("SafeArrayUnlock")
procSafeArrayPutElement, _ = modoleaut32.FindProc("SafeArrayPutElement")
procSafeArrayRedim, _ = modoleaut32.FindProc("SafeArrayRedim")
procSafeArraySetIID, _ = modoleaut32.FindProc("SafeArraySetIID")
procSafeArrayGetRecordInfo, _ = modoleaut32.FindProc("SafeArrayGetRecordInfo")
procSafeArraySetRecordInfo, _ = modoleaut32.FindProc("SafeArraySetRecordInfo")
)
// AccessData returns raw array.
//
// AKA: SafeArrayAccessData in Windows API.
func AccessData(safearray *COMArray) (element uintptr, err error) {
err = com.HResultToError(procSafeArrayAccessData.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(unsafe.Pointer(&element))))
return
}
// UnaccessData releases raw array.
//
// AKA: SafeArrayUnaccessData in Windows API.
func UnaccessData(safearray *COMArray) (err error) {
err = com.HResultToError(procSafeArrayUnaccessData.Call(uintptr(unsafe.Pointer(safearray))))
return
}
// AllocateArrayData allocates SafeArray.
//
// AKA: SafeArrayAllocData in Windows API.
func AllocateArrayData(safearray *COMArray) (err error) {
err = com.HResultToError(procSafeArrayAllocData.Call(uintptr(unsafe.Pointer(safearray))))
return
}
// AllocateArrayDescriptor allocates SafeArray.
//
// AKA: SafeArrayAllocDescriptor in Windows API.
func AllocateArrayDescriptor(dimensions uint32) (safearray *COMArray, err error) {
err = com.HResultToError(procSafeArrayAllocDescriptor.Call(
uintptr(dimensions),
uintptr(unsafe.Pointer(&safearray))))
return
}
// AllocateArrayDescriptorEx allocates SafeArray.
//
// AKA: SafeArrayAllocDescriptorEx in Windows API.
func AllocateArrayDescriptorEx(variantType com.VariantType, dimensions uint32) (safearray *COMArray, err error) {
err = com.HResultToError(procSafeArrayAllocDescriptorEx.Call(
uintptr(variantType),
uintptr(dimensions),
uintptr(unsafe.Pointer(&safearray))))
return
}
// Duplicate returns copy of SafeArray.
//
// AKA: SafeArrayCopy in Windows API.
func Duplicate(original *COMArray) (safearray *COMArray, err error) {
err = com.HResultToError(procSafeArrayCopy.Call(
uintptr(unsafe.Pointer(original)),
uintptr(unsafe.Pointer(&safearray))))
return
}
// DuplicateData duplicates SafeArray into another SafeArray object.
//
// AKA: SafeArrayCopyData in Windows API.
func DuplicateData(original, duplicate *COMArray) (err error) {
err = com.HResultToError(procSafeArrayCopyData.Call(
uintptr(unsafe.Pointer(original)),
uintptr(unsafe.Pointer(&duplicate))))
return
}
// CreateArray creates SafeArray.
//
// AKA: SafeArrayCreate in Windows API.
func CreateArray(variantType com.VariantType, dimensions uint32, bounds *Bounds) (safearray *COMArray, err error) {
sa, _, err := procSafeArrayCreate.Call(
uintptr(variantType),
uintptr(dimensions),
uintptr(unsafe.Pointer(bounds)))
safearray = (*COMArray)(unsafe.Pointer(&sa))
return
}
// CreateArrayEx creates SafeArray.
//
// AKA: SafeArrayCreateEx in Windows API.
func CreateArrayEx(variantType com.VariantType, dimensions uint32, bounds *Bounds, extra uintptr) (safearray *COMArray, err error) {
sa, _, err := procSafeArrayCreateEx.Call(
uintptr(variantType),
uintptr(dimensions),
uintptr(unsafe.Pointer(bounds)),
extra)
safearray = (*COMArray)(unsafe.Pointer(sa))
return
}
// CreateArrayVector creates SafeArray.
//
// AKA: SafeArrayCreateVector in Windows API.
func CreateArrayVector(variantType com.VariantType, lowerBound int32, length uint32) (safearray *COMArray, err error) {
sa, _, err := procSafeArrayCreateVector.Call(
uintptr(variantType),
uintptr(lowerBound),
uintptr(length))
safearray = (*COMArray)(unsafe.Pointer(sa))
return
}
// CreateArrayVectorEx creates SafeArray.
//
// AKA: SafeArrayCreateVectorEx in Windows API.
func CreateArrayVectorEx(variantType com.VariantType, lowerBound int32, length uint32, extra uintptr) (safearray *COMArray, err error) {
sa, _, err := procSafeArrayCreateVectorEx.Call(
uintptr(variantType),
uintptr(lowerBound),
uintptr(length),
extra)
safearray = (*COMArray)(unsafe.Pointer(sa))
return
}
// Destroy destroys SafeArray object.
//
// AKA: SafeArrayDestroy in Windows API.
func Destroy(safearray *COMArray) error {
return com.HResultToError(procSafeArrayDestroy.Call(uintptr(unsafe.Pointer(safearray))))
}
// DestroyData destroys SafeArray object.
//
// AKA: SafeArrayDestroyData in Windows API.
func DestroyData(safearray *COMArray) error {
return com.HResultToError(procSafeArrayDestroyData.Call(uintptr(unsafe.Pointer(safearray))))
}
// DestroyDescriptor destroys SafeArray object.
//
// AKA: SafeArrayDestroyDescriptor in Windows API.
func DestroyDescriptor(safearray *COMArray) error {
return com.HResultToError(procSafeArrayDestroyDescriptor.Call(uintptr(unsafe.Pointer(safearray))))
}
// GetDimensions is the amount of dimensions in the SafeArray.
//
// SafeArrays may have multiple dimensions. Meaning, it could be
// multidimensional array.
//
// AKA: SafeArrayGetDim in Windows API.
func GetDimensions(safearray *COMArray) (dimensions uint32, err error) {
l, _, err := procSafeArrayGetDim.Call(uintptr(unsafe.Pointer(safearray)))
dimensions = *(*uint32)(unsafe.Pointer(l))
return
}
// GetElementSize is the element size in bytes.
//
// AKA: SafeArrayGetElemsize in Windows API.
func GetElementSize(safearray *COMArray) (length uint32, err error) {
l, _, err := procSafeArrayGetElemsize.Call(uintptr(unsafe.Pointer(safearray)))
length = *(*uint32)(unsafe.Pointer(l))
return
}
// GetElement retrieves element at given index.
func GetElement(safearray *COMArray, index int64) (element interface{}, err error) {
err = GetElementDirect(safearray, index, &element)
return
}
// GetElementDirect retrieves element value at given index.
//
// AKA: SafeArrayGetElement in Windows API.
func GetElementDirect(safearray *COMArray, index int64, element interface{}) (err error) {
err = com.HResultToError(procSafeArrayGetElement.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(index),
uintptr(unsafe.Pointer(&element))))
return
}
// GetInterfaceID is the InterfaceID of the elements in the SafeArray.
//
// AKA: SafeArrayGetIID in Windows API.
func GetInterfaceID(safearray *COMArray) (guid *com.GUID, err error) {
err = com.HResultToError(procSafeArrayGetIID.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(unsafe.Pointer(&guid))))
return
}
// GetLowerBound returns lower bounds of SafeArray.
//
// SafeArrays may have multiple dimensions. Meaning, it could be
// multidimensional array.
//
// AKA: SafeArrayGetLBound in Windows API.
func GetLowerBound(safearray *COMArray, dimension uint32) (lowerBound int64, err error) {
err = com.HResultToError(procSafeArrayGetLBound.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(dimension),
uintptr(unsafe.Pointer(&lowerBound))))
return
}
// GetUpperBound returns upper bounds of SafeArray.
//
// SafeArrays may have multiple dimensions. Meaning, it could be
// multidimensional array.
//
// AKA: SafeArrayGetUBound in Windows API.
func GetUpperBound(safearray *COMArray, dimension uint32) (upperBound int64, err error) {
err = com.HResultToError(procSafeArrayGetUBound.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(dimension),
uintptr(unsafe.Pointer(&upperBound))))
return
}
// GetVariantType returns data type of SafeArray.
//
// AKA: SafeArrayGetVartype in Windows API.
func GetVariantType(safearray *COMArray) (varType com.VariantType, err error) {
var vt uint16
err = com.HResultToError(procSafeArrayGetVartype.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(unsafe.Pointer(&vt))))
varType = com.VariantType(vt)
return
}
// Lock locks SafeArray for reading to modify SafeArray.
//
// This must be called during some calls to ensure that another process does not
// read or write to the SafeArray during editing.
//
// AKA: SafeArrayLock in Windows API.
func Lock(safearray *COMArray) (err error) {
err = com.HResultToError(procSafeArrayLock.Call(uintptr(unsafe.Pointer(safearray))))
return
}
// Unlock unlocks SafeArray for reading.
//
// AKA: SafeArrayUnlock in Windows API.
func Unlock(safearray *COMArray) (err error) {
err = com.HResultToError(procSafeArrayUnlock.Call(uintptr(unsafe.Pointer(safearray))))
return
}
// GetPointerOfIndex gets a pointer to an array element.
//
// This must be locked before use.
//
// AKA: SafeArrayPtrOfIndex in Windows API.
func GetPointerOfIndex(safearray *COMArray, index int64) (ref uintptr, err error) {
err = com.HResultToError(procSafeArrayPtrOfIndex.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(index),
uintptr(unsafe.Pointer(&ref))))
return
}
// SetInterfaceID sets the GUID of the interface for the specified safe
// array.
//
// AKA: SafeArraySetIID in Windows API.
func SetInterfaceID(safearray *COMArray, interfaceID *com.GUID) (err error) {
err = com.HResultToError(procSafeArraySetIID.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(unsafe.Pointer(interfaceID))))
return
}
// ResetDimensions changes the right-most (least significant) bound of the
// specified safe array.
//
// AKA: SafeArrayRedim in Windows API.
func ResetDimensions(safearray *COMArray, bounds *Bounds) error {
err = com.HResultToError(procSafeArrayRedim.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(unsafe.Pointer(bounds))))
return
}
// PutElement stores the data element at the specified location in the
// array.
//
// AKA: SafeArrayPutElement in Windows API.
func PutElement(safearray *COMArray, index int64, element interface{}) (err error) {
err = com.HResultToError(procSafeArrayPutElement.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(index),
uintptr(unsafe.Pointer(&element))))
return
}
// GetRecordInfo accesses IRecordInfo info for custom types.
//
// AKA: SafeArrayGetRecordInfo in Windows API.
//
// XXX: Must implement IRecordInfo interface for this to return.
func GetRecordInfo(safearray *COMArray) (recordInfo interface{}, err error) {
err = com.HResultToError(procSafeArrayGetRecordInfo.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(unsafe.Pointer(&recordInfo))))
return
}
// SetRecordInfo mutates IRecordInfo info for custom types.
//
// AKA: SafeArraySetRecordInfo in Windows API.
//
// XXX: Must implement IRecordInfo interface for this to return.
func SetRecordInfo(safearray *COMArray, recordInfo interface{}) (err error) {
err = com.HResultToError(procSafeArraySetRecordInfo.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(unsafe.Pointer(recordInfo))))
return
}