forked from go-ole/go-ole
-
Notifications
You must be signed in to change notification settings - Fork 1
/
safearray_test.go
108 lines (87 loc) · 2.23 KB
/
safearray_test.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
package ole
// This tests more than one function. It tests all of the functions needed in
// order to retrieve an SafeArray populated with Strings.
func Example_safeArrayGetElementString() {
CoInitialize(0)
defer CoUninitialize()
clsid, err := CLSIDFromProgID("QBXMLRP2.RequestProcessor.1")
if err != nil {
if err.(*OleError).Code() == CO_E_CLASSSTRING {
return
}
}
unknown, err := CreateInstance(clsid, IID_IUnknown)
if err != nil {
return
}
defer unknown.Release()
dispatch, err := unknown.QueryInterface(IID_IDispatch)
if err != nil {
return
}
var dispid []int32
dispid, err = dispatch.GetIDsOfName([]string{"OpenConnection2"})
if err != nil {
return
}
var result *VARIANT
_, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", "Test Application 1", 1)
if err != nil {
return
}
dispid, err = dispatch.GetIDsOfName([]string{"BeginSession"})
if err != nil {
return
}
result, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", 2)
if err != nil {
return
}
ticket := result.ToString()
dispid, err = dispatch.GetIDsOfName([]string{"QBXMLVersionsForSession"})
if err != nil {
return
}
result, err = dispatch.Invoke(dispid[0], DISPATCH_PROPERTYGET, ticket)
if err != nil {
return
}
// Where the real tests begin.
var qbXMLVersions *SafeArray
var qbXmlVersionStrings []string
qbXMLVersions = result.ToArray().Array
// Get array bounds
var LowerBounds int32
var UpperBounds int32
LowerBounds, err = safeArrayGetLBound(qbXMLVersions, 1)
if err != nil {
return
}
UpperBounds, err = safeArrayGetUBound(qbXMLVersions, 1)
if err != nil {
return
}
totalElements := UpperBounds - LowerBounds + 1
qbXmlVersionStrings = make([]string, totalElements)
for i := int32(0); i < totalElements; i++ {
qbXmlVersionStrings[i], _ = safeArrayGetElementString(qbXMLVersions, i)
}
// Release Safe Array memory
safeArrayDestroy(qbXMLVersions)
dispid, err = dispatch.GetIDsOfName([]string{"EndSession"})
if err != nil {
return
}
_, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, ticket)
if err != nil {
return
}
dispid, err = dispatch.GetIDsOfName([]string{"CloseConnection"})
if err != nil {
return
}
_, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD)
if err != nil {
return
}
}