-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers_test.go
100 lines (80 loc) · 2.04 KB
/
helpers_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
package safearray
import (
"github.com/go-ole/com"
"github.com/go-ole/idispatch"
"github.com/go-ole/iunknown"
)
// This tests more than one function. It tests all of the functions needed in
// order to retrieve a SafeArray populated with Strings.
func ExampleGetElementString_quickbooks() {
com.CoInitialize()
defer com.CoUninitialize()
clsid, err := com.ClassIDFromProgramID("QBXMLRP2.RequestProcessor.1")
if err != nil {
if err.(*com.OleError).Code() == com.COMObjectClassStringErrorCode {
return
}
t.Log(err)
t.FailNow()
}
var unknown *iunknown.Unknown
var dispatch *idispatch.Dispatch
err := com.CoCreateInstance(clsid, iunknown.InterfaceID, &unknown)
if err != nil {
return
}
defer unknown.Release()
err := unknown.QueryInterface(idispatch.InterfaceID, &dispatch)
if err != nil {
return
}
var result *com.Variant
_, err = idispatch.CallMethod(dispatch, "OpenConnection2", "", "Test Application 1", 1)
if err != nil {
return
}
result, err = idispatch.CallMethod(dispatch, "BeginSession", "", 2)
if err != nil {
return
}
ticket := result.ToString()
result, err = idispatch.GetProperty(dispatch, "QBXMLVersionsForSession", ticket)
if err != nil {
return
}
//
// Example begins.
//
var qbXMLVersions *COMArray
var qbXMLVersionStrings []string
qbXMLVersions = result.ToArray().Array
// Release Safe Array memory
defer Destroy(qbXMLVersions)
// Get array bounds
var LowerBounds int64
var UpperBounds int64
LowerBounds, err = GetLowerBound(qbXMLVersions, 1)
if err != nil {
return
}
UpperBounds, err = GetUpperBound(qbXMLVersions, 1)
if err != nil {
return
}
totalElements := UpperBounds - LowerBounds + 1
qbXMLVersionStrings = make([]string, totalElements)
for i := int64(0); i < totalElements; i++ {
qbXMLVersionStrings[int32(i)], _ = GetElementString(qbXMLVersions, i)
}
//
// Example ends.
//
result, err = idispatch.CallMethod(dispatch, "EndSession", ticket)
if err != nil {
return
}
result, err = idispatch.CallMethod(dispatch, "CloseConnection")
if err != nil {
return
}
}