@cryptotaxi247 / kubo / commits / 5cab903db

force godeps to save windows import

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Oct 20, 2015 at 20:15 UTC 5cab903db7b2810b37a341ca27905d93448c6cb4
83 files changed +5939 -2
Godeps/Godeps.json
+10 -1
@@ -1,6 +1,6 @@
1 {
2 "ImportPath": "github.com/ipfs/go-ipfs",
3 - "GoVersion": "go1.5",
3 + "GoVersion": "go1.5.1",
4 "Packages": [
5 "./..."
6 ],
@@ -14,6 +14,10 @@
14 "Comment": "null-5",
15 "Rev": "75cd24fc2f2c2a2088577d12123ddee5f54e0675"
16 },
17 + {
18 + "ImportPath": "github.com/StackExchange/wmi",
19 + "Rev": "8730d7ed549382cb1f889a576a7223c137be7989"
20 + },
21 {
22 "ImportPath": "github.com/alecthomas/kingpin",
23 "Comment": "v2.1.0-2-gaedd543",
@@ -103,6 +107,11 @@
107 "ImportPath": "github.com/fd/go-nat",
108 "Rev": "50e7633d5f27d81490026a13e5b92d2e42d8c6bb"
109 },
110 + {
111 + "ImportPath": "github.com/go-ole/go-ole",
112 + "Comment": "v1.1.1-64-g4246eab",
113 + "Rev": "4246eab2a27c71c143f965432ace52990308d362"
114 + },
115 {
116 "ImportPath": "github.com/gogo/protobuf/io",
117 "Rev": "0ac967c269268f1af7d9bcc7927ccc9a589b2b36"
Godeps/_workspace/src/github.com/StackExchange/wmi/LICENSE new
+20
@@ -0,0 +1,20 @@
1 +The MIT License (MIT)
2 +
3 +Copyright (c) 2013 Stack Exchange
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining a copy of
6 +this software and associated documentation files (the "Software"), to deal in
7 +the Software without restriction, including without limitation the rights to
8 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 +the Software, and to permit persons to whom the Software is furnished to do so,
10 +subject to the following conditions:
11 +
12 +The above copyright notice and this permission notice shall be included in all
13 +copies or substantial portions of the Software.
14 +
15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Godeps/_workspace/src/github.com/StackExchange/wmi/README.md new
+4
@@ -0,0 +1,4 @@
1 +wmi
2 +===
3 +
4 +Package wmi provides a WQL interface for WMI on Windows.
Godeps/_workspace/src/github.com/StackExchange/wmi/wmi.go new
+416
@@ -0,0 +1,416 @@
1 +// +build windows
2 +
3 +/*
4 +Package wmi provides a WQL interface for WMI on Windows.
5 +
6 +Example code to print names of running processes:
7 +
8 + type Win32_Process struct {
9 + Name string
10 + }
11 +
12 + func main() {
13 + var dst []Win32_Process
14 + q := wmi.CreateQuery(&dst, "")
15 + err := wmi.Query(q, &dst)
16 + if err != nil {
17 + log.Fatal(err)
18 + }
19 + for i, v := range dst {
20 + println(i, v.Name)
21 + }
22 + }
23 +
24 +*/
25 +package wmi
26 +
27 +import (
28 + "bytes"
29 + "errors"
30 + "fmt"
31 + "log"
32 + "os"
33 + "reflect"
34 + "runtime"
35 + "strconv"
36 + "strings"
37 + "sync"
38 + "time"
39 +
40 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
41 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
42 +)
43 +
44 +var l = log.New(os.Stdout, "", log.LstdFlags)
45 +
46 +var (
47 + ErrInvalidEntityType = errors.New("wmi: invalid entity type")
48 + lock sync.Mutex
49 +)
50 +
51 +// QueryNamespace invokes Query with the given namespace on the local machine.
52 +func QueryNamespace(query string, dst interface{}, namespace string) error {
53 + return Query(query, dst, nil, namespace)
54 +}
55 +
56 +// Query runs the WQL query and appends the values to dst.
57 +//
58 +// dst must have type *[]S or *[]*S, for some struct type S. Fields selected in
59 +// the query must have the same name in dst. Supported types are all signed and
60 +// unsigned integers, time.Time, string, bool, or a pointer to one of those.
61 +// Array types are not supported.
62 +//
63 +// By default, the local machine and default namespace are used. These can be
64 +// changed using connectServerArgs. See
65 +// http://msdn.microsoft.com/en-us/library/aa393720.aspx for details.
66 +//
67 +// Query is a wrapper around DefaultClient.Query.
68 +func Query(query string, dst interface{}, connectServerArgs ...interface{}) error {
69 + return DefaultClient.Query(query, dst, connectServerArgs...)
70 +}
71 +
72 +// A Client is an WMI query client.
73 +//
74 +// Its zero value (DefaultClient) is a usable client.
75 +type Client struct {
76 + // NonePtrZero specifies if nil values for fields which aren't pointers
77 + // should be returned as the field types zero value.
78 + //
79 + // Setting this to true allows stucts without pointer fields to be used
80 + // without the risk failure should a nil value returned from WMI.
81 + NonePtrZero bool
82 +
83 + // PtrNil specifies if nil values for pointer fields should be returned
84 + // as nil.
85 + //
86 + // Setting this to true will set pointer fields to nil where WMI
87 + // returned nil, otherwise the types zero value will be returned.
88 + PtrNil bool
89 +
90 + // AllowMissingFields specifies that struct fields not present in the
91 + // query result should not result in an error.
92 + //
93 + // Setting this to true allows custom queries to be used with full
94 + // struct definitions instead of having to define multiple structs.
95 + AllowMissingFields bool
96 +}
97 +
98 +// DefaultClient is the default Client and is used by Query, QueryNamespace
99 +var DefaultClient = &Client{}
100 +
101 +// Query runs the WQL query and appends the values to dst.
102 +//
103 +// dst must have type *[]S or *[]*S, for some struct type S. Fields selected in
104 +// the query must have the same name in dst. Supported types are all signed and
105 +// unsigned integers, time.Time, string, bool, or a pointer to one of those.
106 +// Array types are not supported.
107 +//
108 +// By default, the local machine and default namespace are used. These can be
109 +// changed using connectServerArgs. See
110 +// http://msdn.microsoft.com/en-us/library/aa393720.aspx for details.
111 +func (c *Client) Query(query string, dst interface{}, connectServerArgs ...interface{}) error {
112 + dv := reflect.ValueOf(dst)
113 + if dv.Kind() != reflect.Ptr || dv.IsNil() {
114 + return ErrInvalidEntityType
115 + }
116 + dv = dv.Elem()
117 + mat, elemType := checkMultiArg(dv)
118 + if mat == multiArgTypeInvalid {
119 + return ErrInvalidEntityType
120 + }
121 +
122 + lock.Lock()
123 + defer lock.Unlock()
124 + runtime.LockOSThread()
125 + defer runtime.UnlockOSThread()
126 +
127 + err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
128 + if err != nil {
129 + oleerr := err.(*ole.OleError)
130 + // S_FALSE = 0x00000001 // CoInitializeEx was already called on this thread
131 + if oleerr.Code() != ole.S_OK && oleerr.Code() != 0x00000001 {
132 + return err
133 + }
134 + } else {
135 + // Only invoke CoUninitialize if the thread was not initizlied before.
136 + // This will allow other go packages based on go-ole play along
137 + // with this library.
138 + defer ole.CoUninitialize()
139 + }
140 +
141 + unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator")
142 + if err != nil {
143 + return err
144 + }
145 + defer unknown.Release()
146 +
147 + wmi, err := unknown.QueryInterface(ole.IID_IDispatch)
148 + if err != nil {
149 + return err
150 + }
151 + defer wmi.Release()
152 +
153 + // service is a SWbemServices
154 + serviceRaw, err := oleutil.CallMethod(wmi, "ConnectServer", connectServerArgs...)
155 + if err != nil {
156 + return err
157 + }
158 + service := serviceRaw.ToIDispatch()
159 + defer serviceRaw.Clear()
160 +
161 + // result is a SWBemObjectSet
162 + resultRaw, err := oleutil.CallMethod(service, "ExecQuery", query)
163 + if err != nil {
164 + return err
165 + }
166 + result := resultRaw.ToIDispatch()
167 + defer resultRaw.Clear()
168 +
169 + count, err := oleInt64(result, "Count")
170 + if err != nil {
171 + return err
172 + }
173 +
174 + // Initialize a slice with Count capacity
175 + dv.Set(reflect.MakeSlice(dv.Type(), 0, int(count)))
176 +
177 + var errFieldMismatch error
178 + for i := int64(0); i < count; i++ {
179 + err := func() error {
180 + // item is a SWbemObject, but really a Win32_Process
181 + itemRaw, err := oleutil.CallMethod(result, "ItemIndex", i)
182 + if err != nil {
183 + return err
184 + }
185 + item := itemRaw.ToIDispatch()
186 + defer itemRaw.Clear()
187 +
188 + ev := reflect.New(elemType)
189 + if err = c.loadEntity(ev.Interface(), item); err != nil {
190 + if _, ok := err.(*ErrFieldMismatch); ok {
191 + // We continue loading entities even in the face of field mismatch errors.
192 + // If we encounter any other error, that other error is returned. Otherwise,
193 + // an ErrFieldMismatch is returned.
194 + errFieldMismatch = err
195 + } else {
196 + return err
197 + }
198 + }
199 + if mat != multiArgTypeStructPtr {
200 + ev = ev.Elem()
201 + }
202 + dv.Set(reflect.Append(dv, ev))
203 + return nil
204 + }()
205 + if err != nil {
206 + return err
207 + }
208 + }
209 + return errFieldMismatch
210 +}
211 +
212 +// ErrFieldMismatch is returned when a field is to be loaded into a different
213 +// type than the one it was stored from, or when a field is missing or
214 +// unexported in the destination struct.
215 +// StructType is the type of the struct pointed to by the destination argument.
216 +type ErrFieldMismatch struct {
217 + StructType reflect.Type
218 + FieldName string
219 + Reason string
220 +}
221 +
222 +func (e *ErrFieldMismatch) Error() string {
223 + return fmt.Sprintf("wmi: cannot load field %q into a %q: %s",
224 + e.FieldName, e.StructType, e.Reason)
225 +}
226 +
227 +var timeType = reflect.TypeOf(time.Time{})
228 +
229 +// loadEntity loads a SWbemObject into a struct pointer.
230 +func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismatch error) {
231 + v := reflect.ValueOf(dst).Elem()
232 + for i := 0; i < v.NumField(); i++ {
233 + f := v.Field(i)
234 + of := f
235 + isPtr := f.Kind() == reflect.Ptr
236 + if isPtr {
237 + ptr := reflect.New(f.Type().Elem())
238 + f.Set(ptr)
239 + f = f.Elem()
240 + }
241 + n := v.Type().Field(i).Name
242 + if !f.CanSet() {
243 + return &ErrFieldMismatch{
244 + StructType: of.Type(),
245 + FieldName: n,
246 + Reason: "CanSet() is false",
247 + }
248 + }
249 + prop, err := oleutil.GetProperty(src, n)
250 + if err != nil {
251 + if !c.AllowMissingFields {
252 + errFieldMismatch = &ErrFieldMismatch{
253 + StructType: of.Type(),
254 + FieldName: n,
255 + Reason: "no such struct field",
256 + }
257 + }
258 + continue
259 + }
260 + defer prop.Clear()
261 +
262 + switch val := prop.Value().(type) {
263 + case int8, int16, int32, int64, int:
264 + v := reflect.ValueOf(val).Int()
265 + switch f.Kind() {
266 + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
267 + f.SetInt(v)
268 + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
269 + f.SetUint(uint64(v))
270 + default:
271 + return &ErrFieldMismatch{
272 + StructType: of.Type(),
273 + FieldName: n,
274 + Reason: "not an integer class",
275 + }
276 + }
277 + case uint8, uint16, uint32, uint64:
278 + v := reflect.ValueOf(val).Uint()
279 + switch f.Kind() {
280 + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
281 + f.SetInt(int64(v))
282 + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
283 + f.SetUint(v)
284 + default:
285 + return &ErrFieldMismatch{
286 + StructType: of.Type(),
287 + FieldName: n,
288 + Reason: "not an integer class",
289 + }
290 + }
291 + case string:
292 + switch f.Kind() {
293 + case reflect.String:
294 + f.SetString(val)
295 + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
296 + iv, err := strconv.ParseInt(val, 10, 64)
297 + if err != nil {
298 + return err
299 + }
300 + f.SetInt(iv)
301 + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
302 + uv, err := strconv.ParseUint(val, 10, 64)
303 + if err != nil {
304 + return err
305 + }
306 + f.SetUint(uv)
307 + case reflect.Struct:
308 + switch f.Type() {
309 + case timeType:
310 + if len(val) == 25 {
311 + mins, err := strconv.Atoi(val[22:])
312 + if err != nil {
313 + return err
314 + }
315 + val = val[:22] + fmt.Sprintf("%02d%02d", mins/60, mins%60)
316 + }
317 + t, err := time.Parse("20060102150405.000000-0700", val)
318 + if err != nil {
319 + return err
320 + }
321 + f.Set(reflect.ValueOf(t))
322 + }
323 + }
324 + case bool:
325 + switch f.Kind() {
326 + case reflect.Bool:
327 + f.SetBool(val)
328 + default:
329 + return &ErrFieldMismatch{
330 + StructType: of.Type(),
331 + FieldName: n,
332 + Reason: "not a bool",
333 + }
334 + }
335 + default:
336 + typeof := reflect.TypeOf(val)
337 + if typeof == nil && (isPtr || c.NonePtrZero) {
338 + if (isPtr && c.PtrNil) || (!isPtr && c.NonePtrZero) {
339 + of.Set(reflect.Zero(of.Type()))
340 + }
341 + break
342 + }
343 + return &ErrFieldMismatch{
344 + StructType: of.Type(),
345 + FieldName: n,
346 + Reason: fmt.Sprintf("unsupported type (%T)", val),
347 + }
348 + }
349 + }
350 + return errFieldMismatch
351 +}
352 +
353 +type multiArgType int
354 +
355 +const (
356 + multiArgTypeInvalid multiArgType = iota
357 + multiArgTypeStruct
358 + multiArgTypeStructPtr
359 +)
360 +
361 +// checkMultiArg checks that v has type []S, []*S for some struct type S.
362 +//
363 +// It returns what category the slice's elements are, and the reflect.Type
364 +// that represents S.
365 +func checkMultiArg(v reflect.Value) (m multiArgType, elemType reflect.Type) {
366 + if v.Kind() != reflect.Slice {
367 + return multiArgTypeInvalid, nil
368 + }
369 + elemType = v.Type().Elem()
370 + switch elemType.Kind() {
371 + case reflect.Struct:
372 + return multiArgTypeStruct, elemType
373 + case reflect.Ptr:
374 + elemType = elemType.Elem()
375 + if elemType.Kind() == reflect.Struct {
376 + return multiArgTypeStructPtr, elemType
377 + }
378 + }
379 + return multiArgTypeInvalid, nil
380 +}
381 +
382 +func oleInt64(item *ole.IDispatch, prop string) (int64, error) {
383 + v, err := oleutil.GetProperty(item, prop)
384 + if err != nil {
385 + return 0, err
386 + }
387 + defer v.Clear()
388 +
389 + i := int64(v.Val)
390 + return i, nil
391 +}
392 +
393 +// CreateQuery returns a WQL query string that queries all columns of src. where
394 +// is an optional string that is appended to the query, to be used with WHERE
395 +// clauses. In such a case, the "WHERE" string should appear at the beginning.
396 +func CreateQuery(src interface{}, where string) string {
397 + var b bytes.Buffer
398 + b.WriteString("SELECT ")
399 + s := reflect.Indirect(reflect.ValueOf(src))
400 + t := s.Type()
401 + if s.Kind() == reflect.Slice {
402 + t = t.Elem()
403 + }
404 + if t.Kind() != reflect.Struct {
405 + return ""
406 + }
407 + var fields []string
408 + for i := 0; i < t.NumField(); i++ {
409 + fields = append(fields, t.Field(i).Name)
410 + }
411 + b.WriteString(strings.Join(fields, ", "))
412 + b.WriteString(" FROM ")
413 + b.WriteString(t.Name())
414 + b.WriteString(" " + where)
415 + return b.String()
416 +}
Godeps/_workspace/src/github.com/StackExchange/wmi/wmi_test.go new
+316
@@ -0,0 +1,316 @@
1 +// +build windows
2 +
3 +package wmi
4 +
5 +import (
6 + "encoding/json"
7 + "fmt"
8 + "reflect"
9 + "runtime"
10 + "runtime/debug"
11 + "sync"
12 + "testing"
13 + "time"
14 +)
15 +
16 +func TestQuery(t *testing.T) {
17 + var dst []Win32_Process
18 + q := CreateQuery(&dst, "")
19 + err := Query(q, &dst)
20 + if err != nil {
21 + t.Fatal(err)
22 + }
23 +}
24 +
25 +func TestFieldMismatch(t *testing.T) {
26 + type s struct {
27 + Name string
28 + HandleCount uint32
29 + Blah uint32
30 + }
31 + var dst []s
32 + err := Query("SELECT Name, HandleCount FROM Win32_Process", &dst)
33 + if err == nil || err.Error() != `wmi: cannot load field "Blah" into a "uint32": no such struct field` {
34 + t.Error("Expected err field mismatch")
35 + }
36 +}
37 +
38 +func TestStrings(t *testing.T) {
39 + printed := false
40 + f := func() {
41 + var dst []Win32_Process
42 + zeros := 0
43 + q := CreateQuery(&dst, "")
44 + for i := 0; i < 5; i++ {
45 + err := Query(q, &dst)
46 + if err != nil {
47 + t.Fatal(err, q)
48 + }
49 + for _, d := range dst {
50 + v := reflect.ValueOf(d)
51 + for j := 0; j < v.NumField(); j++ {
52 + f := v.Field(j)
53 + if f.Kind() != reflect.String {
54 + continue
55 + }
56 + s := f.Interface().(string)
57 + if len(s) > 0 && s[0] == '\u0000' {
58 + zeros++
59 + if !printed {
60 + printed = true
61 + j, _ := json.MarshalIndent(&d, "", " ")
62 + t.Log("Example with \\u0000:\n", string(j))
63 + }
64 + }
65 + }
66 + }
67 + fmt.Println("iter", i, "zeros:", zeros)
68 + }
69 + if zeros > 0 {
70 + t.Error("> 0 zeros")
71 + }
72 + }
73 +
74 + fmt.Println("Disabling GC")
75 + debug.SetGCPercent(-1)
76 + f()
77 + fmt.Println("Enabling GC")
78 + debug.SetGCPercent(100)
79 + f()
80 +}
81 +
82 +func TestNamespace(t *testing.T) {
83 + var dst []Win32_Process
84 + q := CreateQuery(&dst, "")
85 + err := QueryNamespace(q, &dst, `root\CIMV2`)
86 + if err != nil {
87 + t.Fatal(err)
88 + }
89 + dst = nil
90 + err = QueryNamespace(q, &dst, `broken\nothing`)
91 + if err == nil {
92 + t.Fatal("expected error")
93 + }
94 +}
95 +
96 +func TestCreateQuery(t *testing.T) {
97 + type TestStruct struct {
98 + Name string
99 + Count int
100 + }
101 + var dst []TestStruct
102 + output := "SELECT Name, Count FROM TestStruct WHERE Count > 2"
103 + tests := []interface{}{
104 + &dst,
105 + dst,
106 + TestStruct{},
107 + &TestStruct{},
108 + }
109 + for i, test := range tests {
110 + if o := CreateQuery(test, "WHERE Count > 2"); o != output {
111 + t.Error("bad output on", i, o)
112 + }
113 + }
114 + if CreateQuery(3, "") != "" {
115 + t.Error("expected empty string")
116 + }
117 +}
118 +
119 +func _TestMany(t *testing.T) {
120 + limit := 5000
121 + fmt.Println("running until:", limit)
122 + fmt.Println("No panics mean it succeeded. Other errors are OK.")
123 + runtime.GOMAXPROCS(2)
124 + wg := sync.WaitGroup{}
125 + wg.Add(2)
126 + go func() {
127 + for i := 0; i < limit; i++ {
128 + if i%25 == 0 {
129 + fmt.Println(i)
130 + }
131 + var dst []Win32_PerfRawData_PerfDisk_LogicalDisk
132 + q := CreateQuery(&dst, "")
133 + err := Query(q, &dst)
134 + if err != nil {
135 + fmt.Println("ERROR disk", err)
136 + }
137 + }
138 + wg.Done()
139 + }()
140 + go func() {
141 + for i := 0; i > -limit; i-- {
142 + if i%25 == 0 {
143 + fmt.Println(i)
144 + }
145 + var dst []Win32_OperatingSystem
146 + q := CreateQuery(&dst, "")
147 + err := Query(q, &dst)
148 + if err != nil {
149 + fmt.Println("ERROR OS", err)
150 + }
151 + }
152 + wg.Done()
153 + }()
154 + wg.Wait()
155 +}
156 +
157 +type Win32_Process struct {
158 + CSCreationClassName string
159 + CSName string
160 + Caption *string
161 + CommandLine *string
162 + CreationClassName string
163 + CreationDate *time.Time
164 + Description *string
165 + ExecutablePath *string
166 + ExecutionState *uint16
167 + Handle string
168 + HandleCount uint32
169 + InstallDate *time.Time
170 + KernelModeTime uint64
171 + MaximumWorkingSetSize *uint32
172 + MinimumWorkingSetSize *uint32
173 + Name string
174 + OSCreationClassName string
175 + OSName string
176 + OtherOperationCount uint64
177 + OtherTransferCount uint64
178 + PageFaults uint32
179 + PageFileUsage uint32
180 + ParentProcessId uint32
181 + PeakPageFileUsage uint32
182 + PeakVirtualSize uint64
183 + PeakWorkingSetSize uint32
184 + Priority uint32
185 + PrivatePageCount uint64
186 + ProcessId uint32
187 + QuotaNonPagedPoolUsage uint32
188 + QuotaPagedPoolUsage uint32
189 + QuotaPeakNonPagedPoolUsage uint32
190 + QuotaPeakPagedPoolUsage uint32
191 + ReadOperationCount uint64
192 + ReadTransferCount uint64
193 + SessionId uint32
194 + Status *string
195 + TerminationDate *time.Time
196 + ThreadCount uint32
197 + UserModeTime uint64
198 + VirtualSize uint64
199 + WindowsVersion string
200 + WorkingSetSize uint64
201 + WriteOperationCount uint64
202 + WriteTransferCount uint64
203 +}
204 +
205 +type Win32_PerfRawData_PerfDisk_LogicalDisk struct {
206 + AvgDiskBytesPerRead uint64
207 + AvgDiskBytesPerRead_Base uint32
208 + AvgDiskBytesPerTransfer uint64
209 + AvgDiskBytesPerTransfer_Base uint32
210 + AvgDiskBytesPerWrite uint64
211 + AvgDiskBytesPerWrite_Base uint32
212 + AvgDiskQueueLength uint64
213 + AvgDiskReadQueueLength uint64
214 + AvgDiskSecPerRead uint32
215 + AvgDiskSecPerRead_Base uint32
216 + AvgDiskSecPerTransfer uint32
217 + AvgDiskSecPerTransfer_Base uint32
218 + AvgDiskSecPerWrite uint32
219 + AvgDiskSecPerWrite_Base uint32
220 + AvgDiskWriteQueueLength uint64
221 + Caption *string
222 + CurrentDiskQueueLength uint32
223 + Description *string
224 + DiskBytesPerSec uint64
225 + DiskReadBytesPerSec uint64
226 + DiskReadsPerSec uint32
227 + DiskTransfersPerSec uint32
228 + DiskWriteBytesPerSec uint64
229 + DiskWritesPerSec uint32
230 + FreeMegabytes uint32
231 + Frequency_Object uint64
232 + Frequency_PerfTime uint64
233 + Frequency_Sys100NS uint64
234 + Name string
235 + PercentDiskReadTime uint64
236 + PercentDiskReadTime_Base uint64
237 + PercentDiskTime uint64
238 + PercentDiskTime_Base uint64
239 + PercentDiskWriteTime uint64
240 + PercentDiskWriteTime_Base uint64
241 + PercentFreeSpace uint32
242 + PercentFreeSpace_Base uint32
243 + PercentIdleTime uint64
244 + PercentIdleTime_Base uint64
245 + SplitIOPerSec uint32
246 + Timestamp_Object uint64
247 + Timestamp_PerfTime uint64
248 + Timestamp_Sys100NS uint64
249 +}
250 +
251 +type Win32_OperatingSystem struct {
252 + BootDevice string
253 + BuildNumber string
254 + BuildType string
255 + Caption *string
256 + CodeSet string
257 + CountryCode string
258 + CreationClassName string
259 + CSCreationClassName string
260 + CSDVersion *string
261 + CSName string
262 + CurrentTimeZone int16
263 + DataExecutionPrevention_Available bool
264 + DataExecutionPrevention_32BitApplications bool
265 + DataExecutionPrevention_Drivers bool
266 + DataExecutionPrevention_SupportPolicy *uint8
267 + Debug bool
268 + Description *string
269 + Distributed bool
270 + EncryptionLevel uint32
271 + ForegroundApplicationBoost *uint8
272 + FreePhysicalMemory uint64
273 + FreeSpaceInPagingFiles uint64
274 + FreeVirtualMemory uint64
275 + InstallDate time.Time
276 + LargeSystemCache *uint32
277 + LastBootUpTime time.Time
278 + LocalDateTime time.Time
279 + Locale string
280 + Manufacturer string
281 + MaxNumberOfProcesses uint32
282 + MaxProcessMemorySize uint64
283 + MUILanguages *[]string
284 + Name string
285 + NumberOfLicensedUsers *uint32
286 + NumberOfProcesses uint32
287 + NumberOfUsers uint32
288 + OperatingSystemSKU uint32
289 + Organization string
290 + OSArchitecture string
291 + OSLanguage uint32
292 + OSProductSuite uint32
293 + OSType uint16
294 + OtherTypeDescription *string
295 + PAEEnabled *bool
296 + PlusProductID *string
297 + PlusVersionNumber *string
298 + PortableOperatingSystem bool
299 + Primary bool
300 + ProductType uint32
301 + RegisteredUser string
302 + SerialNumber string
303 + ServicePackMajorVersion uint16
304 + ServicePackMinorVersion uint16
305 + SizeStoredInPagingFiles uint64
306 + Status string
307 + SuiteMask uint32
308 + SystemDevice string
309 + SystemDirectory string
310 + SystemDrive string
311 + TotalSwapSpaceSize *uint64
312 + TotalVirtualMemorySize uint64
313 + TotalVisibleMemorySize uint64
314 + Version string
315 + WindowsDirectory string
316 +}
Godeps/_workspace/src/github.com/StackExchange/wmi/wmi_unix.go new
+1
@@ -0,0 +1 @@
1 +package wmi
Godeps/_workspace/src/github.com/go-ole/go-ole/.travis.yml new
+9
@@ -0,0 +1,9 @@
1 +language: go
2 +sudo: false
3 +
4 +go:
5 + - 1.1
6 + - 1.2
7 + - 1.3
8 + - 1.4
9 + - tip
Godeps/_workspace/src/github.com/go-ole/go-ole/ChangeLog.md new
+48
@@ -0,0 +1,48 @@
1 +# Version 1.x.x
2 +
3 +* **Add more test cases and reference new test COM server project.** (Placeholder for future additions)
4 +
5 +# Version 1.2.0-alphaX
6 +
7 +**Minimum supported version is now Go 1.4. Go 1.1 support is deprecated, but should still build.**
8 +
9 + * Added CI configuration for Travis-CI and AppVeyor.
10 + * Added test InterfaceID and ClassID for the COM Test Server project.
11 + * Added more inline documentation (#83).
12 + * Added IEnumVARIANT implementation (#88).
13 + * Added support for retrieving `time.Time` from VARIANT (#92).
14 + * Added test case for IUnknown (#64).
15 + * Added test case for IDispatch (#64).
16 + * Added test cases for scalar variants (#64, #76).
17 +
18 +# Version 1.1.1
19 +
20 + * Fixes for Linux build.
21 + * Fixes for Windows build.
22 +
23 +# Version 1.1.0
24 +
25 +The change to provide building on all platforms is a new feature. The increase in minor version reflects that and allows those who wish to stay on 1.0.x to continue to do so. Support for 1.0.x will be limited to bug fixes.
26 +
27 + * Move GUID out of variables.go into its own file to make new documentation available.
28 + * Move OleError out of ole.go into its own file to make new documentation available.
29 + * Add documentation to utility functions.
30 + * Add documentation to variant receiver functions.
31 + * Add documentation to ole structures.
32 + * Make variant available to other systems outside of Windows.
33 + * Make OLE structures available to other systems outside of Windows.
34 +
35 +## New Features
36 +
37 + * Library should now be built on all platforms supported by Go. Library will NOOP on any platform that is not Windows.
38 + * More functions are now documented and available on godoc.org.
39 +
40 +# Version 1.0.1
41 +
42 + 1. Fix package references from repository location change.
43 +
44 +# Version 1.0.0
45 +
46 +This version is stable enough for use. The COM API is still incomplete, but provides enough functionality for accessing COM servers using IDispatch interface.
47 +
48 +There is no changelog for this version. Check commits for history.
Godeps/_workspace/src/github.com/go-ole/go-ole/README.md new
+46
@@ -0,0 +1,46 @@
1 +#Go OLE
2 +
3 +[![Build status](https://ci.appveyor.com/api/projects/status/qr0u2sf7q43us9fj?svg=true)](https://ci.appveyor.com/project/jacobsantos/go-ole-jgs28)
4 +[![Build Status](https://travis-ci.org/go-ole/go-ole.svg?branch=master)](https://travis-ci.org/go-ole/go-ole)
5 +[![GoDoc](https://godoc.org/github.com/go-ole/go-ole?status.svg)](https://godoc.org/github.com/go-ole/go-ole)
6 +
7 +Go bindings for Windows COM using shared libraries instead of cgo.
8 +
9 +By Yasuhiro Matsumoto.
10 +
11 +## Install
12 +
13 +To experiment with go-ole, you can just compile and run the example program:
14 +
15 +```
16 +go get github.com/go-ole/go-ole
17 +cd /path/to/go-ole/
18 +go test
19 +
20 +cd /path/to/go-ole/example/excel
21 +go run excel.go
22 +```
23 +
24 +## Continuous Integration
25 +
26 +Continuous integration configuration has been added for both Travis-CI and AppVeyor. You will have to add these to your own account for your fork in order for it to run.
27 +
28 +**Travis-CI**
29 +
30 +Travis-CI was added to check builds on Linux to ensure that `go get` works when cross building. Currently, Travis-CI is not used to test cross-building, but this may be changed in the future. It is also not currently possible to test the library on Linux, since COM API is specific to Windows and it is not currently possible to run a COM server on Linux or even connect to a remote COM server.
31 +
32 +**AppVeyor**
33 +
34 +AppVeyor is used to build on Windows using the (in-development) test COM server. It is currently only used to test the build and ensure that the code works on Windows. It will be used to register a COM server and then run the test cases based on the test COM server.
35 +
36 +The tests currently do run and do pass and this should be maintained with commits.
37 +
38 +##Versioning
39 +
40 +Go OLE uses [semantic versioning](http://semver.org) for version numbers, which is similar to the version contract of the Go language. Which means that the major version will always maintain backwards compatibility with minor versions. Minor versions will only add new additions and changes. Fixes will always be in patch.
41 +
42 +This contract should allow you to upgrade to new minor and patch versions without breakage or modifications to your existing code. Leave a ticket, if there is breakage, so that it could be fixed.
43 +
44 +##LICENSE
45 +
46 +Under the MIT License: http://mattn.mit-license.org/2013
Godeps/_workspace/src/github.com/go-ole/go-ole/appveyor.yml new
+74
@@ -0,0 +1,74 @@
1 +# Notes:
2 +# - Minimal appveyor.yml file is an empty file. All sections are optional.
3 +# - Indent each level of configuration with 2 spaces. Do not use tabs!
4 +# - All section names are case-sensitive.
5 +# - Section names should be unique on each level.
6 +
7 +version: "1.2.0.{build}-alpha-{branch}"
8 +
9 +os: Windows Server 2012 R2
10 +
11 +branches:
12 + only:
13 + - master
14 + - v1.1
15 + - v1.0
16 +
17 +skip_tags: true
18 +
19 +clone_folder: c:\gopath\src\github.com\go-ole\go-ole
20 +
21 +environment:
22 + GOPATH: c:\gopath
23 + matrix:
24 + - GOARCH: amd64
25 + GOVERSION: 1.4
26 + GOROOT: c:\go
27 + DOWNLOADPLATFORM: "x64"
28 + - GOARCH: 386
29 + GOVERSION: 1.4
30 + GOROOT: c:\go
31 + DOWNLOADPLATFORM: "x86"
32 +
33 +matrix:
34 + fast_finish: true
35 + allow_failures:
36 + - GOARCH: 386
37 + GOVERSION: 1.4
38 + GOROOT: c:\go
39 + DOWNLOADPLATFORM: "x86"
40 +
41 +install:
42 + - choco install mingw
43 + - SET PATH=c:\tools\mingw64\bin;%PATH%
44 + # - Download COM Server
45 + - ps: Start-FileDownload "https://github.com/go-ole/test-com-server/releases/download/v1.0.0/test-com-server-${env:DOWNLOADPLATFORM}.zip"
46 + - 7z e test-com-server-%DOWNLOADPLATFORM%.zip -oc:\gopath\src\github.com\go-ole\go-ole > NUL
47 + - c:\gopath\src\github.com\go-ole\go-ole\build\register-assembly.bat
48 + # - set
49 + - go version
50 + - go env
51 + - c:\gopath\src\github.com\go-ole\go-ole\build\compile-go.bat
52 + - go tool dist install -v cmd/8a
53 + - go tool dist install -v cmd/8c
54 + - go tool dist install -v cmd/8g
55 + - go tool dist install -v cmd/8l
56 + - go tool dist install -v cmd/6a
57 + - go tool dist install -v cmd/6c
58 + - go tool dist install -v cmd/6g
59 + - go tool dist install -v cmd/6l
60 + - go get -u golang.org/x/tools/cmd/cover
61 + - go get -u golang.org/x/tools/cmd/godoc
62 + - go get -u golang.org/x/tools/cmd/stringer
63 +
64 +build_script:
65 + - cd c:\gopath\src\github.com\go-ole\go-ole
66 + - go get -v -t ./...
67 + - go build
68 + - go test -v -cover ./...
69 +
70 +# disable automatic tests
71 +test: off
72 +
73 +# disable deployment
74 +deploy: off
Godeps/_workspace/src/github.com/go-ole/go-ole/build/compile-go.bat new
+5
@@ -0,0 +1,5 @@
1 +@echo OFF
2 +
3 +echo "BUILD GOLANG"
4 +cd "%GOROOT%\src"
5 +./make.bat --dist-tool
Godeps/_workspace/src/github.com/go-ole/go-ole/build/register-assembly.bat new
+8
@@ -0,0 +1,8 @@
1 +@ECHO OFF
2 +
3 +IF "x86" == "%DOWNLOADPLATFORM%" (
4 + CALL c:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /codebase /nologo c:\gopath\src\github.com\go-ole\go-ole\TestCOMServer.dll
5 +)
6 +IF "x64" == "%DOWNLOADPLATFORM%" (
7 + CALL c:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe /codebase /nologo c:\gopath\src\github.com\go-ole\go-ole\TestCOMServer.dll
8 +)
Godeps/_workspace/src/github.com/go-ole/go-ole/com.go new
+328
@@ -0,0 +1,328 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "errors"
7 + "syscall"
8 + "time"
9 + "unicode/utf16"
10 + "unsafe"
11 +)
12 +
13 +var (
14 + procCoInitialize, _ = modole32.FindProc("CoInitialize")
15 + procCoInitializeEx, _ = modole32.FindProc("CoInitializeEx")
16 + procCoUninitialize, _ = modole32.FindProc("CoUninitialize")
17 + procCoCreateInstance, _ = modole32.FindProc("CoCreateInstance")
18 + procCoTaskMemFree, _ = modole32.FindProc("CoTaskMemFree")
19 + procCLSIDFromProgID, _ = modole32.FindProc("CLSIDFromProgID")
20 + procCLSIDFromString, _ = modole32.FindProc("CLSIDFromString")
21 + procStringFromCLSID, _ = modole32.FindProc("StringFromCLSID")
22 + procStringFromIID, _ = modole32.FindProc("StringFromIID")
23 + procIIDFromString, _ = modole32.FindProc("IIDFromString")
24 + procGetUserDefaultLCID, _ = modkernel32.FindProc("GetUserDefaultLCID")
25 + procCopyMemory, _ = modkernel32.FindProc("RtlMoveMemory")
26 + procVariantInit, _ = modoleaut32.FindProc("VariantInit")
27 + procVariantClear, _ = modoleaut32.FindProc("VariantClear")
28 + procVariantTimeToSystemTime, _ = modoleaut32.FindProc("VariantTimeToSystemTime")
29 + procSysAllocString, _ = modoleaut32.FindProc("SysAllocString")
30 + procSysAllocStringLen, _ = modoleaut32.FindProc("SysAllocStringLen")
31 + procSysFreeString, _ = modoleaut32.FindProc("SysFreeString")
32 + procSysStringLen, _ = modoleaut32.FindProc("SysStringLen")
33 + procCreateDispTypeInfo, _ = modoleaut32.FindProc("CreateDispTypeInfo")
34 + procCreateStdDispatch, _ = modoleaut32.FindProc("CreateStdDispatch")
35 + procGetActiveObject, _ = modoleaut32.FindProc("GetActiveObject")
36 +
37 + procGetMessageW, _ = moduser32.FindProc("GetMessageW")
38 + procDispatchMessageW, _ = moduser32.FindProc("DispatchMessageW")
39 +)
40 +
41 +// coInitialize initializes COM library on current thread.
42 +//
43 +// MSDN documentation suggests that this function should not be called. Call
44 +// CoInitializeEx() instead. The reason has to do with threading and this
45 +// function is only for single-threaded apartments.
46 +//
47 +// That said, most users of the library have gotten away with just this
48 +// function. If you are experiencing threading issues, then use
49 +// CoInitializeEx().
50 +func coInitialize() (err error) {
51 + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms678543(v=vs.85).aspx
52 + // Suggests that no value should be passed to CoInitialized.
53 + // Could just be Call() since the parameter is optional. <-- Needs testing to be sure.
54 + hr, _, _ := procCoInitialize.Call(uintptr(0))
55 + if hr != 0 {
56 + err = NewError(hr)
57 + }
58 + return
59 +}
60 +
61 +// coInitializeEx initializes COM library with concurrency model.
62 +func coInitializeEx(coinit uint32) (err error) {
63 + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms695279(v=vs.85).aspx
64 + // Suggests that the first parameter is not only optional but should always be NULL.
65 + hr, _, _ := procCoInitializeEx.Call(uintptr(0), uintptr(coinit))
66 + if hr != 0 {
67 + err = NewError(hr)
68 + }
69 + return
70 +}
71 +
72 +// CoInitialize initializes COM library on current thread.
73 +//
74 +// MSDN documentation suggests that this function should not be called. Call
75 +// CoInitializeEx() instead. The reason has to do with threading and this
76 +// function is only for single-threaded apartments.
77 +//
78 +// That said, most users of the library have gotten away with just this
79 +// function. If you are experiencing threading issues, then use
80 +// CoInitializeEx().
81 +func CoInitialize(p uintptr) (err error) {
82 + // p is ignored and won't be used.
83 + // Avoid any variable not used errors.
84 + p = uintptr(0)
85 + return coInitialize()
86 +}
87 +
88 +// CoInitializeEx initializes COM library with concurrency model.
89 +func CoInitializeEx(p uintptr, coinit uint32) (err error) {
90 + // Avoid any variable not used errors.
91 + p = uintptr(0)
92 + return coInitializeEx(coinit)
93 +}
94 +
95 +// CoUninitialize uninitializes COM Library.
96 +func CoUninitialize() {
97 + procCoUninitialize.Call()
98 +}
99 +
100 +// CoTaskMemFree frees memory pointer.
101 +func CoTaskMemFree(memptr uintptr) {
102 + procCoTaskMemFree.Call(memptr)
103 +}
104 +
105 +// CLSIDFromProgID retrieves Class Identifier with the given Program Identifier.
106 +//
107 +// The Programmatic Identifier must be registered, because it will be looked up
108 +// in the Windows Registry. The registry entry has the following keys: CLSID,
109 +// Insertable, Protocol and Shell
110 +// (https://msdn.microsoft.com/en-us/library/dd542719(v=vs.85).aspx).
111 +//
112 +// programID identifies the class id with less precision and is not guaranteed
113 +// to be unique. These are usually found in the registry under
114 +// HKEY_LOCAL_MACHINE\SOFTWARE\Classes, usually with the format of
115 +// "Program.Component.Version" with version being optional.
116 +//
117 +// CLSIDFromProgID in Windows API.
118 +func CLSIDFromProgID(progId string) (clsid *GUID, err error) {
119 + var guid GUID
120 + lpszProgID := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId)))
121 + hr, _, _ := procCLSIDFromProgID.Call(lpszProgID, uintptr(unsafe.Pointer(&guid)))
122 + if hr != 0 {
123 + err = NewError(hr)
124 + }
125 + clsid = &guid
126 + return
127 +}
128 +
129 +// CLSIDFromString retrieves Class ID from string representation.
130 +//
131 +// This is technically the string version of the GUID and will convert the
132 +// string to object.
133 +//
134 +// CLSIDFromString in Windows API.
135 +func CLSIDFromString(str string) (clsid *GUID, err error) {
136 + var guid GUID
137 + lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(str)))
138 + hr, _, _ := procCLSIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
139 + if hr != 0 {
140 + err = NewError(hr)
141 + }
142 + clsid = &guid
143 + return
144 +}
145 +
146 +// StringFromCLSID returns GUID formated string from GUID object.
147 +func StringFromCLSID(clsid *GUID) (str string, err error) {
148 + var p *uint16
149 + hr, _, _ := procStringFromCLSID.Call(uintptr(unsafe.Pointer(clsid)), uintptr(unsafe.Pointer(&p)))
150 + if hr != 0 {
151 + err = NewError(hr)
152 + }
153 + str = LpOleStrToString(p)
154 + return
155 +}
156 +
157 +// IIDFromString returns GUID from program ID.
158 +func IIDFromString(progId string) (clsid *GUID, err error) {
159 + var guid GUID
160 + lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId)))
161 + hr, _, _ := procIIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
162 + if hr != 0 {
163 + err = NewError(hr)
164 + }
165 + clsid = &guid
166 + return
167 +}
168 +
169 +// StringFromIID returns GUID formatted string from GUID object.
170 +func StringFromIID(iid *GUID) (str string, err error) {
171 + var p *uint16
172 + hr, _, _ := procStringFromIID.Call(uintptr(unsafe.Pointer(iid)), uintptr(unsafe.Pointer(&p)))
173 + if hr != 0 {
174 + err = NewError(hr)
175 + }
176 + str = LpOleStrToString(p)
177 + return
178 +}
179 +
180 +// CreateInstance of single uninitialized object with GUID.
181 +func CreateInstance(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
182 + if iid == nil {
183 + iid = IID_IUnknown
184 + }
185 + hr, _, _ := procCoCreateInstance.Call(
186 + uintptr(unsafe.Pointer(clsid)),
187 + 0,
188 + CLSCTX_SERVER,
189 + uintptr(unsafe.Pointer(iid)),
190 + uintptr(unsafe.Pointer(&unk)))
191 + if hr != 0 {
192 + err = NewError(hr)
193 + }
194 + return
195 +}
196 +
197 +// GetActiveObject retrieves pointer to active object.
198 +func GetActiveObject(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
199 + if iid == nil {
200 + iid = IID_IUnknown
201 + }
202 + hr, _, _ := procGetActiveObject.Call(
203 + uintptr(unsafe.Pointer(clsid)),
204 + uintptr(unsafe.Pointer(iid)),
205 + uintptr(unsafe.Pointer(&unk)))
206 + if hr != 0 {
207 + err = NewError(hr)
208 + }
209 + return
210 +}
211 +
212 +// VariantInit initializes variant.
213 +func VariantInit(v *VARIANT) (err error) {
214 + hr, _, _ := procVariantInit.Call(uintptr(unsafe.Pointer(v)))
215 + if hr != 0 {
216 + err = NewError(hr)
217 + }
218 + return
219 +}
220 +
221 +// VariantClear clears value in Variant settings to VT_EMPTY.
222 +func VariantClear(v *VARIANT) (err error) {
223 + hr, _, _ := procVariantClear.Call(uintptr(unsafe.Pointer(v)))
224 + if hr != 0 {
225 + err = NewError(hr)
226 + }
227 + return
228 +}
229 +
230 +// SysAllocString allocates memory for string and copies string into memory.
231 +func SysAllocString(v string) (ss *int16) {
232 + pss, _, _ := procSysAllocString.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(v))))
233 + ss = (*int16)(unsafe.Pointer(pss))
234 + return
235 +}
236 +
237 +// SysAllocStringLen copies up to length of given string returning pointer.
238 +func SysAllocStringLen(v string) (ss *int16) {
239 + utf16 := utf16.Encode([]rune(v + "\x00"))
240 + ptr := &utf16[0]
241 +
242 + pss, _, _ := procSysAllocStringLen.Call(uintptr(unsafe.Pointer(ptr)), uintptr(len(utf16)-1))
243 + ss = (*int16)(unsafe.Pointer(pss))
244 + return
245 +}
246 +
247 +// SysFreeString frees string system memory. This must be called with SysAllocString.
248 +func SysFreeString(v *int16) (err error) {
249 + hr, _, _ := procSysFreeString.Call(uintptr(unsafe.Pointer(v)))
250 + if hr != 0 {
251 + err = NewError(hr)
252 + }
253 + return
254 +}
255 +
256 +// SysStringLen is the length of the system allocated string.
257 +func SysStringLen(v *int16) uint32 {
258 + l, _, _ := procSysStringLen.Call(uintptr(unsafe.Pointer(v)))
259 + return uint32(l)
260 +}
261 +
262 +// CreateStdDispatch provides default IDispatch implementation for IUnknown.
263 +//
264 +// This handles default IDispatch implementation for objects. It haves a few
265 +// limitations with only supporting one language. It will also only return
266 +// default exception codes.
267 +func CreateStdDispatch(unk *IUnknown, v uintptr, ptinfo *IUnknown) (disp *IDispatch, err error) {
268 + hr, _, _ := procCreateStdDispatch.Call(
269 + uintptr(unsafe.Pointer(unk)),
270 + v,
271 + uintptr(unsafe.Pointer(ptinfo)),
272 + uintptr(unsafe.Pointer(&disp)))
273 + if hr != 0 {
274 + err = NewError(hr)
275 + }
276 + return
277 +}
278 +
279 +// CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch.
280 +//
281 +// This will not handle the full implementation of the interface.
282 +func CreateDispTypeInfo(idata *INTERFACEDATA) (pptinfo *IUnknown, err error) {
283 + hr, _, _ := procCreateDispTypeInfo.Call(
284 + uintptr(unsafe.Pointer(idata)),
285 + uintptr(GetUserDefaultLCID()),
286 + uintptr(unsafe.Pointer(&pptinfo)))
287 + if hr != 0 {
288 + err = NewError(hr)
289 + }
290 + return
291 +}
292 +
293 +// copyMemory moves location of a block of memory.
294 +func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {
295 + procCopyMemory.Call(uintptr(dest), uintptr(src), uintptr(length))
296 +}
297 +
298 +// GetUserDefaultLCID retrieves current user default locale.
299 +func GetUserDefaultLCID() (lcid uint32) {
300 + ret, _, _ := procGetUserDefaultLCID.Call()
301 + lcid = uint32(ret)
302 + return
303 +}
304 +
305 +// GetMessage in message queue from runtime.
306 +//
307 +// This function appears to block. PeekMessage does not block.
308 +func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) {
309 + r0, _, err := procGetMessageW.Call(uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax))
310 + ret = int32(r0)
311 + return
312 +}
313 +
314 +// DispatchMessage to window procedure.
315 +func DispatchMessage(msg *Msg) (ret int32) {
316 + r0, _, _ := procDispatchMessageW.Call(uintptr(unsafe.Pointer(msg)))
317 + ret = int32(r0)
318 + return
319 +}
320 +
321 +func GetVariantDate(value float64) (time.Time, error) {
322 + var st syscall.Systemtime
323 + r, _, _ := procVariantTimeToSystemTime.Call(uintptr(unsafe.Pointer(&value)), uintptr(unsafe.Pointer(&st)))
324 + if r != 0 {
325 + return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), nil), nil
326 + }
327 + return time.Now(), errors.New("Could not convert to time, passing current time.")
328 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/com_func.go new
+174
@@ -0,0 +1,174 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +import (
6 + "time"
7 + "unsafe"
8 +)
9 +
10 +// coInitialize initializes COM library on current thread.
11 +//
12 +// MSDN documentation suggests that this function should not be called. Call
13 +// CoInitializeEx() instead. The reason has to do with threading and this
14 +// function is only for single-threaded apartments.
15 +//
16 +// That said, most users of the library have gotten away with just this
17 +// function. If you are experiencing threading issues, then use
18 +// CoInitializeEx().
19 +func coInitialize() error {
20 + return NewError(E_NOTIMPL)
21 +}
22 +
23 +// coInitializeEx initializes COM library with concurrency model.
24 +func coInitializeEx(coinit uint32) error {
25 + return NewError(E_NOTIMPL)
26 +}
27 +
28 +// CoInitialize initializes COM library on current thread.
29 +//
30 +// MSDN documentation suggests that this function should not be called. Call
31 +// CoInitializeEx() instead. The reason has to do with threading and this
32 +// function is only for single-threaded apartments.
33 +//
34 +// That said, most users of the library have gotten away with just this
35 +// function. If you are experiencing threading issues, then use
36 +// CoInitializeEx().
37 +func CoInitialize(p uintptr) error {
38 + return NewError(E_NOTIMPL)
39 +}
40 +
41 +// CoInitializeEx initializes COM library with concurrency model.
42 +func CoInitializeEx(p uintptr, coinit uint32) error {
43 + return NewError(E_NOTIMPL)
44 +}
45 +
46 +// CoUninitialize uninitializes COM Library.
47 +func CoUninitialize() {}
48 +
49 +// CoTaskMemFree frees memory pointer.
50 +func CoTaskMemFree(memptr uintptr) {}
51 +
52 +// CLSIDFromProgID retrieves Class Identifier with the given Program Identifier.
53 +//
54 +// The Programmatic Identifier must be registered, because it will be looked up
55 +// in the Windows Registry. The registry entry has the following keys: CLSID,
56 +// Insertable, Protocol and Shell
57 +// (https://msdn.microsoft.com/en-us/library/dd542719(v=vs.85).aspx).
58 +//
59 +// programID identifies the class id with less precision and is not guaranteed
60 +// to be unique. These are usually found in the registry under
61 +// HKEY_LOCAL_MACHINE\SOFTWARE\Classes, usually with the format of
62 +// "Program.Component.Version" with version being optional.
63 +//
64 +// CLSIDFromProgID in Windows API.
65 +func CLSIDFromProgID(progId string) (*GUID, error) {
66 + return nil, NewError(E_NOTIMPL)
67 +}
68 +
69 +// CLSIDFromString retrieves Class ID from string representation.
70 +//
71 +// This is technically the string version of the GUID and will convert the
72 +// string to object.
73 +//
74 +// CLSIDFromString in Windows API.
75 +func CLSIDFromString(str string) (*GUID, error) {
76 + return nil, NewError(E_NOTIMPL)
77 +}
78 +
79 +// StringFromCLSID returns GUID formated string from GUID object.
80 +func StringFromCLSID(clsid *GUID) (string, error) {
81 + return "", NewError(E_NOTIMPL)
82 +}
83 +
84 +// IIDFromString returns GUID from program ID.
85 +func IIDFromString(progId string) (*GUID, error) {
86 + return nil, NewError(E_NOTIMPL)
87 +}
88 +
89 +// StringFromIID returns GUID formatted string from GUID object.
90 +func StringFromIID(iid *GUID) (string, error) {
91 + return "", NewError(E_NOTIMPL)
92 +}
93 +
94 +// CreateInstance of single uninitialized object with GUID.
95 +func CreateInstance(clsid *GUID, iid *GUID) (*IUnknown, error) {
96 + return nil, NewError(E_NOTIMPL)
97 +}
98 +
99 +// GetActiveObject retrieves pointer to active object.
100 +func GetActiveObject(clsid *GUID, iid *GUID) (*IUnknown, error) {
101 + return nil, NewError(E_NOTIMPL)
102 +}
103 +
104 +// VariantInit initializes variant.
105 +func VariantInit(v *VARIANT) error {
106 + return NewError(E_NOTIMPL)
107 +}
108 +
109 +// VariantClear clears value in Variant settings to VT_EMPTY.
110 +func VariantClear(v *VARIANT) error {
111 + return NewError(E_NOTIMPL)
112 +}
113 +
114 +// SysAllocString allocates memory for string and copies string into memory.
115 +func SysAllocString(v string) *int16 {
116 + u := int16(0)
117 + return &u
118 +}
119 +
120 +// SysAllocStringLen copies up to length of given string returning pointer.
121 +func SysAllocStringLen(v string) *int16 {
122 + u := int16(0)
123 + return &u
124 +}
125 +
126 +// SysFreeString frees string system memory. This must be called with SysAllocString.
127 +func SysFreeString(v *int16) error {
128 + return NewError(E_NOTIMPL)
129 +}
130 +
131 +// SysStringLen is the length of the system allocated string.
132 +func SysStringLen(v *int16) uint32 {
133 + return uint32(0)
134 +}
135 +
136 +// CreateStdDispatch provides default IDispatch implementation for IUnknown.
137 +//
138 +// This handles default IDispatch implementation for objects. It haves a few
139 +// limitations with only supporting one language. It will also only return
140 +// default exception codes.
141 +func CreateStdDispatch(unk *IUnknown, v uintptr, ptinfo *IUnknown) (*IDispatch, error) {
142 + return nil, NewError(E_NOTIMPL)
143 +}
144 +
145 +// CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch.
146 +//
147 +// This will not handle the full implementation of the interface.
148 +func CreateDispTypeInfo(idata *INTERFACEDATA) (*IUnknown, error) {
149 + return nil, NewError(E_NOTIMPL)
150 +}
151 +
152 +// copyMemory moves location of a block of memory.
153 +func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {}
154 +
155 +// GetUserDefaultLCID retrieves current user default locale.
156 +func GetUserDefaultLCID() uint32 {
157 + return uint32(0)
158 +}
159 +
160 +// GetMessage in message queue from runtime.
161 +//
162 +// This function appears to block. PeekMessage does not block.
163 +func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (int32, error) {
164 + return int32(0), NewError(E_NOTIMPL)
165 +}
166 +
167 +// DispatchMessage to window procedure.
168 +func DispatchMessage(msg *Msg) int32 {
169 + return int32(0)
170 +}
171 +
172 +func GetVariantDate(value float64) (time.Time, error) {
173 + return time.Now(), NewError(E_NOTIMPL)
174 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/com_func_test.go new
+193
@@ -0,0 +1,193 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +import "testing"
6 +
7 +// TestComSetupAndShutDown tests that API fails on Linux.
8 +func TestComSetupAndShutDown(t *testing.T) {
9 + defer func() {
10 + if r := recover(); r != nil {
11 + t.Log(r)
12 + t.Fail()
13 + }
14 + }()
15 +
16 + err := coInitialize()
17 + if err == nil {
18 + t.Error("should be error, because only Windows is supported.")
19 + t.FailNow()
20 + }
21 +
22 + CoUninitialize()
23 +}
24 +
25 +// TestComPublicSetupAndShutDown tests that API fails on Linux.
26 +func TestComPublicSetupAndShutDown(t *testing.T) {
27 + defer func() {
28 + if r := recover(); r != nil {
29 + t.Log(r)
30 + t.Fail()
31 + }
32 + }()
33 +
34 + err := CoInitialize(0)
35 + if err == nil {
36 + t.Error("should be error, because only Windows is supported.")
37 + t.FailNow()
38 + }
39 +
40 + CoUninitialize()
41 +}
42 +
43 +// TestComPublicSetupAndShutDown_WithValue tests that API fails on Linux.
44 +func TestComPublicSetupAndShutDown_WithValue(t *testing.T) {
45 + defer func() {
46 + if r := recover(); r != nil {
47 + t.Log(r)
48 + t.Fail()
49 + }
50 + }()
51 +
52 + err := CoInitialize(5)
53 + if err == nil {
54 + t.Error("should be error, because only Windows is supported.")
55 + t.FailNow()
56 + }
57 +
58 + CoUninitialize()
59 +}
60 +
61 +// TestComExSetupAndShutDown tests that API fails on Linux.
62 +func TestComExSetupAndShutDown(t *testing.T) {
63 + defer func() {
64 + if r := recover(); r != nil {
65 + t.Log(r)
66 + t.Fail()
67 + }
68 + }()
69 +
70 + err := coInitializeEx(COINIT_MULTITHREADED)
71 + if err == nil {
72 + t.Error("should be error, because only Windows is supported.")
73 + t.FailNow()
74 + }
75 +
76 + CoUninitialize()
77 +}
78 +
79 +// TestComPublicExSetupAndShutDown tests that API fails on Linux.
80 +func TestComPublicExSetupAndShutDown(t *testing.T) {
81 + defer func() {
82 + if r := recover(); r != nil {
83 + t.Log(r)
84 + t.Fail()
85 + }
86 + }()
87 +
88 + err := CoInitializeEx(0, COINIT_MULTITHREADED)
89 + if err == nil {
90 + t.Error("should be error, because only Windows is supported.")
91 + t.FailNow()
92 + }
93 +
94 + CoUninitialize()
95 +}
96 +
97 +// TestComPublicExSetupAndShutDown_WithValue tests that API fails on Linux.
98 +func TestComPublicExSetupAndShutDown_WithValue(t *testing.T) {
99 + defer func() {
100 + if r := recover(); r != nil {
101 + t.Log(r)
102 + t.Fail()
103 + }
104 + }()
105 +
106 + err := CoInitializeEx(5, COINIT_MULTITHREADED)
107 + if err == nil {
108 + t.Error("should be error, because only Windows is supported.")
109 + t.FailNow()
110 + }
111 +
112 + CoUninitialize()
113 +}
114 +
115 +// TestClsidFromProgID_WindowsMediaNSSManager tests that API fails on Linux.
116 +func TestClsidFromProgID_WindowsMediaNSSManager(t *testing.T) {
117 + defer func() {
118 + if r := recover(); r != nil {
119 + t.Log(r)
120 + t.Fail()
121 + }
122 + }()
123 +
124 + coInitialize()
125 + defer CoUninitialize()
126 + _, err := CLSIDFromProgID("WMPNSSCI.NSSManager")
127 + if err == nil {
128 + t.Error("should be error, because only Windows is supported.")
129 + t.FailNow()
130 + }
131 +}
132 +
133 +// TestClsidFromString_WindowsMediaNSSManager tests that API fails on Linux.
134 +func TestClsidFromString_WindowsMediaNSSManager(t *testing.T) {
135 + defer func() {
136 + if r := recover(); r != nil {
137 + t.Log(r)
138 + t.Fail()
139 + }
140 + }()
141 +
142 + coInitialize()
143 + defer CoUninitialize()
144 + _, err := CLSIDFromString("{92498132-4D1A-4297-9B78-9E2E4BA99C07}")
145 +
146 + if err == nil {
147 + t.Error("should be error, because only Windows is supported.")
148 + t.FailNow()
149 + }
150 +}
151 +
152 +// TestCreateInstance_WindowsMediaNSSManager tests that API fails on Linux.
153 +func TestCreateInstance_WindowsMediaNSSManager(t *testing.T) {
154 + defer func() {
155 + if r := recover(); r != nil {
156 + t.Log(r)
157 + t.Fail()
158 + }
159 + }()
160 +
161 + coInitialize()
162 + defer CoUninitialize()
163 + _, err := CLSIDFromProgID("WMPNSSCI.NSSManager")
164 +
165 + if err == nil {
166 + t.Error("should be error, because only Windows is supported.")
167 + t.FailNow()
168 + }
169 +}
170 +
171 +// TestError tests that API fails on Linux.
172 +func TestError(t *testing.T) {
173 + defer func() {
174 + if r := recover(); r != nil {
175 + t.Log(r)
176 + t.Fail()
177 + }
178 + }()
179 +
180 + coInitialize()
181 + defer CoUninitialize()
182 + _, err := CLSIDFromProgID("INTERFACE-NOT-FOUND")
183 + if err == nil {
184 + t.Error("should be error, because only Windows is supported.")
185 + t.FailNow()
186 + }
187 +
188 + switch vt := err.(type) {
189 + case *OleError:
190 + default:
191 + t.Fatalf("should be *ole.OleError %t", vt)
192 + }
193 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/com_test.go new
+205
@@ -0,0 +1,205 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "fmt"
7 + "testing"
8 +)
9 +
10 +func TestComSetupAndShutDown(t *testing.T) {
11 + defer func() {
12 + if r := recover(); r != nil {
13 + t.Log(r)
14 + t.Fail()
15 + }
16 + }()
17 +
18 + err := coInitialize()
19 + if err != nil {
20 + t.Error(err)
21 + t.FailNow()
22 + }
23 +
24 + CoUninitialize()
25 +}
26 +
27 +func TestComPublicSetupAndShutDown(t *testing.T) {
28 + defer func() {
29 + if r := recover(); r != nil {
30 + t.Log(r)
31 + t.Fail()
32 + }
33 + }()
34 +
35 + err := CoInitialize(0)
36 + if err != nil {
37 + t.Error(err)
38 + t.FailNow()
39 + }
40 +
41 + CoUninitialize()
42 +}
43 +
44 +func TestComPublicSetupAndShutDown_WithValue(t *testing.T) {
45 + defer func() {
46 + if r := recover(); r != nil {
47 + t.Log(r)
48 + t.Fail()
49 + }
50 + }()
51 +
52 + err := CoInitialize(5)
53 + if err != nil {
54 + t.Error(err)
55 + t.FailNow()
56 + }
57 +
58 + CoUninitialize()
59 +}
60 +
61 +func TestComExSetupAndShutDown(t *testing.T) {
62 + defer func() {
63 + if r := recover(); r != nil {
64 + t.Log(r)
65 + t.Fail()
66 + }
67 + }()
68 +
69 + err := coInitializeEx(COINIT_MULTITHREADED)
70 + if err != nil {
71 + t.Error(err)
72 + t.FailNow()
73 + }
74 +
75 + CoUninitialize()
76 +}
77 +
78 +func TestComPublicExSetupAndShutDown(t *testing.T) {
79 + defer func() {
80 + if r := recover(); r != nil {
81 + t.Log(r)
82 + t.Fail()
83 + }
84 + }()
85 +
86 + err := CoInitializeEx(0, COINIT_MULTITHREADED)
87 + if err != nil {
88 + t.Error(err)
89 + t.FailNow()
90 + }
91 +
92 + CoUninitialize()
93 +}
94 +
95 +func TestComPublicExSetupAndShutDown_WithValue(t *testing.T) {
96 + defer func() {
97 + if r := recover(); r != nil {
98 + t.Log(r)
99 + t.Fail()
100 + }
101 + }()
102 +
103 + err := CoInitializeEx(5, COINIT_MULTITHREADED)
104 + if err != nil {
105 + t.Error(err)
106 + t.FailNow()
107 + }
108 +
109 + CoUninitialize()
110 +}
111 +
112 +func TestClsidFromProgID_WindowsMediaNSSManager(t *testing.T) {
113 + defer func() {
114 + if r := recover(); r != nil {
115 + t.Log(r)
116 + t.Fail()
117 + }
118 + }()
119 +
120 + expected := &GUID{0x92498132, 0x4D1A, 0x4297, [8]byte{0x9B, 0x78, 0x9E, 0x2E, 0x4B, 0xA9, 0x9C, 0x07}}
121 +
122 + coInitialize()
123 + defer CoUninitialize()
124 + actual, err := CLSIDFromProgID("WMPNSSCI.NSSManager")
125 + if err == nil {
126 + if !IsEqualGUID(expected, actual) {
127 + t.Log(err)
128 + t.Log(fmt.Sprintf("Actual GUID: %+v\n", actual))
129 + t.Fail()
130 + }
131 + }
132 +}
133 +
134 +func TestClsidFromString_WindowsMediaNSSManager(t *testing.T) {
135 + defer func() {
136 + if r := recover(); r != nil {
137 + t.Log(r)
138 + t.Fail()
139 + }
140 + }()
141 +
142 + expected := &GUID{0x92498132, 0x4D1A, 0x4297, [8]byte{0x9B, 0x78, 0x9E, 0x2E, 0x4B, 0xA9, 0x9C, 0x07}}
143 +
144 + coInitialize()
145 + defer CoUninitialize()
146 + actual, err := CLSIDFromString("{92498132-4D1A-4297-9B78-9E2E4BA99C07}")
147 +
148 + if !IsEqualGUID(expected, actual) {
149 + t.Log(err)
150 + t.Log(fmt.Sprintf("Actual GUID: %+v\n", actual))
151 + t.Fail()
152 + }
153 +}
154 +
155 +func TestCreateInstance_WindowsMediaNSSManager(t *testing.T) {
156 + defer func() {
157 + if r := recover(); r != nil {
158 + t.Log(r)
159 + t.Fail()
160 + }
161 + }()
162 +
163 + expected := &GUID{0x92498132, 0x4D1A, 0x4297, [8]byte{0x9B, 0x78, 0x9E, 0x2E, 0x4B, 0xA9, 0x9C, 0x07}}
164 +
165 + coInitialize()
166 + defer CoUninitialize()
167 + actual, err := CLSIDFromProgID("WMPNSSCI.NSSManager")
168 +
169 + if err == nil {
170 + if !IsEqualGUID(expected, actual) {
171 + t.Log(err)
172 + t.Log(fmt.Sprintf("Actual GUID: %+v\n", actual))
173 + t.Fail()
174 + }
175 +
176 + unknown, err := CreateInstance(actual, IID_IUnknown)
177 + if err != nil {
178 + t.Log(err)
179 + t.Fail()
180 + }
181 + unknown.Release()
182 + }
183 +}
184 +
185 +func TestError(t *testing.T) {
186 + defer func() {
187 + if r := recover(); r != nil {
188 + t.Log(r)
189 + t.Fail()
190 + }
191 + }()
192 +
193 + coInitialize()
194 + defer CoUninitialize()
195 + _, err := CLSIDFromProgID("INTERFACE-NOT-FOUND")
196 + if err == nil {
197 + t.Fatalf("should be fail", err)
198 + }
199 +
200 + switch vt := err.(type) {
201 + case *OleError:
202 + default:
203 + t.Fatalf("should be *ole.OleError %t", vt)
204 + }
205 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/connect.go new
+192
@@ -0,0 +1,192 @@
1 +package ole
2 +
3 +// Connection contains IUnknown for fluent interface interaction.
4 +//
5 +// Deprecated. Use oleutil package instead.
6 +type Connection struct {
7 + Object *IUnknown // Access COM
8 +}
9 +
10 +// Initialize COM.
11 +func (*Connection) Initialize() (err error) {
12 + return coInitialize()
13 +}
14 +
15 +// Uninitialize COM.
16 +func (*Connection) Uninitialize() {
17 + CoUninitialize()
18 +}
19 +
20 +// Create IUnknown object based first on ProgId and then from String.
21 +func (c *Connection) Create(progId string) (err error) {
22 + var clsid *GUID
23 + clsid, err = CLSIDFromProgID(progId)
24 + if err != nil {
25 + clsid, err = CLSIDFromString(progId)
26 + if err != nil {
27 + return
28 + }
29 + }
30 +
31 + unknown, err := CreateInstance(clsid, IID_IUnknown)
32 + if err != nil {
33 + return
34 + }
35 + c.Object = unknown
36 +
37 + return
38 +}
39 +
40 +// Release IUnknown object.
41 +func (c *Connection) Release() {
42 + c.Object.Release()
43 +}
44 +
45 +// Load COM object from list of programIDs or strings.
46 +func (c *Connection) Load(names ...string) (errors []error) {
47 + var tempErrors []error = make([]error, len(names))
48 + var numErrors int = 0
49 + for _, name := range names {
50 + err := c.Create(name)
51 + if err != nil {
52 + tempErrors = append(tempErrors, err)
53 + numErrors += 1
54 + continue
55 + }
56 + break
57 + }
58 +
59 + copy(errors, tempErrors[0:numErrors])
60 + return
61 +}
62 +
63 +// Dispatch returns Dispatch object.
64 +func (c *Connection) Dispatch() (object *Dispatch, err error) {
65 + dispatch, err := c.Object.QueryInterface(IID_IDispatch)
66 + if err != nil {
67 + return
68 + }
69 + object = &Dispatch{dispatch}
70 + return
71 +}
72 +
73 +// Dispatch stores IDispatch object.
74 +type Dispatch struct {
75 + Object *IDispatch // Dispatch object.
76 +}
77 +
78 +// Call method on IDispatch with parameters.
79 +func (d *Dispatch) Call(method string, params ...interface{}) (result *VARIANT, err error) {
80 + id, err := d.GetId(method)
81 + if err != nil {
82 + return
83 + }
84 +
85 + result, err = d.Invoke(id, DISPATCH_METHOD, params)
86 + return
87 +}
88 +
89 +// MustCall method on IDispatch with parameters.
90 +func (d *Dispatch) MustCall(method string, params ...interface{}) (result *VARIANT) {
91 + id, err := d.GetId(method)
92 + if err != nil {
93 + panic(err)
94 + }
95 +
96 + result, err = d.Invoke(id, DISPATCH_METHOD, params)
97 + if err != nil {
98 + panic(err)
99 + }
100 +
101 + return
102 +}
103 +
104 +// Get property on IDispatch with parameters.
105 +func (d *Dispatch) Get(name string, params ...interface{}) (result *VARIANT, err error) {
106 + id, err := d.GetId(name)
107 + if err != nil {
108 + return
109 + }
110 + result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
111 + return
112 +}
113 +
114 +// MustGet property on IDispatch with parameters.
115 +func (d *Dispatch) MustGet(name string, params ...interface{}) (result *VARIANT) {
116 + id, err := d.GetId(name)
117 + if err != nil {
118 + panic(err)
119 + }
120 +
121 + result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
122 + if err != nil {
123 + panic(err)
124 + }
125 + return
126 +}
127 +
128 +// Set property on IDispatch with parameters.
129 +func (d *Dispatch) Set(name string, params ...interface{}) (result *VARIANT, err error) {
130 + id, err := d.GetId(name)
131 + if err != nil {
132 + return
133 + }
134 + result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
135 + return
136 +}
137 +
138 +// MustSet property on IDispatch with parameters.
139 +func (d *Dispatch) MustSet(name string, params ...interface{}) (result *VARIANT) {
140 + id, err := d.GetId(name)
141 + if err != nil {
142 + panic(err)
143 + }
144 +
145 + result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
146 + if err != nil {
147 + panic(err)
148 + }
149 + return
150 +}
151 +
152 +// GetId retrieves ID of name on IDispatch.
153 +func (d *Dispatch) GetId(name string) (id int32, err error) {
154 + var dispid []int32
155 + dispid, err = d.Object.GetIDsOfName([]string{name})
156 + if err != nil {
157 + return
158 + }
159 + id = dispid[0]
160 + return
161 +}
162 +
163 +// GetIds retrieves all IDs of names on IDispatch.
164 +func (d *Dispatch) GetIds(names ...string) (dispid []int32, err error) {
165 + dispid, err = d.Object.GetIDsOfName(names)
166 + return
167 +}
168 +
169 +// Invoke IDispatch on DisplayID of dispatch type with parameters.
170 +//
171 +// There have been problems where if send cascading params..., it would error
172 +// out because the parameters would be empty.
173 +func (d *Dispatch) Invoke(id int32, dispatch int16, params []interface{}) (result *VARIANT, err error) {
174 + if len(params) < 1 {
175 + result, err = d.Object.Invoke(id, dispatch)
176 + } else {
177 + result, err = d.Object.Invoke(id, dispatch, params...)
178 + }
179 + return
180 +}
181 +
182 +// Release IDispatch object.
183 +func (d *Dispatch) Release() {
184 + d.Object.Release()
185 +}
186 +
187 +// Connect initializes COM and attempts to load IUnknown based on given names.
188 +func Connect(names ...string) (connection *Connection) {
189 + connection.Initialize()
190 + connection.Load(names...)
191 + return
192 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/connect_test.go new
+159
@@ -0,0 +1,159 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +import "strings"
6 +
7 +func Example_quickbooks() {
8 + var err error
9 +
10 + connection := &Connection{nil}
11 +
12 + err = connection.Initialize()
13 + if err != nil {
14 + return
15 + }
16 + defer connection.Uninitialize()
17 +
18 + err = connection.Create("QBXMLRP2.RequestProcessor.1")
19 + if err != nil {
20 + if err.(*OleError).Code() == CO_E_CLASSSTRING {
21 + return
22 + }
23 + }
24 + defer connection.Release()
25 +
26 + dispatch, err := connection.Dispatch()
27 + if err != nil {
28 + return
29 + }
30 + defer dispatch.Release()
31 +}
32 +
33 +func Example_quickbooksConnectHelperCallDispatch() {
34 + var err error
35 +
36 + connection := &Connection{nil}
37 +
38 + err = connection.Initialize()
39 + if err != nil {
40 + return
41 + }
42 + defer connection.Uninitialize()
43 +
44 + err = connection.Create("QBXMLRP2.RequestProcessor.1")
45 + if err != nil {
46 + if err.(*OleError).Code() == CO_E_CLASSSTRING {
47 + return
48 + }
49 + return
50 + }
51 + defer connection.Release()
52 +
53 + dispatch, err := connection.Dispatch()
54 + if err != nil {
55 + return
56 + }
57 + defer dispatch.Release()
58 +
59 + var result *VARIANT
60 +
61 + _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1)
62 + if err != nil {
63 + return
64 + }
65 +
66 + result, err = dispatch.Call("BeginSession", "", 2)
67 + if err != nil {
68 + return
69 + }
70 +
71 + ticket := result.ToString()
72 +
73 + _, err = dispatch.Call("EndSession", ticket)
74 + if err != nil {
75 + return
76 + }
77 +
78 + _, err = dispatch.Call("CloseConnection")
79 + if err != nil {
80 + return
81 + }
82 +}
83 +
84 +func Example_quickbooksConnectHelperDispatchProperty() {
85 + var err error
86 +
87 + connection := &Connection{nil}
88 +
89 + err = connection.Initialize()
90 + if err != nil {
91 + return
92 + }
93 + defer connection.Uninitialize()
94 +
95 + err = connection.Create("QBXMLRP2.RequestProcessor.1")
96 + if err != nil {
97 + if err.(*OleError).Code() == CO_E_CLASSSTRING {
98 + return
99 + }
100 + return
101 + }
102 + defer connection.Release()
103 +
104 + dispatch, err := connection.Dispatch()
105 + if err != nil {
106 + return
107 + }
108 + defer dispatch.Release()
109 +
110 + var result *VARIANT
111 +
112 + _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1)
113 + if err != nil {
114 + return
115 + }
116 +
117 + result, err = dispatch.Call("BeginSession", "", 2)
118 + if err != nil {
119 + return
120 + }
121 +
122 + ticket := result.ToString()
123 +
124 + result, err = dispatch.Get("QBXMLVersionsForSession", ticket)
125 + if err != nil {
126 + return
127 + }
128 +
129 + conversion := result.ToArray()
130 +
131 + totalElements, _ := conversion.TotalElements(0)
132 + if totalElements != 13 {
133 + return
134 + }
135 +
136 + versions := conversion.ToStringArray()
137 + expectedVersionString := "1.0, 1.1, 2.0, 2.1, 3.0, 4.0, 4.1, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0"
138 + versionString := strings.Join(versions, ", ")
139 +
140 + if len(versions) != 13 {
141 + return
142 + }
143 +
144 + if expectedVersionString != versionString {
145 + return
146 + }
147 +
148 + conversion.Release()
149 +
150 + _, err = dispatch.Call("EndSession", ticket)
151 + if err != nil {
152 + return
153 + }
154 +
155 + _, err = dispatch.Call("CloseConnection")
156 + if err != nil {
157 + return
158 + }
159 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/connect_windows_test.go new
+181
@@ -0,0 +1,181 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "fmt"
7 + "strings"
8 + "testing"
9 +)
10 +
11 +func Example_quickbooks() {
12 + var err error
13 +
14 + connection := &Connection{nil}
15 +
16 + err = connection.Initialize()
17 + if err != nil {
18 + return
19 + }
20 + defer connection.Uninitialize()
21 +
22 + err = connection.Create("QBXMLRP2.RequestProcessor.1")
23 + if err != nil {
24 + if err.(*OleError).Code() == CO_E_CLASSSTRING {
25 + return
26 + }
27 + }
28 + defer connection.Release()
29 +
30 + dispatch, err := connection.Dispatch()
31 + if err != nil {
32 + return
33 + }
34 + defer dispatch.Release()
35 +}
36 +
37 +func TestConnectHelperCallDispatch_QuickBooks(t *testing.T) {
38 + var err error
39 +
40 + connection := &Connection{nil}
41 +
42 + err = connection.Initialize()
43 + if err != nil {
44 + t.Log(err)
45 + t.FailNow()
46 + }
47 + defer connection.Uninitialize()
48 +
49 + err = connection.Create("QBXMLRP2.RequestProcessor.1")
50 + if err != nil {
51 + if err.(*OleError).Code() == CO_E_CLASSSTRING {
52 + return
53 + }
54 + t.Log(err)
55 + t.FailNow()
56 + }
57 + defer connection.Release()
58 +
59 + dispatch, err := connection.Dispatch()
60 + if err != nil {
61 + t.Log(err)
62 + t.FailNow()
63 + }
64 + defer dispatch.Release()
65 +
66 + var result *VARIANT
67 +
68 + _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1)
69 + if err != nil {
70 + t.Log(err)
71 + t.FailNow()
72 + }
73 +
74 + result, err = dispatch.Call("BeginSession", "", 2)
75 + if err != nil {
76 + t.Log(err)
77 + t.FailNow()
78 + }
79 +
80 + ticket := result.ToString()
81 +
82 + _, err = dispatch.Call("EndSession", ticket)
83 + if err != nil {
84 + t.Log(err)
85 + t.Fail()
86 + }
87 +
88 + _, err = dispatch.Call("CloseConnection")
89 + if err != nil {
90 + t.Log(err)
91 + t.Fail()
92 + }
93 +}
94 +
95 +func TestConnectHelperDispatchProperty_QuickBooks(t *testing.T) {
96 + var err error
97 +
98 + connection := &Connection{nil}
99 +
100 + err = connection.Initialize()
101 + if err != nil {
102 + t.Log(err)
103 + t.FailNow()
104 + }
105 + defer connection.Uninitialize()
106 +
107 + err = connection.Create("QBXMLRP2.RequestProcessor.1")
108 + if err != nil {
109 + if err.(*OleError).Code() == CO_E_CLASSSTRING {
110 + return
111 + }
112 + t.Log(err)
113 + t.FailNow()
114 + }
115 + defer connection.Release()
116 +
117 + dispatch, err := connection.Dispatch()
118 + if err != nil {
119 + t.Log(err)
120 + t.FailNow()
121 + }
122 + defer dispatch.Release()
123 +
124 + var result *VARIANT
125 +
126 + _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1)
127 + if err != nil {
128 + t.Log(err)
129 + t.FailNow()
130 + }
131 +
132 + result, err = dispatch.Call("BeginSession", "", 2)
133 + if err != nil {
134 + t.Log(err)
135 + t.FailNow()
136 + }
137 +
138 + ticket := result.ToString()
139 +
140 + result, err = dispatch.Get("QBXMLVersionsForSession", ticket)
141 + if err != nil {
142 + t.Log(err)
143 + t.FailNow()
144 + }
145 +
146 + conversion := result.ToArray()
147 +
148 + totalElements, _ := conversion.TotalElements(0)
149 + if totalElements != 13 {
150 + t.Log(fmt.Sprintf("%d total elements does not equal 13\n", totalElements))
151 + t.Fail()
152 + }
153 +
154 + versions := conversion.ToStringArray()
155 + expectedVersionString := "1.0, 1.1, 2.0, 2.1, 3.0, 4.0, 4.1, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0"
156 + versionString := strings.Join(versions, ", ")
157 +
158 + if len(versions) != 13 {
159 + t.Log(fmt.Sprintf("%s\n", versionString))
160 + t.Fail()
161 + }
162 +
163 + if expectedVersionString != versionString {
164 + t.Log(fmt.Sprintf("Expected: %s\nActual: %s", expectedVersionString, versionString))
165 + t.Fail()
166 + }
167 +
168 + conversion.Release()
169 +
170 + _, err = dispatch.Call("EndSession", ticket)
171 + if err != nil {
172 + t.Log(err)
173 + t.Fail()
174 + }
175 +
176 + _, err = dispatch.Call("CloseConnection")
177 + if err != nil {
178 + t.Log(err)
179 + t.Fail()
180 + }
181 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/constants.go new
+153
@@ -0,0 +1,153 @@
1 +package ole
2 +
3 +const (
4 + CLSCTX_INPROC_SERVER = 1
5 + CLSCTX_INPROC_HANDLER = 2
6 + CLSCTX_LOCAL_SERVER = 4
7 + CLSCTX_INPROC_SERVER16 = 8
8 + CLSCTX_REMOTE_SERVER = 16
9 + CLSCTX_ALL = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER
10 + CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER
11 + CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER
12 +)
13 +
14 +const (
15 + COINIT_APARTMENTTHREADED = 0x2
16 + COINIT_MULTITHREADED = 0x0
17 + COINIT_DISABLE_OLE1DDE = 0x4
18 + COINIT_SPEED_OVER_MEMORY = 0x8
19 +)
20 +
21 +const (
22 + DISPATCH_METHOD = 1
23 + DISPATCH_PROPERTYGET = 2
24 + DISPATCH_PROPERTYPUT = 4
25 + DISPATCH_PROPERTYPUTREF = 8
26 +)
27 +
28 +const (
29 + S_OK = 0x00000000
30 + E_UNEXPECTED = 0x8000FFFF
31 + E_NOTIMPL = 0x80004001
32 + E_OUTOFMEMORY = 0x8007000E
33 + E_INVALIDARG = 0x80070057
34 + E_NOINTERFACE = 0x80004002
35 + E_POINTER = 0x80004003
36 + E_HANDLE = 0x80070006
37 + E_ABORT = 0x80004004
38 + E_FAIL = 0x80004005
39 + E_ACCESSDENIED = 0x80070005
40 + E_PENDING = 0x8000000A
41 +
42 + CO_E_CLASSSTRING = 0x800401F3
43 +)
44 +
45 +const (
46 + CC_FASTCALL = iota
47 + CC_CDECL
48 + CC_MSCPASCAL
49 + CC_PASCAL = CC_MSCPASCAL
50 + CC_MACPASCAL
51 + CC_STDCALL
52 + CC_FPFASTCALL
53 + CC_SYSCALL
54 + CC_MPWCDECL
55 + CC_MPWPASCAL
56 + CC_MAX = CC_MPWPASCAL
57 +)
58 +
59 +type VT uint16
60 +
61 +const (
62 + VT_EMPTY VT = 0x0
63 + VT_NULL VT = 0x1
64 + VT_I2 VT = 0x2
65 + VT_I4 VT = 0x3
66 + VT_R4 VT = 0x4
67 + VT_R8 VT = 0x5
68 + VT_CY VT = 0x6
69 + VT_DATE VT = 0x7
70 + VT_BSTR VT = 0x8
71 + VT_DISPATCH VT = 0x9
72 + VT_ERROR VT = 0xa
73 + VT_BOOL VT = 0xb
74 + VT_VARIANT VT = 0xc
75 + VT_UNKNOWN VT = 0xd
76 + VT_DECIMAL VT = 0xe
77 + VT_I1 VT = 0x10
78 + VT_UI1 VT = 0x11
79 + VT_UI2 VT = 0x12
80 + VT_UI4 VT = 0x13
81 + VT_I8 VT = 0x14
82 + VT_UI8 VT = 0x15
83 + VT_INT VT = 0x16
84 + VT_UINT VT = 0x17
85 + VT_VOID VT = 0x18
86 + VT_HRESULT VT = 0x19
87 + VT_PTR VT = 0x1a
88 + VT_SAFEARRAY VT = 0x1b
89 + VT_CARRAY VT = 0x1c
90 + VT_USERDEFINED VT = 0x1d
91 + VT_LPSTR VT = 0x1e
92 + VT_LPWSTR VT = 0x1f
93 + VT_RECORD VT = 0x24
94 + VT_INT_PTR VT = 0x25
95 + VT_UINT_PTR VT = 0x26
96 + VT_FILETIME VT = 0x40
97 + VT_BLOB VT = 0x41
98 + VT_STREAM VT = 0x42
99 + VT_STORAGE VT = 0x43
100 + VT_STREAMED_OBJECT VT = 0x44
101 + VT_STORED_OBJECT VT = 0x45
102 + VT_BLOB_OBJECT VT = 0x46
103 + VT_CF VT = 0x47
104 + VT_CLSID VT = 0x48
105 + VT_BSTR_BLOB VT = 0xfff
106 + VT_VECTOR VT = 0x1000
107 + VT_ARRAY VT = 0x2000
108 + VT_BYREF VT = 0x4000
109 + VT_RESERVED VT = 0x8000
110 + VT_ILLEGAL VT = 0xffff
111 + VT_ILLEGALMASKED VT = 0xfff
112 + VT_TYPEMASK VT = 0xfff
113 +)
114 +
115 +const (
116 + DISPID_UNKNOWN = -1
117 + DISPID_VALUE = 0
118 + DISPID_PROPERTYPUT = -3
119 + DISPID_NEWENUM = -4
120 + DISPID_EVALUATE = -5
121 + DISPID_CONSTRUCTOR = -6
122 + DISPID_DESTRUCTOR = -7
123 + DISPID_COLLECT = -8
124 +)
125 +
126 +const (
127 + TKIND_ENUM = 1
128 + TKIND_RECORD = 2
129 + TKIND_MODULE = 3
130 + TKIND_INTERFACE = 4
131 + TKIND_DISPATCH = 5
132 + TKIND_COCLASS = 6
133 + TKIND_ALIAS = 7
134 + TKIND_UNION = 8
135 + TKIND_MAX = 9
136 +)
137 +
138 +// Safe Array Feature Flags
139 +
140 +const (
141 + FADF_AUTO = 0x0001
142 + FADF_STATIC = 0x0002
143 + FADF_EMBEDDED = 0x0004
144 + FADF_FIXEDSIZE = 0x0010
145 + FADF_RECORD = 0x0020
146 + FADF_HAVEIID = 0x0040
147 + FADF_HAVEVARTYPE = 0x0080
148 + FADF_BSTR = 0x0100
149 + FADF_UNKNOWN = 0x0200
150 + FADF_DISPATCH = 0x0400
151 + FADF_VARIANT = 0x0800
152 + FADF_RESERVED = 0xF008
153 +)
Godeps/_workspace/src/github.com/go-ole/go-ole/data/screenshot.png
Binary files /dev/null and b/Godeps/_workspace/src/github.com/go-ole/go-ole/data/screenshot.png differ
Godeps/_workspace/src/github.com/go-ole/go-ole/error.go new
+51
@@ -0,0 +1,51 @@
1 +package ole
2 +
3 +// OleError stores COM errors.
4 +type OleError struct {
5 + hr uintptr
6 + description string
7 + subError error
8 +}
9 +
10 +// NewError creates new error with HResult.
11 +func NewError(hr uintptr) *OleError {
12 + return &OleError{hr: hr}
13 +}
14 +
15 +// NewErrorWithDescription creates new COM error with HResult and description.
16 +func NewErrorWithDescription(hr uintptr, description string) *OleError {
17 + return &OleError{hr: hr, description: description}
18 +}
19 +
20 +// NewErrorWithSubError creates new COM error with parent error.
21 +func NewErrorWithSubError(hr uintptr, description string, err error) *OleError {
22 + return &OleError{hr: hr, description: description, subError: err}
23 +}
24 +
25 +// Code is the HResult.
26 +func (v *OleError) Code() uintptr {
27 + return uintptr(v.hr)
28 +}
29 +
30 +// String description, either manually set or format message with error code.
31 +func (v *OleError) String() string {
32 + if v.description != "" {
33 + return errstr(int(v.hr)) + " (" + v.description + ")"
34 + }
35 + return errstr(int(v.hr))
36 +}
37 +
38 +// Error implements error interface.
39 +func (v *OleError) Error() string {
40 + return v.String()
41 +}
42 +
43 +// Description retrieves error summary, if there is one.
44 +func (v *OleError) Description() string {
45 + return v.description
46 +}
47 +
48 +// SubError returns parent error, if there is one.
49 +func (v *OleError) SubError() error {
50 + return v.subError
51 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/error_func.go new
+8
@@ -0,0 +1,8 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +// errstr converts error code to string.
6 +func errstr(errno int) string {
7 + return ""
8 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/error_windows.go new
+24
@@ -0,0 +1,24 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "fmt"
7 + "syscall"
8 + "unicode/utf16"
9 +)
10 +
11 +// errstr converts error code to string.
12 +func errstr(errno int) string {
13 + // ask windows for the remaining errors
14 + var flags uint32 = syscall.FORMAT_MESSAGE_FROM_SYSTEM | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
15 + b := make([]uint16, 300)
16 + n, err := syscall.FormatMessage(flags, 0, uint32(errno), 0, b, nil)
17 + if err != nil {
18 + return fmt.Sprintf("error %d (FormatMessage failed with: %v)", errno, err)
19 + }
20 + // trim terminating \r and \n
21 + for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
22 + }
23 + return string(utf16.Decode(b[:n]))
24 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/excel/excel.go new
+31
@@ -0,0 +1,31 @@
1 +// +build windows
2 +
3 +package main
4 +
5 +import (
6 + "time"
7 +
8 + ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
9 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
10 +)
11 +
12 +func main() {
13 + ole.CoInitialize(0)
14 + unknown, _ := oleutil.CreateObject("Excel.Application")
15 + excel, _ := unknown.QueryInterface(ole.IID_IDispatch)
16 + oleutil.PutProperty(excel, "Visible", true)
17 + workbooks := oleutil.MustGetProperty(excel, "Workbooks").ToIDispatch()
18 + workbook := oleutil.MustCallMethod(workbooks, "Add", nil).ToIDispatch()
19 + worksheet := oleutil.MustGetProperty(workbook, "Worksheets", 1).ToIDispatch()
20 + cell := oleutil.MustGetProperty(worksheet, "Cells", 1, 1).ToIDispatch()
21 + oleutil.PutProperty(cell, "Value", 12345)
22 +
23 + time.Sleep(2000000000)
24 +
25 + oleutil.PutProperty(workbook, "Saved", true)
26 + oleutil.CallMethod(workbook, "Close", false)
27 + oleutil.CallMethod(excel, "Quit")
28 + excel.Release()
29 +
30 + ole.CoUninitialize()
31 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/excel2/excel.go new
+96
@@ -0,0 +1,96 @@
1 +// +build windows
2 +
3 +package main
4 +
5 +import (
6 + "fmt"
7 + "log"
8 + "os"
9 +
10 + ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
11 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
12 +)
13 +
14 +func writeExample(excel, workbooks *ole.IDispatch, filepath string) {
15 + // ref: https://msdn.microsoft.com/zh-tw/library/office/ff198017.aspx
16 + // http://stackoverflow.com/questions/12159513/what-is-the-correct-xlfileformat-enumeration-for-excel-97-2003
17 + const xlExcel8 = 56
18 + workbook := oleutil.MustCallMethod(workbooks, "Add", nil).ToIDispatch()
19 + defer workbook.Release()
20 + worksheet := oleutil.MustGetProperty(workbook, "Worksheets", 1).ToIDispatch()
21 + defer worksheet.Release()
22 + cell := oleutil.MustGetProperty(worksheet, "Cells", 1, 1).ToIDispatch()
23 + oleutil.PutProperty(cell, "Value", 12345)
24 + cell.Release()
25 + activeWorkBook := oleutil.MustGetProperty(excel, "ActiveWorkBook").ToIDispatch()
26 + defer activeWorkBook.Release()
27 +
28 + os.Remove(filepath)
29 + // ref: https://msdn.microsoft.com/zh-tw/library/microsoft.office.tools.excel.workbook.saveas.aspx
30 + oleutil.MustCallMethod(activeWorkBook, "SaveAs", filepath, xlExcel8, nil, nil).ToIDispatch()
31 +
32 + //time.Sleep(2 * time.Second)
33 +
34 + // let excel could close without asking
35 + // oleutil.PutProperty(workbook, "Saved", true)
36 + // oleutil.CallMethod(workbook, "Close", false)
37 +}
38 +
39 +func readExample(fileName string, excel, workbooks *ole.IDispatch) {
40 + workbook, err := oleutil.CallMethod(workbooks, "Open", fileName)
41 +
42 + if err != nil {
43 + log.Fatalln(err)
44 + }
45 + defer workbook.ToIDispatch().Release()
46 +
47 + sheets := oleutil.MustGetProperty(excel, "Sheets").ToIDispatch()
48 + sheetCount := (int)(oleutil.MustGetProperty(sheets, "Count").Val)
49 + fmt.Println("sheet count=", sheetCount)
50 + sheets.Release()
51 +
52 + worksheet := oleutil.MustGetProperty(workbook.ToIDispatch(), "Worksheets", 1).ToIDispatch()
53 + defer worksheet.Release()
54 + for row := 1; row <= 2; row++ {
55 + for col := 1; col <= 5; col++ {
56 + cell := oleutil.MustGetProperty(worksheet, "Cells", row, col).ToIDispatch()
57 + val, err := oleutil.GetProperty(cell, "Value")
58 + if err != nil {
59 + break
60 + }
61 + fmt.Printf("(%d,%d)=%+v toString=%s\n", col, row, val.Value(), val.ToString())
62 + cell.Release()
63 + }
64 + }
65 +}
66 +
67 +func showMethodsAndProperties(i *ole.IDispatch) {
68 + n, err := i.GetTypeInfoCount()
69 + if err != nil {
70 + log.Fatalln(err)
71 + }
72 + tinfo, err := i.GetTypeInfo()
73 + if err != nil {
74 + log.Fatalln(err)
75 + }
76 +
77 + fmt.Println("n=", n, "tinfo=", tinfo)
78 +}
79 +
80 +func main() {
81 + log.SetFlags(log.Flags() | log.Lshortfile)
82 + ole.CoInitialize(0)
83 + unknown, _ := oleutil.CreateObject("Excel.Application")
84 + excel, _ := unknown.QueryInterface(ole.IID_IDispatch)
85 + oleutil.PutProperty(excel, "Visible", true)
86 +
87 + workbooks := oleutil.MustGetProperty(excel, "Workbooks").ToIDispatch()
88 + cwd, _ := os.Getwd()
89 + writeExample(excel, workbooks, cwd+"\\write.xls")
90 + readExample(cwd+"\\excel97-2003.xls", excel, workbooks)
91 + showMethodsAndProperties(workbooks)
92 + workbooks.Release()
93 + // oleutil.CallMethod(excel, "Quit")
94 + excel.Release()
95 + ole.CoUninitialize()
96 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/ie/ie.go new
+33
@@ -0,0 +1,33 @@
1 +// +build windows
2 +
3 +package main
4 +
5 +import (
6 + "time"
7 +
8 + ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
9 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
10 +)
11 +
12 +func main() {
13 + ole.CoInitialize(0)
14 + unknown, _ := oleutil.CreateObject("InternetExplorer.Application")
15 + ie, _ := unknown.QueryInterface(ole.IID_IDispatch)
16 + oleutil.CallMethod(ie, "Navigate", "http://www.google.com")
17 + oleutil.PutProperty(ie, "Visible", true)
18 + for {
19 + if oleutil.MustGetProperty(ie, "Busy").Val == 0 {
20 + break
21 + }
22 + }
23 +
24 + time.Sleep(1e9)
25 +
26 + document := oleutil.MustGetProperty(ie, "document").ToIDispatch()
27 + window := oleutil.MustGetProperty(document, "parentWindow").ToIDispatch()
28 + // set 'golang' to text box.
29 + oleutil.MustCallMethod(window, "eval", "document.getElementsByName('q')[0].value = 'golang'")
30 + // click btnG.
31 + btnG := oleutil.MustCallMethod(window, "eval", "document.getElementsByName('btnG')[0]").ToIDispatch()
32 + oleutil.MustCallMethod(btnG, "click")
33 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/itunes/itunes.go new
+47
@@ -0,0 +1,47 @@
1 +// +build windows
2 +
3 +package main
4 +
5 +import (
6 + "log"
7 + "os"
8 + "strings"
9 +
10 + "github.com/gonuts/commander"
11 + ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
12 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
13 +)
14 +
15 +func iTunes() *ole.IDispatch {
16 + ole.CoInitialize(0)
17 + unknown, err := oleutil.CreateObject("iTunes.Application")
18 + if err != nil {
19 + log.Fatal(err)
20 + }
21 + itunes, err := unknown.QueryInterface(ole.IID_IDispatch)
22 + if err != nil {
23 + log.Fatal(err)
24 + }
25 + return itunes
26 +}
27 +
28 +func main() {
29 + command := &commander.Command{
30 + UsageLine: os.Args[0],
31 + Short: "itunes cmd",
32 + }
33 + command.Subcommands = []*commander.Command{}
34 + for _, name := range []string{"Play", "Stop", "Pause", "Quit"} {
35 + command.Subcommands = append(command.Subcommands, &commander.Command{
36 + Run: func(cmd *commander.Command, args []string) error {
37 + _, err := oleutil.CallMethod(iTunes(), name)
38 + return err
39 + },
40 + UsageLine: strings.ToLower(name),
41 + })
42 + }
43 + err := command.Dispatch(os.Args[1:])
44 + if err != nil {
45 + log.Fatal(err)
46 + }
47 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/mediaplayer/mediaplayer.go new
+29
@@ -0,0 +1,29 @@
1 +// +build windows
2 +
3 +package main
4 +
5 +import (
6 + "fmt"
7 + "log"
8 +
9 + ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
10 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
11 +)
12 +
13 +func main() {
14 + ole.CoInitialize(0)
15 + unknown, err := oleutil.CreateObject("WMPlayer.OCX")
16 + if err != nil {
17 + log.Fatal(err)
18 + }
19 + wmp := unknown.MustQueryInterface(ole.IID_IDispatch)
20 + collection := oleutil.MustGetProperty(wmp, "MediaCollection").ToIDispatch()
21 + list := oleutil.MustCallMethod(collection, "getAll").ToIDispatch()
22 + count := int(oleutil.MustGetProperty(list, "count").Val)
23 + for i := 0; i < count; i++ {
24 + item := oleutil.MustGetProperty(list, "item", i).ToIDispatch()
25 + name := oleutil.MustGetProperty(item, "name").ToString()
26 + sourceURL := oleutil.MustGetProperty(item, "sourceURL").ToString()
27 + fmt.Println(name, sourceURL)
28 + }
29 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/msagent/msagent.go new
+24
@@ -0,0 +1,24 @@
1 +// +build windows
2 +
3 +package main
4 +
5 +import (
6 + "time"
7 +
8 + ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
9 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
10 +)
11 +
12 +func main() {
13 + ole.CoInitialize(0)
14 + unknown, _ := oleutil.CreateObject("Agent.Control.1")
15 + agent, _ := unknown.QueryInterface(ole.IID_IDispatch)
16 + oleutil.PutProperty(agent, "Connected", true)
17 + characters := oleutil.MustGetProperty(agent, "Characters").ToIDispatch()
18 + oleutil.CallMethod(characters, "Load", "Merlin", "c:\\windows\\msagent\\chars\\Merlin.acs")
19 + character := oleutil.MustCallMethod(characters, "Character", "Merlin").ToIDispatch()
20 + oleutil.CallMethod(character, "Show")
21 + oleutil.CallMethod(character, "Speak", "こんにちわ世界")
22 +
23 + time.Sleep(4000000000)
24 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/msxml/rssreader.go new
+49
@@ -0,0 +1,49 @@
1 +// +build windows
2 +
3 +package main
4 +
5 +import (
6 + "fmt"
7 + "time"
8 +
9 + ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
10 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
11 +)
12 +
13 +func main() {
14 + ole.CoInitialize(0)
15 + unknown, _ := oleutil.CreateObject("Microsoft.XMLHTTP")
16 + xmlhttp, _ := unknown.QueryInterface(ole.IID_IDispatch)
17 + _, err := oleutil.CallMethod(xmlhttp, "open", "GET", "http://rss.slashdot.org/Slashdot/slashdot", false)
18 + if err != nil {
19 + panic(err.Error())
20 + }
21 + _, err = oleutil.CallMethod(xmlhttp, "send", nil)
22 + if err != nil {
23 + panic(err.Error())
24 + }
25 + state := -1
26 + for state != 4 {
27 + state = int(oleutil.MustGetProperty(xmlhttp, "readyState").Val)
28 + time.Sleep(10000000)
29 + }
30 + responseXml := oleutil.MustGetProperty(xmlhttp, "responseXml").ToIDispatch()
31 + items := oleutil.MustCallMethod(responseXml, "selectNodes", "/rss/channel/item").ToIDispatch()
32 + length := int(oleutil.MustGetProperty(items, "length").Val)
33 +
34 + for n := 0; n < length; n++ {
35 + item := oleutil.MustGetProperty(items, "item", n).ToIDispatch()
36 +
37 + title := oleutil.MustCallMethod(item, "selectSingleNode", "title").ToIDispatch()
38 + fmt.Println(oleutil.MustGetProperty(title, "text").ToString())
39 +
40 + link := oleutil.MustCallMethod(item, "selectSingleNode", "link").ToIDispatch()
41 + fmt.Println(" " + oleutil.MustGetProperty(link, "text").ToString())
42 +
43 + title.Release()
44 + link.Release()
45 + item.Release()
46 + }
47 + items.Release()
48 + xmlhttp.Release()
49 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/outlook/outlook.go new
+29
@@ -0,0 +1,29 @@
1 +// +build windows
2 +
3 +package main
4 +
5 +import (
6 + "fmt"
7 +
8 + ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
9 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
10 +)
11 +
12 +func main() {
13 + ole.CoInitialize(0)
14 + unknown, _ := oleutil.CreateObject("Outlook.Application")
15 + outlook, _ := unknown.QueryInterface(ole.IID_IDispatch)
16 + ns := oleutil.MustCallMethod(outlook, "GetNamespace", "MAPI").ToIDispatch()
17 + folder := oleutil.MustCallMethod(ns, "GetDefaultFolder", 10).ToIDispatch()
18 + contacts := oleutil.MustCallMethod(folder, "Items").ToIDispatch()
19 + count := oleutil.MustGetProperty(contacts, "Count").Value().(int32)
20 + for i := 1; i <= int(count); i++ {
21 + item, err := oleutil.GetProperty(contacts, "Item", i)
22 + if err == nil && item.VT == ole.VT_DISPATCH {
23 + if value, err := oleutil.GetProperty(item.ToIDispatch(), "FullName"); err == nil {
24 + fmt.Println(value.Value())
25 + }
26 + }
27 + }
28 + oleutil.MustCallMethod(outlook, "Quit")
29 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/example/winsock/winsock.go new
+140
@@ -0,0 +1,140 @@
1 +// +build windows
2 +
3 +package main
4 +
5 +import (
6 + "log"
7 + "syscall"
8 + "unsafe"
9 +
10 + ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
11 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
12 +)
13 +
14 +type EventReceiver struct {
15 + lpVtbl *EventReceiverVtbl
16 + ref int32
17 + host *ole.IDispatch
18 +}
19 +
20 +type EventReceiverVtbl struct {
21 + pQueryInterface uintptr
22 + pAddRef uintptr
23 + pRelease uintptr
24 + pGetTypeInfoCount uintptr
25 + pGetTypeInfo uintptr
26 + pGetIDsOfNames uintptr
27 + pInvoke uintptr
28 +}
29 +
30 +func QueryInterface(this *ole.IUnknown, iid *ole.GUID, punk **ole.IUnknown) uint32 {
31 + s, _ := ole.StringFromCLSID(iid)
32 + *punk = nil
33 + if ole.IsEqualGUID(iid, ole.IID_IUnknown) ||
34 + ole.IsEqualGUID(iid, ole.IID_IDispatch) {
35 + AddRef(this)
36 + *punk = this
37 + return ole.S_OK
38 + }
39 + if s == "{248DD893-BB45-11CF-9ABC-0080C7E7B78D}" {
40 + AddRef(this)
41 + *punk = this
42 + return ole.S_OK
43 + }
44 + return ole.E_NOINTERFACE
45 +}
46 +
47 +func AddRef(this *ole.IUnknown) int32 {
48 + pthis := (*EventReceiver)(unsafe.Pointer(this))
49 + pthis.ref++
50 + return pthis.ref
51 +}
52 +
53 +func Release(this *ole.IUnknown) int32 {
54 + pthis := (*EventReceiver)(unsafe.Pointer(this))
55 + pthis.ref--
56 + return pthis.ref
57 +}
58 +
59 +func GetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen int, lcid int, pdisp []int32) uintptr {
60 + for n := 0; n < namelen; n++ {
61 + pdisp[n] = int32(n)
62 + }
63 + return uintptr(ole.S_OK)
64 +}
65 +
66 +func GetTypeInfoCount(pcount *int) uintptr {
67 + if pcount != nil {
68 + *pcount = 0
69 + }
70 + return uintptr(ole.S_OK)
71 +}
72 +
73 +func GetTypeInfo(ptypeif *uintptr) uintptr {
74 + return uintptr(ole.E_NOTIMPL)
75 +}
76 +
77 +func Invoke(this *ole.IDispatch, dispid int, riid *ole.GUID, lcid int, flags int16, dispparams *ole.DISPPARAMS, result *ole.VARIANT, pexcepinfo *ole.EXCEPINFO, nerr *uint) uintptr {
78 + switch dispid {
79 + case 0:
80 + log.Println("DataArrival")
81 + winsock := (*EventReceiver)(unsafe.Pointer(this)).host
82 + var data ole.VARIANT
83 + ole.VariantInit(&data)
84 + oleutil.CallMethod(winsock, "GetData", &data)
85 + s := string(data.ToArray().ToByteArray())
86 + println()
87 + println(s)
88 + println()
89 + case 1:
90 + log.Println("Connected")
91 + winsock := (*EventReceiver)(unsafe.Pointer(this)).host
92 + oleutil.CallMethod(winsock, "SendData", "GET / HTTP/1.0\r\n\r\n")
93 + case 3:
94 + log.Println("SendProgress")
95 + case 4:
96 + log.Println("SendComplete")
97 + case 5:
98 + log.Println("Close")
99 + this.Release()
100 + case 6:
101 + log.Fatal("Error")
102 + default:
103 + log.Println(dispid)
104 + }
105 + return ole.E_NOTIMPL
106 +}
107 +
108 +func main() {
109 + ole.CoInitialize(0)
110 +
111 + unknown, err := oleutil.CreateObject("{248DD896-BB45-11CF-9ABC-0080C7E7B78D}")
112 + if err != nil {
113 + panic(err.Error())
114 + }
115 + winsock, _ := unknown.QueryInterface(ole.IID_IDispatch)
116 + iid, _ := ole.CLSIDFromString("{248DD893-BB45-11CF-9ABC-0080C7E7B78D}")
117 +
118 + dest := &EventReceiver{}
119 + dest.lpVtbl = &EventReceiverVtbl{}
120 + dest.lpVtbl.pQueryInterface = syscall.NewCallback(QueryInterface)
121 + dest.lpVtbl.pAddRef = syscall.NewCallback(AddRef)
122 + dest.lpVtbl.pRelease = syscall.NewCallback(Release)
123 + dest.lpVtbl.pGetTypeInfoCount = syscall.NewCallback(GetTypeInfoCount)
124 + dest.lpVtbl.pGetTypeInfo = syscall.NewCallback(GetTypeInfo)
125 + dest.lpVtbl.pGetIDsOfNames = syscall.NewCallback(GetIDsOfNames)
126 + dest.lpVtbl.pInvoke = syscall.NewCallback(Invoke)
127 + dest.host = winsock
128 +
129 + oleutil.ConnectObject(winsock, iid, (*ole.IUnknown)(unsafe.Pointer(dest)))
130 + _, err = oleutil.CallMethod(winsock, "Connect", "127.0.0.1", 80)
131 + if err != nil {
132 + log.Fatal(err)
133 + }
134 +
135 + var m ole.Msg
136 + for dest.ref != 0 {
137 + ole.GetMessage(&m, 0, 0, 0)
138 + ole.DispatchMessage(&m)
139 + }
140 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/guid.go new
+115
@@ -0,0 +1,115 @@
1 +package ole
2 +
3 +var (
4 + // IID_NULL is null Interface ID, used when no other Interface ID is known.
5 + IID_NULL = &GUID{0x00000000, 0x0000, 0x0000, [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
6 +
7 + // IID_IUnknown is for IUnknown interfaces.
8 + IID_IUnknown = &GUID{0x00000000, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}
9 +
10 + // IID_IDispatch is for IDispatch interfaces.
11 + IID_IDispatch = &GUID{0x00020400, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}
12 +
13 + // IID_IConnectionPointContainer is for IConnectionPointContainer interfaces.
14 + IID_IConnectionPointContainer = &GUID{0xB196B284, 0xBAB4, 0x101A, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}}
15 +
16 + // IID_IConnectionPoint is for IConnectionPoint interfaces.
17 + IID_IConnectionPoint = &GUID{0xB196B286, 0xBAB4, 0x101A, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}}
18 +
19 + // IID_IInspectable is for IInspectable interfaces.
20 + IID_IInspectable = &GUID{0xaf86e2e0, 0xb12d, 0x4c6a, [8]byte{0x9c, 0x5a, 0xd7, 0xaa, 0x65, 0x10, 0x1e, 0x90}}
21 +
22 + // IID_IProvideClassInfo is for IProvideClassInfo interfaces.
23 + IID_IProvideClassInfo = &GUID{0xb196b283, 0xbab4, 0x101a, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}}
24 +)
25 +
26 +// These are for testing and not part of any library.
27 +var (
28 + // IID_ICOMTestString is for ICOMTestString interfaces.
29 + //
30 + // {E0133EB4-C36F-469A-9D3D-C66B84BE19ED}
31 + IID_ICOMTestString = &GUID{0xe0133eb4, 0xc36f, 0x469a, [8]byte{0x9d, 0x3d, 0xc6, 0x6b, 0x84, 0xbe, 0x19, 0xed}}
32 +
33 + // IID_ICOMTestInt8 is for ICOMTestInt8 interfaces.
34 + //
35 + // {BEB06610-EB84-4155-AF58-E2BFF53608B4}
36 + IID_ICOMTestInt8 = &GUID{0xbeb06610, 0xeb84, 0x4155, [8]byte{0xaf, 0x58, 0xe2, 0xbf, 0xf5, 0x36, 0x80, 0xb4}}
37 +
38 + // IID_ICOMTestInt16 is for ICOMTestInt16 interfaces.
39 + //
40 + // {DAA3F9FA-761E-4976-A860-8364CE55F6FC}
41 + IID_ICOMTestInt16 = &GUID{0xdaa3f9fa, 0x761e, 0x4976, [8]byte{0xa8, 0x60, 0x83, 0x64, 0xce, 0x55, 0xf6, 0xfc}}
42 +
43 + // IID_ICOMTestInt32 is for ICOMTestInt32 interfaces.
44 + //
45 + // {E3DEDEE7-38A2-4540-91D1-2EEF1D8891B0}
46 + IID_ICOMTestInt32 = &GUID{0xe3dedee7, 0x38a2, 0x4540, [8]byte{0x91, 0xd1, 0x2e, 0xef, 0x1d, 0x88, 0x91, 0xb0}}
47 +
48 + // IID_ICOMTestInt64 is for ICOMTestInt64 interfaces.
49 + //
50 + // {8D437CBC-B3ED-485C-BC32-C336432A1623}
51 + IID_ICOMTestInt64 = &GUID{0x8d437cbc, 0xb3ed, 0x485c, [8]byte{0xbc, 0x32, 0xc3, 0x36, 0x43, 0x2a, 0x16, 0x23}}
52 +
53 + // IID_ICOMTestFloat is for ICOMTestFloat interfaces.
54 + //
55 + // {BF1ED004-EA02-456A-AA55-2AC8AC6B054C}
56 + IID_ICOMTestFloat = &GUID{0xbf1ed004, 0xea02, 0x456a, [8]byte{0xaa, 0x55, 0x2a, 0xc8, 0xac, 0x6b, 0x5, 0x4c}}
57 +
58 + // IID_ICOMTestDouble is for ICOMTestDouble interfaces.
59 + //
60 + // {BF908A81-8687-4E93-999F-D86FAB284BA0}
61 + IID_ICOMTestDouble = &GUID{0xbf908a81, 0x8687, 0x4e93, [8]byte{0x99, 0x9f, 0xd8, 0x6f, 0xab, 0x28, 0x4b, 0xa0}}
62 +
63 + // IID_ICOMTestBoolean is for ICOMTestBoolean interfaces.
64 + //
65 + // {D530E7A6-4EE8-40D1-8931-3D63B8605001}
66 + IID_ICOMTestBoolean = &GUID{0xd530e7a6, 0x4ee8, 0x40d1, [8]byte{0x89, 0x31, 0x3d, 0x63, 0xb8, 0x60, 0x50, 0x10}}
67 +
68 + // IID_ICOMEchoTestObject is for ICOMEchoTestObject interfaces.
69 + //
70 + // {6485B1EF-D780-4834-A4FE-1EBB51746CA3}
71 + IID_ICOMEchoTestObject = &GUID{0x6485b1ef, 0xd780, 0x4834, [8]byte{0xa4, 0xfe, 0x1e, 0xbb, 0x51, 0x74, 0x6c, 0xa3}}
72 +
73 + // IID_ICOMTestTypes is for ICOMTestTypes interfaces.
74 + //
75 + // {CCA8D7AE-91C0-4277-A8B3-FF4EDF28D3C0}
76 + IID_ICOMTestTypes = &GUID{0xcca8d7ae, 0x91c0, 0x4277, [8]byte{0xa8, 0xb3, 0xff, 0x4e, 0xdf, 0x28, 0xd3, 0xc0}}
77 +
78 + // CLSID_COMEchoTestObject is for COMEchoTestObject class.
79 + //
80 + // {3C24506A-AE9E-4D50-9157-EF317281F1B0}
81 + CLSID_COMEchoTestObject = &GUID{0x3c24506a, 0xae9e, 0x4d50, [8]byte{0x91, 0x57, 0xef, 0x31, 0x72, 0x81, 0xf1, 0xb0}}
82 +
83 + // CLSID_COMTestScalarClass is for COMTestScalarClass class.
84 + //
85 + // {865B85C5-0334-4AC6-9EF6-AACEC8FC5E86}
86 + CLSID_COMTestScalarClass = &GUID{0x865b85c5, 0x3340, 0x4ac6, [8]byte{0x9e, 0xf6, 0xaa, 0xce, 0xc8, 0xfc, 0x5e, 0x86}}
87 +)
88 +
89 +// GUID is Windows API specific GUID type.
90 +//
91 +// This exists to match Windows GUID type for direct passing for COM.
92 +// Format is in xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx.
93 +type GUID struct {
94 + Data1 uint32
95 + Data2 uint16
96 + Data3 uint16
97 + Data4 [8]byte
98 +}
99 +
100 +// IsEqualGUID compares two GUID.
101 +//
102 +// Not constant time comparison.
103 +func IsEqualGUID(guid1 *GUID, guid2 *GUID) bool {
104 + return guid1.Data1 == guid2.Data1 &&
105 + guid1.Data2 == guid2.Data2 &&
106 + guid1.Data3 == guid2.Data3 &&
107 + guid1.Data4[0] == guid2.Data4[0] &&
108 + guid1.Data4[1] == guid2.Data4[1] &&
109 + guid1.Data4[2] == guid2.Data4[2] &&
110 + guid1.Data4[3] == guid2.Data4[3] &&
111 + guid1.Data4[4] == guid2.Data4[4] &&
112 + guid1.Data4[5] == guid2.Data4[5] &&
113 + guid1.Data4[6] == guid2.Data4[6] &&
114 + guid1.Data4[7] == guid2.Data4[7]
115 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint.go new
+20
@@ -0,0 +1,20 @@
1 +package ole
2 +
3 +import "unsafe"
4 +
5 +type IConnectionPoint struct {
6 + IUnknown
7 +}
8 +
9 +type IConnectionPointVtbl struct {
10 + IUnknownVtbl
11 + GetConnectionInterface uintptr
12 + GetConnectionPointContainer uintptr
13 + Advise uintptr
14 + Unadvise uintptr
15 + EnumConnections uintptr
16 +}
17 +
18 +func (v *IConnectionPoint) VTable() *IConnectionPointVtbl {
19 + return (*IConnectionPointVtbl)(unsafe.Pointer(v.RawVTable))
20 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint_func.go new
+21
@@ -0,0 +1,21 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +import "unsafe"
6 +
7 +func (v *IConnectionPoint) GetConnectionInterface(piid **GUID) int32 {
8 + return int32(0)
9 +}
10 +
11 +func (v *IConnectionPoint) Advise(unknown *IUnknown) (uint32, error) {
12 + return uint32(0), NewError(E_NOTIMPL)
13 +}
14 +
15 +func (v *IConnectionPoint) Unadvise(cookie uint32) error {
16 + return NewError(E_NOTIMPL)
17 +}
18 +
19 +func (v *IConnectionPoint) EnumConnections(p *unsafe.Pointer) (err error) {
20 + return NewError(E_NOTIMPL)
21 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint_windows.go new
+43
@@ -0,0 +1,43 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "syscall"
7 + "unsafe"
8 +)
9 +
10 +func (v *IConnectionPoint) GetConnectionInterface(piid **GUID) int32 {
11 + // XXX: This doesn't look like it does what it's supposed to
12 + return release((*IUnknown)(unsafe.Pointer(v)))
13 +}
14 +
15 +func (v *IConnectionPoint) Advise(unknown *IUnknown) (cookie uint32, err error) {
16 + hr, _, _ := syscall.Syscall(
17 + v.VTable().Advise,
18 + 3,
19 + uintptr(unsafe.Pointer(v)),
20 + uintptr(unsafe.Pointer(unknown)),
21 + uintptr(unsafe.Pointer(&cookie)))
22 + if hr != 0 {
23 + err = NewError(hr)
24 + }
25 + return
26 +}
27 +
28 +func (v *IConnectionPoint) Unadvise(cookie uint32) (err error) {
29 + hr, _, _ := syscall.Syscall(
30 + v.VTable().Unadvise,
31 + 2,
32 + uintptr(unsafe.Pointer(v)),
33 + uintptr(cookie),
34 + 0)
35 + if hr != 0 {
36 + err = NewError(hr)
37 + }
38 + return
39 +}
40 +
41 +func (v *IConnectionPoint) EnumConnections(p *unsafe.Pointer) error {
42 + return NewError(E_NOTIMPL)
43 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer.go new
+17
@@ -0,0 +1,17 @@
1 +package ole
2 +
3 +import "unsafe"
4 +
5 +type IConnectionPointContainer struct {
6 + IUnknown
7 +}
8 +
9 +type IConnectionPointContainerVtbl struct {
10 + IUnknownVtbl
11 + EnumConnectionPoints uintptr
12 + FindConnectionPoint uintptr
13 +}
14 +
15 +func (v *IConnectionPointContainer) VTable() *IConnectionPointContainerVtbl {
16 + return (*IConnectionPointContainerVtbl)(unsafe.Pointer(v.RawVTable))
17 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer_func.go new
+11
@@ -0,0 +1,11 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +func (v *IConnectionPointContainer) EnumConnectionPoints(points interface{}) error {
6 + return NewError(E_NOTIMPL)
7 +}
8 +
9 +func (v *IConnectionPointContainer) FindConnectionPoint(iid *GUID, point **IConnectionPoint) error {
10 + return NewError(E_NOTIMPL)
11 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer_windows.go new
+25
@@ -0,0 +1,25 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "syscall"
7 + "unsafe"
8 +)
9 +
10 +func (v *IConnectionPointContainer) EnumConnectionPoints(points interface{}) error {
11 + return NewError(E_NOTIMPL)
12 +}
13 +
14 +func (v *IConnectionPointContainer) FindConnectionPoint(iid *GUID, point **IConnectionPoint) (err error) {
15 + hr, _, _ := syscall.Syscall(
16 + v.VTable().FindConnectionPoint,
17 + 3,
18 + uintptr(unsafe.Pointer(v)),
19 + uintptr(unsafe.Pointer(iid)),
20 + uintptr(unsafe.Pointer(point)))
21 + if hr != 0 {
22 + err = NewError(hr)
23 + }
24 + return
25 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch.go new
+39
@@ -0,0 +1,39 @@
1 +package ole
2 +
3 +import "unsafe"
4 +
5 +type IDispatch struct {
6 + IUnknown
7 +}
8 +
9 +type IDispatchVtbl struct {
10 + IUnknownVtbl
11 + GetTypeInfoCount uintptr
12 + GetTypeInfo uintptr
13 + GetIDsOfNames uintptr
14 + Invoke uintptr
15 +}
16 +
17 +func (v *IDispatch) VTable() *IDispatchVtbl {
18 + return (*IDispatchVtbl)(unsafe.Pointer(v.RawVTable))
19 +}
20 +
21 +func (v *IDispatch) GetIDsOfName(names []string) (dispid []int32, err error) {
22 + dispid, err = getIDsOfName(v, names)
23 + return
24 +}
25 +
26 +func (v *IDispatch) Invoke(dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error) {
27 + result, err = invoke(v, dispid, dispatch, params...)
28 + return
29 +}
30 +
31 +func (v *IDispatch) GetTypeInfoCount() (c uint32, err error) {
32 + c, err = getTypeInfoCount(v)
33 + return
34 +}
35 +
36 +func (v *IDispatch) GetTypeInfo() (tinfo *ITypeInfo, err error) {
37 + tinfo, err = getTypeInfo(v)
38 + return
39 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_func.go new
+19
@@ -0,0 +1,19 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +func getIDsOfName(disp *IDispatch, names []string) ([]int32, error) {
6 + return []int32{}, NewError(E_NOTIMPL)
7 +}
8 +
9 +func getTypeInfoCount(disp *IDispatch) (uint32, error) {
10 + return uint32(0), NewError(E_NOTIMPL)
11 +}
12 +
13 +func getTypeInfo(disp *IDispatch) (*ITypeInfo, error) {
14 + return nil, NewError(E_NOTIMPL)
15 +}
16 +
17 +func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}) (*VARIANT, error) {
18 + return nil, NewError(E_NOTIMPL)
19 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_windows.go new
+184
@@ -0,0 +1,184 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "syscall"
7 + "time"
8 + "unsafe"
9 +)
10 +
11 +func getIDsOfName(disp *IDispatch, names []string) (dispid []int32, err error) {
12 + wnames := make([]*uint16, len(names))
13 + for i := 0; i < len(names); i++ {
14 + wnames[i] = syscall.StringToUTF16Ptr(names[i])
15 + }
16 + dispid = make([]int32, len(names))
17 + namelen := uint32(len(names))
18 + hr, _, _ := syscall.Syscall6(
19 + disp.VTable().GetIDsOfNames,
20 + 6,
21 + uintptr(unsafe.Pointer(disp)),
22 + uintptr(unsafe.Pointer(IID_NULL)),
23 + uintptr(unsafe.Pointer(&wnames[0])),
24 + uintptr(namelen),
25 + uintptr(GetUserDefaultLCID()),
26 + uintptr(unsafe.Pointer(&dispid[0])))
27 + if hr != 0 {
28 + err = NewError(hr)
29 + }
30 + return
31 +}
32 +
33 +func getTypeInfoCount(disp *IDispatch) (c uint32, err error) {
34 + hr, _, _ := syscall.Syscall(
35 + disp.VTable().GetTypeInfoCount,
36 + 2,
37 + uintptr(unsafe.Pointer(disp)),
38 + uintptr(unsafe.Pointer(&c)),
39 + 0)
40 + if hr != 0 {
41 + err = NewError(hr)
42 + }
43 + return
44 +}
45 +
46 +func getTypeInfo(disp *IDispatch) (tinfo *ITypeInfo, err error) {
47 + hr, _, _ := syscall.Syscall(
48 + disp.VTable().GetTypeInfo,
49 + 3,
50 + uintptr(unsafe.Pointer(disp)),
51 + uintptr(GetUserDefaultLCID()),
52 + uintptr(unsafe.Pointer(&tinfo)))
53 + if hr != 0 {
54 + err = NewError(hr)
55 + }
56 + return
57 +}
58 +
59 +func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error) {
60 + var dispparams DISPPARAMS
61 +
62 + if dispatch&DISPATCH_PROPERTYPUT != 0 {
63 + dispnames := [1]int32{DISPID_PROPERTYPUT}
64 + dispparams.rgdispidNamedArgs = uintptr(unsafe.Pointer(&dispnames[0]))
65 + dispparams.cNamedArgs = 1
66 + }
67 + var vargs []VARIANT
68 + if len(params) > 0 {
69 + vargs = make([]VARIANT, len(params))
70 + for i, v := range params {
71 + //n := len(params)-i-1
72 + n := len(params) - i - 1
73 + VariantInit(&vargs[n])
74 + switch vv := v.(type) {
75 + case bool:
76 + if vv {
77 + vargs[n] = NewVariant(VT_BOOL, 0xffff)
78 + } else {
79 + vargs[n] = NewVariant(VT_BOOL, 0)
80 + }
81 + case *bool:
82 + vargs[n] = NewVariant(VT_BOOL|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*bool)))))
83 + case byte:
84 + vargs[n] = NewVariant(VT_I1, int64(v.(byte)))
85 + case *byte:
86 + vargs[n] = NewVariant(VT_I1|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*byte)))))
87 + case int16:
88 + vargs[n] = NewVariant(VT_I2, int64(v.(int16)))
89 + case *int16:
90 + vargs[n] = NewVariant(VT_I2|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int16)))))
91 + case uint16:
92 + vargs[n] = NewVariant(VT_UI2, int64(v.(uint16)))
93 + case *uint16:
94 + vargs[n] = NewVariant(VT_UI2|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint16)))))
95 + case int, int32:
96 + vargs[n] = NewVariant(VT_I4, int64(v.(int)))
97 + case *int, *int32:
98 + vargs[n] = NewVariant(VT_I4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int)))))
99 + case uint, uint32:
100 + vargs[n] = NewVariant(VT_UI4, int64(v.(uint)))
101 + case *uint, *uint32:
102 + vargs[n] = NewVariant(VT_UI4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint)))))
103 + case int64:
104 + vargs[n] = NewVariant(VT_I8, int64(v.(int64)))
105 + case *int64:
106 + vargs[n] = NewVariant(VT_I8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int64)))))
107 + case uint64:
108 + vargs[n] = NewVariant(VT_UI8, v.(int64))
109 + case *uint64:
110 + vargs[n] = NewVariant(VT_UI8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint64)))))
111 + case float32:
112 + vargs[n] = NewVariant(VT_R4, *(*int64)(unsafe.Pointer(&vv)))
113 + case *float32:
114 + vargs[n] = NewVariant(VT_R4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*float32)))))
115 + case float64:
116 + vargs[n] = NewVariant(VT_R8, *(*int64)(unsafe.Pointer(&vv)))
117 + case *float64:
118 + vargs[n] = NewVariant(VT_R8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*float64)))))
119 + case string:
120 + vargs[n] = NewVariant(VT_BSTR, int64(uintptr(unsafe.Pointer(SysAllocStringLen(v.(string))))))
121 + case *string:
122 + vargs[n] = NewVariant(VT_BSTR|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*string)))))
123 + case time.Time:
124 + s := vv.Format("2006-01-02 15:04:05")
125 + vargs[n] = NewVariant(VT_BSTR, int64(uintptr(unsafe.Pointer(SysAllocStringLen(s)))))
126 + case *time.Time:
127 + s := vv.Format("2006-01-02 15:04:05")
128 + vargs[n] = NewVariant(VT_BSTR|VT_BYREF, int64(uintptr(unsafe.Pointer(&s))))
129 + case *IDispatch:
130 + vargs[n] = NewVariant(VT_DISPATCH, int64(uintptr(unsafe.Pointer(v.(*IDispatch)))))
131 + case **IDispatch:
132 + vargs[n] = NewVariant(VT_DISPATCH|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(**IDispatch)))))
133 + case nil:
134 + vargs[n] = NewVariant(VT_NULL, 0)
135 + case *VARIANT:
136 + vargs[n] = NewVariant(VT_VARIANT|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*VARIANT)))))
137 + case []byte:
138 + safeByteArray := safeArrayFromByteSlice(v.([]byte))
139 + vargs[n] = NewVariant(VT_ARRAY|VT_UI1, int64(uintptr(unsafe.Pointer(safeByteArray))))
140 + defer VariantClear(&vargs[n])
141 + case []string:
142 + safeByteArray := safeArrayFromStringSlice(v.([]string))
143 + vargs[n] = NewVariant(VT_ARRAY|VT_BSTR, int64(uintptr(unsafe.Pointer(safeByteArray))))
144 + defer VariantClear(&vargs[n])
145 + default:
146 + panic("unknown type")
147 + }
148 + }
149 + dispparams.rgvarg = uintptr(unsafe.Pointer(&vargs[0]))
150 + dispparams.cArgs = uint32(len(params))
151 + }
152 +
153 + result = new(VARIANT)
154 + var excepInfo EXCEPINFO
155 + VariantInit(result)
156 + hr, _, _ := syscall.Syscall9(
157 + disp.VTable().Invoke,
158 + 9,
159 + uintptr(unsafe.Pointer(disp)),
160 + uintptr(dispid),
161 + uintptr(unsafe.Pointer(IID_NULL)),
162 + uintptr(GetUserDefaultLCID()),
163 + uintptr(dispatch),
164 + uintptr(unsafe.Pointer(&dispparams)),
165 + uintptr(unsafe.Pointer(result)),
166 + uintptr(unsafe.Pointer(&excepInfo)),
167 + 0)
168 + if hr != 0 {
169 + err = NewErrorWithSubError(hr, BstrToString(excepInfo.bstrDescription), excepInfo)
170 + }
171 + for _, varg := range vargs {
172 + if varg.VT == VT_BSTR && varg.Val != 0 {
173 + SysFreeString(((*int16)(unsafe.Pointer(uintptr(varg.Val)))))
174 + }
175 + /*
176 + if varg.VT == (VT_BSTR|VT_BYREF) && varg.Val != 0 {
177 + *(params[n].(*string)) = LpOleStrToString((*uint16)(unsafe.Pointer(uintptr(varg.Val))))
178 + println(*(params[n].(*string)))
179 + fmt.Fprintln(os.Stderr, *(params[n].(*string)))
180 + }
181 + */
182 + }
183 + return
184 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_windows_test.go new
+83
@@ -0,0 +1,83 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "reflect"
7 + "testing"
8 +)
9 +
10 +func TestIDispatch(t *testing.T) {
11 + defer func() {
12 + if r := recover(); r != nil {
13 + t.Error(r)
14 + }
15 + }()
16 +
17 + var err error
18 +
19 + err = CoInitialize(0)
20 + if err != nil {
21 + t.Fatal(err)
22 + }
23 +
24 + defer CoUninitialize()
25 +
26 + var unknown *IUnknown
27 + var dispatch *IDispatch
28 +
29 + // oleutil.CreateObject()
30 + unknown, err = CreateInstance(CLSID_COMEchoTestObject, IID_IUnknown)
31 + if err != nil {
32 + t.Fatal(err)
33 + return
34 + }
35 + defer unknown.Release()
36 +
37 + dispatch, err = unknown.QueryInterface(IID_ICOMEchoTestObject)
38 + if err != nil {
39 + t.Fatal(err)
40 + return
41 + }
42 + defer dispatch.Release()
43 +
44 + echoValue := func(method string, value interface{}) (interface{}, bool) {
45 + var dispid []int32
46 + var err error
47 +
48 + dispid, err = dispatch.GetIDsOfName([]string{method})
49 + if err != nil {
50 + t.Fatal(err)
51 + return nil, false
52 + }
53 +
54 + result, err := dispatch.Invoke(dispid[0], DISPATCH_METHOD, value)
55 + if err != nil {
56 + t.Fatal(err)
57 + return nil, false
58 + }
59 +
60 + return result.Value(), true
61 + }
62 +
63 + methods := map[string]interface{}{
64 + "EchoInt8": int8(1),
65 + "EchoInt16": int16(1),
66 + "EchoInt32": int32(1),
67 + "EchoInt64": int64(1),
68 + "EchoUInt8": uint8(1),
69 + "EchoUInt16": uint16(1),
70 + "EchoUInt32": uint(1),
71 + "EchoUInt64": uint64(1),
72 + "EchoFloat32": float32(1.2),
73 + "EchoFloat64": float64(1.2),
74 + "EchoString": "Test String"}
75 +
76 + for method, expected := range methods {
77 + if actual, passed := echoValue(method, expected); passed {
78 + if !reflect.DeepEqual(expected, actual) {
79 + t.Errorf("%s() expected %v did not match %v", method, expected, actual)
80 + }
81 + }
82 + }
83 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant.go new
+19
@@ -0,0 +1,19 @@
1 +package ole
2 +
3 +import "unsafe"
4 +
5 +type IEnumVARIANT struct {
6 + IUnknown
7 +}
8 +
9 +type IEnumVARIANTVtbl struct {
10 + IUnknownVtbl
11 + Next uintptr
12 + Skip uintptr
13 + Reset uintptr
14 + Clone uintptr
15 +}
16 +
17 +func (v *IEnumVARIANT) VTable() *IEnumVARIANTVtbl {
18 + return (*IEnumVARIANTVtbl)(unsafe.Pointer(v.RawVTable))
19 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant_func.go new
+19
@@ -0,0 +1,19 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +func (enum *IEnumVARIANT) Clone() (*IEnumVARIANT, error) {
6 + return nil, NewError(E_NOTIMPL)
7 +}
8 +
9 +func (enum *IEnumVARIANT) Reset() error {
10 + return NewError(E_NOTIMPL)
11 +}
12 +
13 +func (enum *IEnumVARIANT) Skip(celt uint) error {
14 + return NewError(E_NOTIMPL)
15 +}
16 +
17 +func (enum *IEnumVARIANT) Next(celt uint) (*VARIANT, uint, error) {
18 + return nil, 0, NewError(E_NOTIMPL)
19 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant_windows.go new
+63
@@ -0,0 +1,63 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "syscall"
7 + "unsafe"
8 +)
9 +
10 +func (enum *IEnumVARIANT) Clone() (cloned *IEnumVARIANT, err error) {
11 + hr, _, _ := syscall.Syscall(
12 + enum.VTable().Clone,
13 + 2,
14 + uintptr(unsafe.Pointer(enum)),
15 + uintptr(unsafe.Pointer(&cloned)),
16 + 0)
17 + if hr != 0 {
18 + err = NewError(hr)
19 + }
20 + return
21 +}
22 +
23 +func (enum *IEnumVARIANT) Reset() (err error) {
24 + hr, _, _ := syscall.Syscall(
25 + enum.VTable().Reset,
26 + 1,
27 + uintptr(unsafe.Pointer(enum)),
28 + 0,
29 + 0)
30 + if hr != 0 {
31 + err = NewError(hr)
32 + }
33 + return
34 +}
35 +
36 +func (enum *IEnumVARIANT) Skip(celt uint) (err error) {
37 + hr, _, _ := syscall.Syscall(
38 + enum.VTable().Skip,
39 + 2,
40 + uintptr(unsafe.Pointer(enum)),
41 + uintptr(celt),
42 + 0)
43 + if hr != 0 {
44 + err = NewError(hr)
45 + }
46 + return
47 +}
48 +
49 +func (enum *IEnumVARIANT) Next(celt uint) (array *VARIANT, length uint, err error) {
50 + hr, _, _ := syscall.Syscall6(
51 + enum.VTable().Next,
52 + 4,
53 + uintptr(unsafe.Pointer(enum)),
54 + uintptr(celt),
55 + uintptr(unsafe.Pointer(&array)),
56 + uintptr(unsafe.Pointer(&length)),
57 + 0,
58 + 0)
59 + if hr != 0 {
60 + err = NewError(hr)
61 + }
62 + return
63 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable.go new
+18
@@ -0,0 +1,18 @@
1 +package ole
2 +
3 +import "unsafe"
4 +
5 +type IInspectable struct {
6 + IUnknown
7 +}
8 +
9 +type IInspectableVtbl struct {
10 + IUnknownVtbl
11 + GetIIds uintptr
12 + GetRuntimeClassName uintptr
13 + GetTrustLevel uintptr
14 +}
15 +
16 +func (v *IInspectable) VTable() *IInspectableVtbl {
17 + return (*IInspectableVtbl)(unsafe.Pointer(v.RawVTable))
18 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable_func.go new
+15
@@ -0,0 +1,15 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +func (v *IInspectable) GetIids() ([]*GUID, error) {
6 + return []*GUID{}, NewError(E_NOTIMPL)
7 +}
8 +
9 +func (v *IInspectable) GetRuntimeClassName() (string, error) {
10 + return "", NewError(E_NOTIMPL)
11 +}
12 +
13 +func (v *IInspectable) GetTrustLevel() (uint32, error) {
14 + return uint32(0), NewError(E_NOTIMPL)
15 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable_windows.go new
+72
@@ -0,0 +1,72 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "bytes"
7 + "encoding/binary"
8 + "reflect"
9 + "syscall"
10 + "unsafe"
11 +)
12 +
13 +func (v *IInspectable) GetIids() (iids []*GUID, err error) {
14 + var count uint32
15 + var array uintptr
16 + hr, _, _ := syscall.Syscall(
17 + v.VTable().GetIIds,
18 + 3,
19 + uintptr(unsafe.Pointer(v)),
20 + uintptr(unsafe.Pointer(&count)),
21 + uintptr(unsafe.Pointer(&array)))
22 + if hr != 0 {
23 + err = NewError(hr)
24 + return
25 + }
26 + defer CoTaskMemFree(array)
27 +
28 + iids = make([]*GUID, count)
29 + byteCount := count * uint32(unsafe.Sizeof(GUID{}))
30 + slicehdr := reflect.SliceHeader{Data: array, Len: int(byteCount), Cap: int(byteCount)}
31 + byteSlice := *(*[]byte)(unsafe.Pointer(&slicehdr))
32 + reader := bytes.NewReader(byteSlice)
33 + for i, _ := range iids {
34 + guid := GUID{}
35 + err = binary.Read(reader, binary.LittleEndian, &guid)
36 + if err != nil {
37 + return
38 + }
39 + iids[i] = &guid
40 + }
41 + return
42 +}
43 +
44 +func (v *IInspectable) GetRuntimeClassName() (s string, err error) {
45 + var hstring HString
46 + hr, _, _ := syscall.Syscall(
47 + v.VTable().GetRuntimeClassName,
48 + 2,
49 + uintptr(unsafe.Pointer(v)),
50 + uintptr(unsafe.Pointer(&hstring)),
51 + 0)
52 + if hr != 0 {
53 + err = NewError(hr)
54 + return
55 + }
56 + s = hstring.String()
57 + DeleteHString(hstring)
58 + return
59 +}
60 +
61 +func (v *IInspectable) GetTrustLevel() (level uint32, err error) {
62 + hr, _, _ := syscall.Syscall(
63 + v.VTable().GetTrustLevel,
64 + 2,
65 + uintptr(unsafe.Pointer(v)),
66 + uintptr(unsafe.Pointer(&level)),
67 + 0)
68 + if hr != 0 {
69 + err = NewError(hr)
70 + }
71 + return
72 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo.go new
+21
@@ -0,0 +1,21 @@
1 +package ole
2 +
3 +import "unsafe"
4 +
5 +type IProvideClassInfo struct {
6 + IUnknown
7 +}
8 +
9 +type IProvideClassInfoVtbl struct {
10 + IUnknownVtbl
11 + GetClassInfo uintptr
12 +}
13 +
14 +func (v *IProvideClassInfo) VTable() *IProvideClassInfoVtbl {
15 + return (*IProvideClassInfoVtbl)(unsafe.Pointer(v.RawVTable))
16 +}
17 +
18 +func (v *IProvideClassInfo) GetClassInfo() (cinfo *ITypeInfo, err error) {
19 + cinfo, err = getClassInfo(v)
20 + return
21 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo_func.go new
+7
@@ -0,0 +1,7 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +func getClassInfo(disp *IProvideClassInfo) (tinfo *ITypeInfo, err error) {
6 + return nil, NewError(E_NOTIMPL)
7 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo_windows.go new
+21
@@ -0,0 +1,21 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "syscall"
7 + "unsafe"
8 +)
9 +
10 +func getClassInfo(disp *IProvideClassInfo) (tinfo *ITypeInfo, err error) {
11 + hr, _, _ := syscall.Syscall(
12 + disp.VTable().GetClassInfo,
13 + 2,
14 + uintptr(unsafe.Pointer(disp)),
15 + uintptr(unsafe.Pointer(&tinfo)),
16 + 0)
17 + if hr != 0 {
18 + err = NewError(hr)
19 + }
20 + return
21 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo.go new
+34
@@ -0,0 +1,34 @@
1 +package ole
2 +
3 +import "unsafe"
4 +
5 +type ITypeInfo struct {
6 + IUnknown
7 +}
8 +
9 +type ITypeInfoVtbl struct {
10 + IUnknownVtbl
11 + GetTypeAttr uintptr
12 + GetTypeComp uintptr
13 + GetFuncDesc uintptr
14 + GetVarDesc uintptr
15 + GetNames uintptr
16 + GetRefTypeOfImplType uintptr
17 + GetImplTypeFlags uintptr
18 + GetIDsOfNames uintptr
19 + Invoke uintptr
20 + GetDocumentation uintptr
21 + GetDllEntry uintptr
22 + GetRefTypeInfo uintptr
23 + AddressOfMember uintptr
24 + CreateInstance uintptr
25 + GetMops uintptr
26 + GetContainingTypeLib uintptr
27 + ReleaseTypeAttr uintptr
28 + ReleaseFuncDesc uintptr
29 + ReleaseVarDesc uintptr
30 +}
31 +
32 +func (v *ITypeInfo) VTable() *ITypeInfoVtbl {
33 + return (*ITypeInfoVtbl)(unsafe.Pointer(v.RawVTable))
34 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo_func.go new
+7
@@ -0,0 +1,7 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +func (v *ITypeInfo) GetTypeAttr() (*TYPEATTR, error) {
6 + return nil, NewError(E_NOTIMPL)
7 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo_windows.go new
+21
@@ -0,0 +1,21 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "syscall"
7 + "unsafe"
8 +)
9 +
10 +func (v *ITypeInfo) GetTypeAttr() (tattr *TYPEATTR, err error) {
11 + hr, _, _ := syscall.Syscall(
12 + uintptr(v.VTable().GetTypeAttr),
13 + 2,
14 + uintptr(unsafe.Pointer(v)),
15 + uintptr(unsafe.Pointer(&tattr)),
16 + 0)
17 + if hr != 0 {
18 + err = NewError(hr)
19 + }
20 + return
21 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown.go new
+57
@@ -0,0 +1,57 @@
1 +package ole
2 +
3 +import "unsafe"
4 +
5 +type IUnknown struct {
6 + RawVTable *interface{}
7 +}
8 +
9 +type IUnknownVtbl struct {
10 + QueryInterface uintptr
11 + AddRef uintptr
12 + Release uintptr
13 +}
14 +
15 +type UnknownLike interface {
16 + QueryInterface(iid *GUID) (disp *IDispatch, err error)
17 + AddRef() int32
18 + Release() int32
19 +}
20 +
21 +func (v *IUnknown) VTable() *IUnknownVtbl {
22 + return (*IUnknownVtbl)(unsafe.Pointer(v.RawVTable))
23 +}
24 +
25 +func (v *IUnknown) PutQueryInterface(interfaceID *GUID, obj interface{}) error {
26 + return reflectQueryInterface(v, v.VTable().QueryInterface, interfaceID, &obj)
27 +}
28 +
29 +func (v *IUnknown) IDispatch(interfaceID *GUID) (dispatch *IDispatch, err error) {
30 + err = v.PutQueryInterface(interfaceID, &dispatch)
31 + return
32 +}
33 +
34 +func (v *IUnknown) IEnumVARIANT(interfaceID *GUID) (enum *IEnumVARIANT, err error) {
35 + err = v.PutQueryInterface(interfaceID, &enum)
36 + return
37 +}
38 +
39 +func (v *IUnknown) QueryInterface(iid *GUID) (*IDispatch, error) {
40 + return queryInterface(v, iid)
41 +}
42 +
43 +func (v *IUnknown) MustQueryInterface(iid *GUID) (disp *IDispatch) {
44 + unk, err := queryInterface(v, iid)
45 + if err != nil {
46 + panic(err)
47 + }
48 + return unk
49 +}
50 +
51 +func (v *IUnknown) AddRef() int32 {
52 + return addRef(v)
53 +}
54 +
55 +func (v *IUnknown) Release() int32 {
56 + return release(v)
57 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_func.go new
+19
@@ -0,0 +1,19 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +func reflectQueryInterface(self interface{}, method uintptr, interfaceID *GUID, obj interface{}) (err error) {
6 + return NewError(E_NOTIMPL)
7 +}
8 +
9 +func queryInterface(unk *IUnknown, iid *GUID) (disp *IDispatch, err error) {
10 + return nil, NewError(E_NOTIMPL)
11 +}
12 +
13 +func addRef(unk *IUnknown) int32 {
14 + return 0
15 +}
16 +
17 +func release(unk *IUnknown) int32 {
18 + return 0
19 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_windows.go new
+55
@@ -0,0 +1,55 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "reflect"
7 + "syscall"
8 + "unsafe"
9 +)
10 +
11 +func reflectQueryInterface(self interface{}, method uintptr, interfaceID *GUID, obj interface{}) (err error) {
12 + hr, _, _ := syscall.Syscall(
13 + method,
14 + 3,
15 + reflect.ValueOf(self).UnsafeAddr(),
16 + uintptr(unsafe.Pointer(interfaceID)),
17 + reflect.ValueOf(obj).UnsafeAddr())
18 + if hr != 0 {
19 + err = NewError(hr)
20 + }
21 + return
22 +}
23 +
24 +func queryInterface(unk *IUnknown, iid *GUID) (disp *IDispatch, err error) {
25 + hr, _, _ := syscall.Syscall(
26 + unk.VTable().QueryInterface,
27 + 3,
28 + uintptr(unsafe.Pointer(unk)),
29 + uintptr(unsafe.Pointer(iid)),
30 + uintptr(unsafe.Pointer(&disp)))
31 + if hr != 0 {
32 + err = NewError(hr)
33 + }
34 + return
35 +}
36 +
37 +func addRef(unk *IUnknown) int32 {
38 + ret, _, _ := syscall.Syscall(
39 + unk.VTable().AddRef,
40 + 1,
41 + uintptr(unsafe.Pointer(unk)),
42 + 0,
43 + 0)
44 + return int32(ret)
45 +}
46 +
47 +func release(unk *IUnknown) int32 {
48 + ret, _, _ := syscall.Syscall(
49 + unk.VTable().Release,
50 + 1,
51 + uintptr(unsafe.Pointer(unk)),
52 + 0,
53 + 0)
54 + return int32(ret)
55 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_windows_test.go new
+32
@@ -0,0 +1,32 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import "testing"
6 +
7 +func TestIUnknown(t *testing.T) {
8 + defer func() {
9 + if r := recover(); r != nil {
10 + t.Error(r)
11 + }
12 + }()
13 +
14 + var err error
15 +
16 + err = CoInitialize(0)
17 + if err != nil {
18 + t.Fatal(err)
19 + }
20 +
21 + defer CoUninitialize()
22 +
23 + var unknown *IUnknown
24 +
25 + // oleutil.CreateObject()
26 + unknown, err = CreateInstance(CLSID_COMEchoTestObject, IID_IUnknown)
27 + if err != nil {
28 + t.Fatal(err)
29 + return
30 + }
31 + unknown.Release()
32 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/ole.go new
+147
@@ -0,0 +1,147 @@
1 +package ole
2 +
3 +import (
4 + "fmt"
5 + "strings"
6 +)
7 +
8 +// DISPPARAMS are the arguments that passed to methods or property.
9 +type DISPPARAMS struct {
10 + rgvarg uintptr
11 + rgdispidNamedArgs uintptr
12 + cArgs uint32
13 + cNamedArgs uint32
14 +}
15 +
16 +// EXCEPINFO defines exception info.
17 +type EXCEPINFO struct {
18 + wCode uint16
19 + wReserved uint16
20 + bstrSource *uint16
21 + bstrDescription *uint16
22 + bstrHelpFile *uint16
23 + dwHelpContext uint32
24 + pvReserved uintptr
25 + pfnDeferredFillIn uintptr
26 + scode uint32
27 +}
28 +
29 +// String convert EXCEPINFO to string.
30 +func (e EXCEPINFO) String() string {
31 + var src, desc, hlp string
32 + if e.bstrSource == nil {
33 + src = "<nil>"
34 + } else {
35 + src = BstrToString(e.bstrSource)
36 + }
37 +
38 + if e.bstrDescription == nil {
39 + desc = "<nil>"
40 + } else {
41 + desc = BstrToString(e.bstrDescription)
42 + }
43 +
44 + if e.bstrHelpFile == nil {
45 + hlp = "<nil>"
46 + } else {
47 + hlp = BstrToString(e.bstrHelpFile)
48 + }
49 +
50 + return fmt.Sprintf(
51 + "wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x",
52 + e.wCode, src, desc, hlp, e.dwHelpContext, e.scode,
53 + )
54 +}
55 +
56 +// Error implements error interface and returns error string.
57 +func (e EXCEPINFO) Error() string {
58 + if e.bstrDescription != nil {
59 + return strings.TrimSpace(BstrToString(e.bstrDescription))
60 + }
61 +
62 + src := "Unknown"
63 + if e.bstrSource != nil {
64 + src = BstrToString(e.bstrSource)
65 + }
66 +
67 + code := e.scode
68 + if e.wCode != 0 {
69 + code = uint32(e.wCode)
70 + }
71 +
72 + return fmt.Sprintf("%v: %#x", src, code)
73 +}
74 +
75 +// PARAMDATA defines parameter data type.
76 +type PARAMDATA struct {
77 + Name *int16
78 + Vt uint16
79 +}
80 +
81 +// METHODDATA defines method info.
82 +type METHODDATA struct {
83 + Name *uint16
84 + Data *PARAMDATA
85 + Dispid int32
86 + Meth uint32
87 + CC int32
88 + CArgs uint32
89 + Flags uint16
90 + VtReturn uint32
91 +}
92 +
93 +// INTERFACEDATA defines interface info.
94 +type INTERFACEDATA struct {
95 + MethodData *METHODDATA
96 + CMembers uint32
97 +}
98 +
99 +// Point is 2D vector type.
100 +type Point struct {
101 + X int32
102 + Y int32
103 +}
104 +
105 +// Msg is message between processes.
106 +type Msg struct {
107 + Hwnd uint32
108 + Message uint32
109 + Wparam int32
110 + Lparam int32
111 + Time uint32
112 + Pt Point
113 +}
114 +
115 +// TYPEDESC defines data type.
116 +type TYPEDESC struct {
117 + Hreftype uint32
118 + VT uint16
119 +}
120 +
121 +// IDLDESC defines IDL info.
122 +type IDLDESC struct {
123 + DwReserved uint32
124 + WIDLFlags uint16
125 +}
126 +
127 +// TYPEATTR defines type info.
128 +type TYPEATTR struct {
129 + Guid GUID
130 + Lcid uint32
131 + dwReserved uint32
132 + MemidConstructor int32
133 + MemidDestructor int32
134 + LpstrSchema *uint16
135 + CbSizeInstance uint32
136 + Typekind int32
137 + CFuncs uint16
138 + CVars uint16
139 + CImplTypes uint16
140 + CbSizeVft uint16
141 + CbAlignment uint16
142 + WTypeFlags uint16
143 + WMajorVerNum uint16
144 + WMinorVerNum uint16
145 + TdescAlias TYPEDESC
146 + IdldescType IDLDESC
147 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection.go new
+100
@@ -0,0 +1,100 @@
1 +// +build windows
2 +
3 +package oleutil
4 +
5 +import (
6 + "reflect"
7 + "unsafe"
8 +
9 + ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
10 +)
11 +
12 +type stdDispatch struct {
13 + lpVtbl *stdDispatchVtbl
14 + ref int32
15 + iid *ole.GUID
16 + iface interface{}
17 + funcMap map[string]int32
18 +}
19 +
20 +type stdDispatchVtbl struct {
21 + pQueryInterface uintptr
22 + pAddRef uintptr
23 + pRelease uintptr
24 + pGetTypeInfoCount uintptr
25 + pGetTypeInfo uintptr
26 + pGetIDsOfNames uintptr
27 + pInvoke uintptr
28 +}
29 +
30 +func dispQueryInterface(this *ole.IUnknown, iid *ole.GUID, punk **ole.IUnknown) uint32 {
31 + pthis := (*stdDispatch)(unsafe.Pointer(this))
32 + *punk = nil
33 + if ole.IsEqualGUID(iid, ole.IID_IUnknown) ||
34 + ole.IsEqualGUID(iid, ole.IID_IDispatch) {
35 + dispAddRef(this)
36 + *punk = this
37 + return ole.S_OK
38 + }
39 + if ole.IsEqualGUID(iid, pthis.iid) {
40 + dispAddRef(this)
41 + *punk = this
42 + return ole.S_OK
43 + }
44 + return ole.E_NOINTERFACE
45 +}
46 +
47 +func dispAddRef(this *ole.IUnknown) int32 {
48 + pthis := (*stdDispatch)(unsafe.Pointer(this))
49 + pthis.ref++
50 + return pthis.ref
51 +}
52 +
53 +func dispRelease(this *ole.IUnknown) int32 {
54 + pthis := (*stdDispatch)(unsafe.Pointer(this))
55 + pthis.ref--
56 + return pthis.ref
57 +}
58 +
59 +func dispGetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen int, lcid int, pdisp []int32) uintptr {
60 + pthis := (*stdDispatch)(unsafe.Pointer(this))
61 + names := make([]string, len(wnames))
62 + for i := 0; i < len(names); i++ {
63 + names[i] = ole.LpOleStrToString(wnames[i])
64 + }
65 + for n := 0; n < namelen; n++ {
66 + if id, ok := pthis.funcMap[names[n]]; ok {
67 + pdisp[n] = id
68 + }
69 + }
70 + return ole.S_OK
71 +}
72 +
73 +func dispGetTypeInfoCount(pcount *int) uintptr {
74 + if pcount != nil {
75 + *pcount = 0
76 + }
77 + return ole.S_OK
78 +}
79 +
80 +func dispGetTypeInfo(ptypeif *uintptr) uintptr {
81 + return ole.E_NOTIMPL
82 +}
83 +
84 +func dispInvoke(this *ole.IDispatch, dispid int32, riid *ole.GUID, lcid int, flags int16, dispparams *ole.DISPPARAMS, result *ole.VARIANT, pexcepinfo *ole.EXCEPINFO, nerr *uint) uintptr {
85 + pthis := (*stdDispatch)(unsafe.Pointer(this))
86 + found := ""
87 + for name, id := range pthis.funcMap {
88 + if id == dispid {
89 + found = name
90 + }
91 + }
92 + if found != "" {
93 + rv := reflect.ValueOf(pthis.iface).Elem()
94 + rm := rv.MethodByName(found)
95 + rr := rm.Call([]reflect.Value{})
96 + println(len(rr))
97 + return ole.S_OK
98 + }
99 + return ole.E_NOTIMPL
100 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection_func.go new
+10
@@ -0,0 +1,10 @@
1 +// +build !windows
2 +
3 +package oleutil
4 +
5 +import ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
6 +
7 +// ConnectObject creates a connection point between two services for communication.
8 +func ConnectObject(disp *ole.IDispatch, iid *ole.GUID, idisp interface{}) (uint32, error) {
9 + return 0, ole.NewError(ole.E_NOTIMPL)
10 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection_windows.go new
+57
@@ -0,0 +1,57 @@
1 +// +build windows
2 +
3 +package oleutil
4 +
5 +import (
6 + "reflect"
7 + "syscall"
8 + "unsafe"
9 +
10 + ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
11 +)
12 +
13 +// ConnectObject creates a connection point between two services for communication.
14 +func ConnectObject(disp *ole.IDispatch, iid *ole.GUID, idisp interface{}) (cookie uint32, err error) {
15 + unknown, err := disp.QueryInterface(ole.IID_IConnectionPointContainer)
16 + if err != nil {
17 + return
18 + }
19 +
20 + container := (*ole.IConnectionPointContainer)(unsafe.Pointer(unknown))
21 + var point *ole.IConnectionPoint
22 + err = container.FindConnectionPoint(iid, &point)
23 + if err != nil {
24 + return
25 + }
26 + if edisp, ok := idisp.(*ole.IUnknown); ok {
27 + cookie, err = point.Advise(edisp)
28 + container.Release()
29 + if err != nil {
30 + return
31 + }
32 + }
33 + rv := reflect.ValueOf(disp).Elem()
34 + if rv.Type().Kind() == reflect.Struct {
35 + dest := &stdDispatch{}
36 + dest.lpVtbl = &stdDispatchVtbl{}
37 + dest.lpVtbl.pQueryInterface = syscall.NewCallback(dispQueryInterface)
38 + dest.lpVtbl.pAddRef = syscall.NewCallback(dispAddRef)
39 + dest.lpVtbl.pRelease = syscall.NewCallback(dispRelease)
40 + dest.lpVtbl.pGetTypeInfoCount = syscall.NewCallback(dispGetTypeInfoCount)
41 + dest.lpVtbl.pGetTypeInfo = syscall.NewCallback(dispGetTypeInfo)
42 + dest.lpVtbl.pGetIDsOfNames = syscall.NewCallback(dispGetIDsOfNames)
43 + dest.lpVtbl.pInvoke = syscall.NewCallback(dispInvoke)
44 + dest.iface = disp
45 + dest.iid = iid
46 + cookie, err = point.Advise((*ole.IUnknown)(unsafe.Pointer(dest)))
47 + container.Release()
48 + if err != nil {
49 + point.Release()
50 + return
51 + }
52 + }
53 +
54 + container.Release()
55 +
56 + return 0, ole.NewError(ole.E_INVALIDARG)
57 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/go-get.go new
+6
@@ -0,0 +1,6 @@
1 +// This file is here so go get succeeds as without it errors with:
2 +// no buildable Go source files in ...
3 +//
4 +// +build !windows
5 +
6 +package oleutil
Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/oleutil.go new
+132
@@ -0,0 +1,132 @@
1 +package oleutil
2 +
3 +import ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
4 +
5 +// ClassIDFrom retrieves class ID whether given is program ID or application string.
6 +func ClassIDFrom(programID string) (classID *ole.GUID, err error) {
7 + classID, err = ole.CLSIDFromProgID(programID)
8 + if err != nil {
9 + classID, err = ole.CLSIDFromString(programID)
10 + if err != nil {
11 + return
12 + }
13 + }
14 + return
15 +}
16 +
17 +// CreateObject creates object from programID based on interface type.
18 +//
19 +// Only supports IUnknown.
20 +//
21 +// Program ID can be either program ID or application string.
22 +func CreateObject(programID string) (unknown *ole.IUnknown, err error) {
23 + classID, err := ClassIDFrom(programID)
24 + if err != nil {
25 + return
26 + }
27 +
28 + unknown, err = ole.CreateInstance(classID, ole.IID_IUnknown)
29 + if err != nil {
30 + return
31 + }
32 +
33 + return
34 +}
35 +
36 +// GetActiveObject retrieves active object for program ID and interface ID based
37 +// on interface type.
38 +//
39 +// Only supports IUnknown.
40 +//
41 +// Program ID can be either program ID or application string.
42 +func GetActiveObject(programID string) (unknown *ole.IUnknown, err error) {
43 + classID, err := ClassIDFrom(programID)
44 + if err != nil {
45 + return
46 + }
47 +
48 + unknown, err = ole.GetActiveObject(classID, ole.IID_IUnknown)
49 + if err != nil {
50 + return
51 + }
52 +
53 + return
54 +}
55 +
56 +// CallMethod calls method on IDispatch with parameters.
57 +func CallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
58 + var dispid []int32
59 + dispid, err = disp.GetIDsOfName([]string{name})
60 + if err != nil {
61 + return
62 + }
63 +
64 + if len(params) < 1 {
65 + result, err = disp.Invoke(dispid[0], ole.DISPATCH_METHOD)
66 + } else {
67 + result, err = disp.Invoke(dispid[0], ole.DISPATCH_METHOD, params...)
68 + }
69 +
70 + return
71 +}
72 +
73 +// MustCallMethod calls method on IDispatch with parameters or panics.
74 +func MustCallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
75 + r, err := CallMethod(disp, name, params...)
76 + if err != nil {
77 + panic(err.Error())
78 + }
79 + return r
80 +}
81 +
82 +// GetProperty retrieves property from IDispatch.
83 +func GetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
84 + var dispid []int32
85 + dispid, err = disp.GetIDsOfName([]string{name})
86 + if err != nil {
87 + return
88 + }
89 +
90 + if len(params) < 1 {
91 + result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYGET)
92 + } else {
93 + result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYGET, params...)
94 + }
95 +
96 + return
97 +}
98 +
99 +// MustGetProperty retrieves property from IDispatch or panics.
100 +func MustGetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
101 + r, err := GetProperty(disp, name, params...)
102 + if err != nil {
103 + panic(err.Error())
104 + }
105 + return r
106 +}
107 +
108 +// PutProperty mutates property.
109 +func PutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
110 + var dispid []int32
111 + dispid, err = disp.GetIDsOfName([]string{name})
112 + if err != nil {
113 + return
114 + }
115 +
116 + if len(params) < 1 {
117 + result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYPUT)
118 + } else {
119 + result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYPUT, params...)
120 + }
121 +
122 + return
123 +}
124 +
125 +// MustPutProperty mutates property or panics.
126 +func MustPutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
127 + r, err := PutProperty(disp, name, params...)
128 + if err != nil {
129 + panic(err.Error())
130 + }
131 + return r
132 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearray.go new
+27
@@ -0,0 +1,27 @@
1 +// Package is meant to retrieve and process safe array data returned from COM.
2 +
3 +package ole
4 +
5 +// SafeArrayBound defines the SafeArray boundaries.
6 +type SafeArrayBound struct {
7 + Elements uint32
8 + LowerBound int32
9 +}
10 +
11 +// SafeArray is how COM handles arrays.
12 +type SafeArray struct {
13 + Dimensions uint16
14 + FeaturesFlag uint16
15 + ElementsSize uint32
16 + LocksAmount uint32
17 + Data uint32
18 + Bounds [16]byte
19 +}
20 +
21 +// SAFEARRAY is obsolete, exists for backwards compatibility.
22 +// Use SafeArray
23 +type SAFEARRAY SafeArray
24 +
25 +// SAFEARRAYBOUND is obsolete, exists for backwards compatibility.
26 +// Use SafeArrayBound
27 +type SAFEARRAYBOUND SafeArrayBound
Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_func.go new
+207
@@ -0,0 +1,207 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +// safeArrayAccessData returns raw array pointer.
6 +//
7 +// AKA: SafeArrayAccessData in Windows API.
8 +func safeArrayAccessData(safearray *SafeArray) (uintptr, error) {
9 + return uintptr(0), NewError(E_NOTIMPL)
10 +}
11 +
12 +// safeArrayUnaccessData releases raw array.
13 +//
14 +// AKA: SafeArrayUnaccessData in Windows API.
15 +func safeArrayUnaccessData(safearray *SafeArray) error {
16 + return NewError(E_NOTIMPL)
17 +}
18 +
19 +// safeArrayAllocData allocates SafeArray.
20 +//
21 +// AKA: SafeArrayAllocData in Windows API.
22 +func safeArrayAllocData(safearray *SafeArray) error {
23 + return NewError(E_NOTIMPL)
24 +}
25 +
26 +// safeArrayAllocDescriptor allocates SafeArray.
27 +//
28 +// AKA: SafeArrayAllocDescriptor in Windows API.
29 +func safeArrayAllocDescriptor(dimensions uint32) (*SafeArray, error) {
30 + return nil, NewError(E_NOTIMPL)
31 +}
32 +
33 +// safeArrayAllocDescriptorEx allocates SafeArray.
34 +//
35 +// AKA: SafeArrayAllocDescriptorEx in Windows API.
36 +func safeArrayAllocDescriptorEx(variantType VT, dimensions uint32) (*SafeArray, error) {
37 + return nil, NewError(E_NOTIMPL)
38 +}
39 +
40 +// safeArrayCopy returns copy of SafeArray.
41 +//
42 +// AKA: SafeArrayCopy in Windows API.
43 +func safeArrayCopy(original *SafeArray) (*SafeArray, error) {
44 + return nil, NewError(E_NOTIMPL)
45 +}
46 +
47 +// safeArrayCopyData duplicates SafeArray into another SafeArray object.
48 +//
49 +// AKA: SafeArrayCopyData in Windows API.
50 +func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) error {
51 + return NewError(E_NOTIMPL)
52 +}
53 +
54 +// safeArrayCreate creates SafeArray.
55 +//
56 +// AKA: SafeArrayCreate in Windows API.
57 +func safeArrayCreate(variantType VT, dimensions uint32, bounds *SafeArrayBound) (*SafeArray, error) {
58 + return nil, NewError(E_NOTIMPL)
59 +}
60 +
61 +// safeArrayCreateEx creates SafeArray.
62 +//
63 +// AKA: SafeArrayCreateEx in Windows API.
64 +func safeArrayCreateEx(variantType VT, dimensions uint32, bounds *SafeArrayBound, extra uintptr) (*SafeArray, error) {
65 + return nil, NewError(E_NOTIMPL)
66 +}
67 +
68 +// safeArrayCreateVector creates SafeArray.
69 +//
70 +// AKA: SafeArrayCreateVector in Windows API.
71 +func safeArrayCreateVector(variantType VT, lowerBound int32, length uint32) (*SafeArray, error) {
72 + return nil, NewError(E_NOTIMPL)
73 +}
74 +
75 +// safeArrayCreateVectorEx creates SafeArray.
76 +//
77 +// AKA: SafeArrayCreateVectorEx in Windows API.
78 +func safeArrayCreateVectorEx(variantType VT, lowerBound int32, length uint32, extra uintptr) (*SafeArray, error) {
79 + return nil, NewError(E_NOTIMPL)
80 +}
81 +
82 +// safeArrayDestroy destroys SafeArray object.
83 +//
84 +// AKA: SafeArrayDestroy in Windows API.
85 +func safeArrayDestroy(safearray *SafeArray) error {
86 + return NewError(E_NOTIMPL)
87 +}
88 +
89 +// safeArrayDestroyData destroys SafeArray object.
90 +//
91 +// AKA: SafeArrayDestroyData in Windows API.
92 +func safeArrayDestroyData(safearray *SafeArray) error {
93 + return NewError(E_NOTIMPL)
94 +}
95 +
96 +// safeArrayDestroyDescriptor destroys SafeArray object.
97 +//
98 +// AKA: SafeArrayDestroyDescriptor in Windows API.
99 +func safeArrayDestroyDescriptor(safearray *SafeArray) error {
100 + return NewError(E_NOTIMPL)
101 +}
102 +
103 +// safeArrayGetDim is the amount of dimensions in the SafeArray.
104 +//
105 +// SafeArrays may have multiple dimensions. Meaning, it could be
106 +// multidimensional array.
107 +//
108 +// AKA: SafeArrayGetDim in Windows API.
109 +func safeArrayGetDim(safearray *SafeArray) (*uint32, error) {
110 + u := uint32(0)
111 + return &u, NewError(E_NOTIMPL)
112 +}
113 +
114 +// safeArrayGetElementSize is the element size in bytes.
115 +//
116 +// AKA: SafeArrayGetElemsize in Windows API.
117 +func safeArrayGetElementSize(safearray *SafeArray) (*uint32, error) {
118 + u := uint32(0)
119 + return &u, NewError(E_NOTIMPL)
120 +}
121 +
122 +// safeArrayGetElement retrieves element at given index.
123 +func safeArrayGetElement(safearray *SafeArray, index int64) (uintptr, error) {
124 + return uintptr(0), NewError(E_NOTIMPL)
125 +}
126 +
127 +// safeArrayGetElement retrieves element at given index and converts to string.
128 +func safeArrayGetElementString(safearray *SafeArray, index int64) (string, error) {
129 + return "", NewError(E_NOTIMPL)
130 +}
131 +
132 +// safeArrayGetIID is the InterfaceID of the elements in the SafeArray.
133 +//
134 +// AKA: SafeArrayGetIID in Windows API.
135 +func safeArrayGetIID(safearray *SafeArray) (*GUID, error) {
136 + return nil, NewError(E_NOTIMPL)
137 +}
138 +
139 +// safeArrayGetLBound returns lower bounds of SafeArray.
140 +//
141 +// SafeArrays may have multiple dimensions. Meaning, it could be
142 +// multidimensional array.
143 +//
144 +// AKA: SafeArrayGetLBound in Windows API.
145 +func safeArrayGetLBound(safearray *SafeArray, dimension uint32) (int64, error) {
146 + return int64(0), NewError(E_NOTIMPL)
147 +}
148 +
149 +// safeArrayGetUBound returns upper bounds of SafeArray.
150 +//
151 +// SafeArrays may have multiple dimensions. Meaning, it could be
152 +// multidimensional array.
153 +//
154 +// AKA: SafeArrayGetUBound in Windows API.
155 +func safeArrayGetUBound(safearray *SafeArray, dimension uint32) (int64, error) {
156 + return int64(0), NewError(E_NOTIMPL)
157 +}
158 +
159 +// safeArrayGetVartype returns data type of SafeArray.
160 +//
161 +// AKA: SafeArrayGetVartype in Windows API.
162 +func safeArrayGetVartype(safearray *SafeArray) (uint16, error) {
163 + return uint16(0), NewError(E_NOTIMPL)
164 +}
165 +
166 +// safeArrayLock locks SafeArray for reading to modify SafeArray.
167 +//
168 +// This must be called during some calls to ensure that another process does not
169 +// read or write to the SafeArray during editing.
170 +//
171 +// AKA: SafeArrayLock in Windows API.
172 +func safeArrayLock(safearray *SafeArray) error {
173 + return NewError(E_NOTIMPL)
174 +}
175 +
176 +// safeArrayUnlock unlocks SafeArray for reading.
177 +//
178 +// AKA: SafeArrayUnlock in Windows API.
179 +func safeArrayUnlock(safearray *SafeArray) error {
180 + return NewError(E_NOTIMPL)
181 +}
182 +
183 +// safeArrayPutElement stores the data element at the specified location in the
184 +// array.
185 +//
186 +// AKA: SafeArrayPutElement in Windows API.
187 +func safeArrayPutElement(safearray *SafeArray, index int64, element uintptr) error {
188 + return NewError(E_NOTIMPL)
189 +}
190 +
191 +// safeArrayGetRecordInfo accesses IRecordInfo info for custom types.
192 +//
193 +// AKA: SafeArrayGetRecordInfo in Windows API.
194 +//
195 +// XXX: Must implement IRecordInfo interface for this to return.
196 +func safeArrayGetRecordInfo(safearray *SafeArray) (interface{}, error) {
197 + return nil, NewError(E_NOTIMPL)
198 +}
199 +
200 +// safeArraySetRecordInfo mutates IRecordInfo info for custom types.
201 +//
202 +// AKA: SafeArraySetRecordInfo in Windows API.
203 +//
204 +// XXX: Must implement IRecordInfo interface for this to return.
205 +func safeArraySetRecordInfo(safearray *SafeArray, recordInfo interface{}) error {
206 + return NewError(E_NOTIMPL)
207 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_test.go new
+108
@@ -0,0 +1,108 @@
1 +package ole
2 +
3 +// This tests more than one function. It tests all of the functions needed in
4 +// order to retrieve an SafeArray populated with Strings.
5 +func Example_safeArrayGetElementString() {
6 + CoInitialize(0)
7 + defer CoUninitialize()
8 +
9 + clsid, err := CLSIDFromProgID("QBXMLRP2.RequestProcessor.1")
10 + if err != nil {
11 + if err.(*OleError).Code() == CO_E_CLASSSTRING {
12 + return
13 + }
14 + }
15 +
16 + unknown, err := CreateInstance(clsid, IID_IUnknown)
17 + if err != nil {
18 + return
19 + }
20 + defer unknown.Release()
21 +
22 + dispatch, err := unknown.QueryInterface(IID_IDispatch)
23 + if err != nil {
24 + return
25 + }
26 +
27 + var dispid []int32
28 + dispid, err = dispatch.GetIDsOfName([]string{"OpenConnection2"})
29 + if err != nil {
30 + return
31 + }
32 +
33 + var result *VARIANT
34 + _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", "Test Application 1", 1)
35 + if err != nil {
36 + return
37 + }
38 +
39 + dispid, err = dispatch.GetIDsOfName([]string{"BeginSession"})
40 + if err != nil {
41 + return
42 + }
43 +
44 + result, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", 2)
45 + if err != nil {
46 + return
47 + }
48 +
49 + ticket := result.ToString()
50 +
51 + dispid, err = dispatch.GetIDsOfName([]string{"QBXMLVersionsForSession"})
52 + if err != nil {
53 + return
54 + }
55 +
56 + result, err = dispatch.Invoke(dispid[0], DISPATCH_PROPERTYGET, ticket)
57 + if err != nil {
58 + return
59 + }
60 +
61 + // Where the real tests begin.
62 + var qbXMLVersions *SafeArray
63 + var qbXmlVersionStrings []string
64 + qbXMLVersions = result.ToArray().Array
65 +
66 + // Get array bounds
67 + var LowerBounds int64
68 + var UpperBounds int64
69 + LowerBounds, err = safeArrayGetLBound(qbXMLVersions, 1)
70 + if err != nil {
71 + return
72 + }
73 +
74 + UpperBounds, err = safeArrayGetUBound(qbXMLVersions, 1)
75 + if err != nil {
76 + return
77 + }
78 +
79 + totalElements := UpperBounds - LowerBounds + 1
80 + qbXmlVersionStrings = make([]string, totalElements)
81 +
82 + for i := int64(0); i < totalElements; i++ {
83 + qbXmlVersionStrings[int32(i)], _ = safeArrayGetElementString(qbXMLVersions, i)
84 + }
85 +
86 + // Release Safe Array memory
87 + safeArrayDestroy(qbXMLVersions)
88 +
89 + dispid, err = dispatch.GetIDsOfName([]string{"EndSession"})
90 + if err != nil {
91 + return
92 + }
93 +
94 + _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, ticket)
95 + if err != nil {
96 + return
97 + }
98 +
99 + dispid, err = dispatch.GetIDsOfName([]string{"CloseConnection"})
100 + if err != nil {
101 + return
102 + }
103 +
104 + _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD)
105 + if err != nil {
106 + return
107 + }
108 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_windows.go new
+338
@@ -0,0 +1,338 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "unsafe"
7 +)
8 +
9 +var (
10 + procSafeArrayAccessData, _ = modoleaut32.FindProc("SafeArrayAccessData")
11 + procSafeArrayAllocData, _ = modoleaut32.FindProc("SafeArrayAllocData")
12 + procSafeArrayAllocDescriptor, _ = modoleaut32.FindProc("SafeArrayAllocDescriptor")
13 + procSafeArrayAllocDescriptorEx, _ = modoleaut32.FindProc("SafeArrayAllocDescriptorEx")
14 + procSafeArrayCopy, _ = modoleaut32.FindProc("SafeArrayCopy")
15 + procSafeArrayCopyData, _ = modoleaut32.FindProc("SafeArrayCopyData")
16 + procSafeArrayCreate, _ = modoleaut32.FindProc("SafeArrayCreate")
17 + procSafeArrayCreateEx, _ = modoleaut32.FindProc("SafeArrayCreateEx")
18 + procSafeArrayCreateVector, _ = modoleaut32.FindProc("SafeArrayCreateVector")
19 + procSafeArrayCreateVectorEx, _ = modoleaut32.FindProc("SafeArrayCreateVectorEx")
20 + procSafeArrayDestroy, _ = modoleaut32.FindProc("SafeArrayDestroy")
21 + procSafeArrayDestroyData, _ = modoleaut32.FindProc("SafeArrayDestroyData")
22 + procSafeArrayDestroyDescriptor, _ = modoleaut32.FindProc("SafeArrayDestroyDescriptor")
23 + procSafeArrayGetDim, _ = modoleaut32.FindProc("SafeArrayGetDim")
24 + procSafeArrayGetElement, _ = modoleaut32.FindProc("SafeArrayGetElement")
25 + procSafeArrayGetElemsize, _ = modoleaut32.FindProc("SafeArrayGetElemsize")
26 + procSafeArrayGetIID, _ = modoleaut32.FindProc("SafeArrayGetIID")
27 + procSafeArrayGetLBound, _ = modoleaut32.FindProc("SafeArrayGetLBound")
28 + procSafeArrayGetUBound, _ = modoleaut32.FindProc("SafeArrayGetUBound")
29 + procSafeArrayGetVartype, _ = modoleaut32.FindProc("SafeArrayGetVartype")
30 + procSafeArrayLock, _ = modoleaut32.FindProc("SafeArrayLock")
31 + procSafeArrayPtrOfIndex, _ = modoleaut32.FindProc("SafeArrayPtrOfIndex")
32 + procSafeArrayUnaccessData, _ = modoleaut32.FindProc("SafeArrayUnaccessData")
33 + procSafeArrayUnlock, _ = modoleaut32.FindProc("SafeArrayUnlock")
34 + procSafeArrayPutElement, _ = modoleaut32.FindProc("SafeArrayPutElement")
35 + //procSafeArrayRedim, _ = modoleaut32.FindProc("SafeArrayRedim") // TODO
36 + //procSafeArraySetIID, _ = modoleaut32.FindProc("SafeArraySetIID") // TODO
37 + procSafeArrayGetRecordInfo, _ = modoleaut32.FindProc("SafeArrayGetRecordInfo")
38 + procSafeArraySetRecordInfo, _ = modoleaut32.FindProc("SafeArraySetRecordInfo")
39 +)
40 +
41 +// safeArrayAccessData returns raw array pointer.
42 +//
43 +// AKA: SafeArrayAccessData in Windows API.
44 +// Todo: Test
45 +func safeArrayAccessData(safearray *SafeArray) (element uintptr, err error) {
46 + err = convertHresultToError(
47 + procSafeArrayAccessData.Call(
48 + uintptr(unsafe.Pointer(safearray)),
49 + uintptr(unsafe.Pointer(&element))))
50 + return
51 +}
52 +
53 +// safeArrayUnaccessData releases raw array.
54 +//
55 +// AKA: SafeArrayUnaccessData in Windows API.
56 +func safeArrayUnaccessData(safearray *SafeArray) (err error) {
57 + err = convertHresultToError(procSafeArrayUnaccessData.Call(uintptr(unsafe.Pointer(safearray))))
58 + return
59 +}
60 +
61 +// safeArrayAllocData allocates SafeArray.
62 +//
63 +// AKA: SafeArrayAllocData in Windows API.
64 +func safeArrayAllocData(safearray *SafeArray) (err error) {
65 + err = convertHresultToError(procSafeArrayAllocData.Call(uintptr(unsafe.Pointer(safearray))))
66 + return
67 +}
68 +
69 +// safeArrayAllocDescriptor allocates SafeArray.
70 +//
71 +// AKA: SafeArrayAllocDescriptor in Windows API.
72 +func safeArrayAllocDescriptor(dimensions uint32) (safearray *SafeArray, err error) {
73 + err = convertHresultToError(
74 + procSafeArrayAllocDescriptor.Call(uintptr(dimensions), uintptr(unsafe.Pointer(&safearray))))
75 + return
76 +}
77 +
78 +// safeArrayAllocDescriptorEx allocates SafeArray.
79 +//
80 +// AKA: SafeArrayAllocDescriptorEx in Windows API.
81 +func safeArrayAllocDescriptorEx(variantType VT, dimensions uint32) (safearray *SafeArray, err error) {
82 + err = convertHresultToError(
83 + procSafeArrayAllocDescriptorEx.Call(
84 + uintptr(variantType),
85 + uintptr(dimensions),
86 + uintptr(unsafe.Pointer(&safearray))))
87 + return
88 +}
89 +
90 +// safeArrayCopy returns copy of SafeArray.
91 +//
92 +// AKA: SafeArrayCopy in Windows API.
93 +func safeArrayCopy(original *SafeArray) (safearray *SafeArray, err error) {
94 + err = convertHresultToError(
95 + procSafeArrayCopy.Call(
96 + uintptr(unsafe.Pointer(original)),
97 + uintptr(unsafe.Pointer(&safearray))))
98 + return
99 +}
100 +
101 +// safeArrayCopyData duplicates SafeArray into another SafeArray object.
102 +//
103 +// AKA: SafeArrayCopyData in Windows API.
104 +func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) (err error) {
105 + err = convertHresultToError(
106 + procSafeArrayCopyData.Call(
107 + uintptr(unsafe.Pointer(original)),
108 + uintptr(unsafe.Pointer(duplicate))))
109 + return
110 +}
111 +
112 +// safeArrayCreate creates SafeArray.
113 +//
114 +// AKA: SafeArrayCreate in Windows API.
115 +func safeArrayCreate(variantType VT, dimensions uint32, bounds *SafeArrayBound) (safearray *SafeArray, err error) {
116 + sa, _, err := procSafeArrayCreate.Call(
117 + uintptr(variantType),
118 + uintptr(dimensions),
119 + uintptr(unsafe.Pointer(bounds)))
120 + safearray = (*SafeArray)(unsafe.Pointer(&sa))
121 + return
122 +}
123 +
124 +// safeArrayCreateEx creates SafeArray.
125 +//
126 +// AKA: SafeArrayCreateEx in Windows API.
127 +func safeArrayCreateEx(variantType VT, dimensions uint32, bounds *SafeArrayBound, extra uintptr) (safearray *SafeArray, err error) {
128 + sa, _, err := procSafeArrayCreateEx.Call(
129 + uintptr(variantType),
130 + uintptr(dimensions),
131 + uintptr(unsafe.Pointer(bounds)),
132 + extra)
133 + safearray = (*SafeArray)(unsafe.Pointer(sa))
134 + return
135 +}
136 +
137 +// safeArrayCreateVector creates SafeArray.
138 +//
139 +// AKA: SafeArrayCreateVector in Windows API.
140 +func safeArrayCreateVector(variantType VT, lowerBound int32, length uint32) (safearray *SafeArray, err error) {
141 + sa, _, err := procSafeArrayCreateVector.Call(
142 + uintptr(variantType),
143 + uintptr(lowerBound),
144 + uintptr(length))
145 + safearray = (*SafeArray)(unsafe.Pointer(sa))
146 + return
147 +}
148 +
149 +// safeArrayCreateVectorEx creates SafeArray.
150 +//
151 +// AKA: SafeArrayCreateVectorEx in Windows API.
152 +func safeArrayCreateVectorEx(variantType VT, lowerBound int32, length uint32, extra uintptr) (safearray *SafeArray, err error) {
153 + sa, _, err := procSafeArrayCreateVectorEx.Call(
154 + uintptr(variantType),
155 + uintptr(lowerBound),
156 + uintptr(length),
157 + extra)
158 + safearray = (*SafeArray)(unsafe.Pointer(sa))
159 + return
160 +}
161 +
162 +// safeArrayDestroy destroys SafeArray object.
163 +//
164 +// AKA: SafeArrayDestroy in Windows API.
165 +func safeArrayDestroy(safearray *SafeArray) (err error) {
166 + err = convertHresultToError(procSafeArrayDestroy.Call(uintptr(unsafe.Pointer(safearray))))
167 + return
168 +}
169 +
170 +// safeArrayDestroyData destroys SafeArray object.
171 +//
172 +// AKA: SafeArrayDestroyData in Windows API.
173 +func safeArrayDestroyData(safearray *SafeArray) (err error) {
174 + err = convertHresultToError(procSafeArrayDestroyData.Call(uintptr(unsafe.Pointer(safearray))))
175 + return
176 +}
177 +
178 +// safeArrayDestroyDescriptor destroys SafeArray object.
179 +//
180 +// AKA: SafeArrayDestroyDescriptor in Windows API.
181 +func safeArrayDestroyDescriptor(safearray *SafeArray) (err error) {
182 + err = convertHresultToError(procSafeArrayDestroyDescriptor.Call(uintptr(unsafe.Pointer(safearray))))
183 + return
184 +}
185 +
186 +// safeArrayGetDim is the amount of dimensions in the SafeArray.
187 +//
188 +// SafeArrays may have multiple dimensions. Meaning, it could be
189 +// multidimensional array.
190 +//
191 +// AKA: SafeArrayGetDim in Windows API.
192 +func safeArrayGetDim(safearray *SafeArray) (dimensions *uint32, err error) {
193 + l, _, err := procSafeArrayGetDim.Call(uintptr(unsafe.Pointer(safearray)))
194 + dimensions = (*uint32)(unsafe.Pointer(l))
195 + return
196 +}
197 +
198 +// safeArrayGetElementSize is the element size in bytes.
199 +//
200 +// AKA: SafeArrayGetElemsize in Windows API.
201 +func safeArrayGetElementSize(safearray *SafeArray) (length *uint32, err error) {
202 + l, _, err := procSafeArrayGetElemsize.Call(uintptr(unsafe.Pointer(safearray)))
203 + length = (*uint32)(unsafe.Pointer(l))
204 + return
205 +}
206 +
207 +// safeArrayGetElement retrieves element at given index.
208 +func safeArrayGetElement(safearray *SafeArray, index int64) (element uintptr, err error) {
209 + err = convertHresultToError(
210 + procSafeArrayGetElement.Call(
211 + uintptr(unsafe.Pointer(safearray)),
212 + uintptr(unsafe.Pointer(&index)),
213 + uintptr(unsafe.Pointer(&element))))
214 + return
215 +}
216 +
217 +// safeArrayGetElement retrieves element at given index and converts to string.
218 +func safeArrayGetElementString(safearray *SafeArray, index int64) (str string, err error) {
219 + var element *int16
220 + err = convertHresultToError(
221 + procSafeArrayGetElement.Call(
222 + uintptr(unsafe.Pointer(safearray)),
223 + uintptr(unsafe.Pointer(&index)),
224 + uintptr(unsafe.Pointer(&element))))
225 + str = BstrToString(*(**uint16)(unsafe.Pointer(&element)))
226 + SysFreeString(element)
227 + return
228 +}
229 +
230 +// safeArrayGetIID is the InterfaceID of the elements in the SafeArray.
231 +//
232 +// AKA: SafeArrayGetIID in Windows API.
233 +func safeArrayGetIID(safearray *SafeArray) (guid *GUID, err error) {
234 + err = convertHresultToError(
235 + procSafeArrayGetIID.Call(
236 + uintptr(unsafe.Pointer(safearray)),
237 + uintptr(unsafe.Pointer(&guid))))
238 + return
239 +}
240 +
241 +// safeArrayGetLBound returns lower bounds of SafeArray.
242 +//
243 +// SafeArrays may have multiple dimensions. Meaning, it could be
244 +// multidimensional array.
245 +//
246 +// AKA: SafeArrayGetLBound in Windows API.
247 +func safeArrayGetLBound(safearray *SafeArray, dimension uint32) (lowerBound int64, err error) {
248 + err = convertHresultToError(
249 + procSafeArrayGetLBound.Call(
250 + uintptr(unsafe.Pointer(safearray)),
251 + uintptr(dimension),
252 + uintptr(unsafe.Pointer(&lowerBound))))
253 + return
254 +}
255 +
256 +// safeArrayGetUBound returns upper bounds of SafeArray.
257 +//
258 +// SafeArrays may have multiple dimensions. Meaning, it could be
259 +// multidimensional array.
260 +//
261 +// AKA: SafeArrayGetUBound in Windows API.
262 +func safeArrayGetUBound(safearray *SafeArray, dimension uint32) (upperBound int64, err error) {
263 + err = convertHresultToError(
264 + procSafeArrayGetUBound.Call(
265 + uintptr(unsafe.Pointer(safearray)),
266 + uintptr(dimension),
267 + uintptr(unsafe.Pointer(&upperBound))))
268 + return
269 +}
270 +
271 +// safeArrayGetVartype returns data type of SafeArray.
272 +//
273 +// AKA: SafeArrayGetVartype in Windows API.
274 +func safeArrayGetVartype(safearray *SafeArray) (varType uint16, err error) {
275 + err = convertHresultToError(
276 + procSafeArrayGetVartype.Call(
277 + uintptr(unsafe.Pointer(safearray)),
278 + uintptr(unsafe.Pointer(&varType))))
279 + return
280 +}
281 +
282 +// safeArrayLock locks SafeArray for reading to modify SafeArray.
283 +//
284 +// This must be called during some calls to ensure that another process does not
285 +// read or write to the SafeArray during editing.
286 +//
287 +// AKA: SafeArrayLock in Windows API.
288 +func safeArrayLock(safearray *SafeArray) (err error) {
289 + err = convertHresultToError(procSafeArrayLock.Call(uintptr(unsafe.Pointer(safearray))))
290 + return
291 +}
292 +
293 +// safeArrayUnlock unlocks SafeArray for reading.
294 +//
295 +// AKA: SafeArrayUnlock in Windows API.
296 +func safeArrayUnlock(safearray *SafeArray) (err error) {
297 + err = convertHresultToError(procSafeArrayUnlock.Call(uintptr(unsafe.Pointer(safearray))))
298 + return
299 +}
300 +
301 +// safeArrayPutElement stores the data element at the specified location in the
302 +// array.
303 +//
304 +// AKA: SafeArrayPutElement in Windows API.
305 +func safeArrayPutElement(safearray *SafeArray, index int64, element uintptr) (err error) {
306 + err = convertHresultToError(
307 + procSafeArrayPutElement.Call(
308 + uintptr(unsafe.Pointer(safearray)),
309 + uintptr(unsafe.Pointer(&index)),
310 + uintptr(unsafe.Pointer(element))))
311 + return
312 +}
313 +
314 +// safeArrayGetRecordInfo accesses IRecordInfo info for custom types.
315 +//
316 +// AKA: SafeArrayGetRecordInfo in Windows API.
317 +//
318 +// XXX: Must implement IRecordInfo interface for this to return.
319 +func safeArrayGetRecordInfo(safearray *SafeArray) (recordInfo interface{}, err error) {
320 + err = convertHresultToError(
321 + procSafeArrayGetRecordInfo.Call(
322 + uintptr(unsafe.Pointer(safearray)),
323 + uintptr(unsafe.Pointer(&recordInfo))))
324 + return
325 +}
326 +
327 +// safeArraySetRecordInfo mutates IRecordInfo info for custom types.
328 +//
329 +// AKA: SafeArraySetRecordInfo in Windows API.
330 +//
331 +// XXX: Must implement IRecordInfo interface for this to return.
332 +func safeArraySetRecordInfo(safearray *SafeArray, recordInfo interface{}) (err error) {
333 + err = convertHresultToError(
334 + procSafeArraySetRecordInfo.Call(
335 + uintptr(unsafe.Pointer(safearray)),
336 + uintptr(unsafe.Pointer(&recordInfo))))
337 + return
338 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayconversion.go new
+72
@@ -0,0 +1,72 @@
1 +// Helper for converting SafeArray to array of objects.
2 +
3 +package ole
4 +
5 +import "unsafe"
6 +
7 +type SafeArrayConversion struct {
8 + Array *SafeArray
9 +}
10 +
11 +func (sac *SafeArrayConversion) ToStringArray() (strings []string) {
12 + totalElements, _ := sac.TotalElements(0)
13 + strings = make([]string, totalElements)
14 +
15 + for i := int64(0); i < totalElements; i++ {
16 + strings[int32(i)], _ = safeArrayGetElementString(sac.Array, i)
17 + }
18 +
19 + return
20 +}
21 +
22 +func (sac *SafeArrayConversion) ToByteArray() (bytes []byte) {
23 + totalElements, _ := sac.TotalElements(0)
24 + bytes = make([]byte, totalElements)
25 +
26 + for i := int64(0); i < totalElements; i++ {
27 + ptr, _ := safeArrayGetElement(sac.Array, i)
28 + bytes[int32(i)] = *(*byte)(unsafe.Pointer(&ptr))
29 + }
30 +
31 + return
32 +}
33 +
34 +func (sac *SafeArrayConversion) GetType() (varType uint16, err error) {
35 + return safeArrayGetVartype(sac.Array)
36 +}
37 +
38 +func (sac *SafeArrayConversion) GetDimensions() (dimensions *uint32, err error) {
39 + return safeArrayGetDim(sac.Array)
40 +}
41 +
42 +func (sac *SafeArrayConversion) GetSize() (length *uint32, err error) {
43 + return safeArrayGetElementSize(sac.Array)
44 +}
45 +
46 +func (sac *SafeArrayConversion) TotalElements(index uint32) (totalElements int64, err error) {
47 + if index < 1 {
48 + index = 1
49 + }
50 +
51 + // Get array bounds
52 + var LowerBounds int64
53 + var UpperBounds int64
54 +
55 + LowerBounds, err = safeArrayGetLBound(sac.Array, index)
56 + if err != nil {
57 + return
58 + }
59 +
60 + UpperBounds, err = safeArrayGetUBound(sac.Array, index)
61 + if err != nil {
62 + return
63 + }
64 +
65 + totalElements = UpperBounds - LowerBounds + 1
66 + return
67 +}
68 +
69 +// Release Safe Array memory
70 +func (sac *SafeArrayConversion) Release() {
71 + safeArrayDestroy(sac.Array)
72 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayconversion_test.go new
+119
@@ -0,0 +1,119 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "fmt"
7 + "strings"
8 + "testing"
9 +)
10 +
11 +// This tests more than one function. It tests all of the functions needed in order to retrieve an
12 +// SafeArray populated with Strings.
13 +func TestSafeArrayConversionString(t *testing.T) {
14 + CoInitialize(0)
15 + defer CoUninitialize()
16 +
17 + clsid, err := CLSIDFromProgID("QBXMLRP2.RequestProcessor.1")
18 + if err != nil {
19 + if err.(*OleError).Code() == CO_E_CLASSSTRING {
20 + return
21 + }
22 + t.Log(err)
23 + t.FailNow()
24 + }
25 +
26 + unknown, err := CreateInstance(clsid, IID_IUnknown)
27 + if err != nil {
28 + t.Log(err)
29 + t.FailNow()
30 + }
31 + defer unknown.Release()
32 +
33 + dispatch, err := unknown.QueryInterface(IID_IDispatch)
34 + if err != nil {
35 + t.Log(err)
36 + t.FailNow()
37 + }
38 +
39 + var dispid []int32
40 + dispid, err = dispatch.GetIDsOfName([]string{"OpenConnection2"})
41 + if err != nil {
42 + t.Log(err)
43 + t.FailNow()
44 + }
45 +
46 + var result *VARIANT
47 + _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", "Test Application 1", 1)
48 + if err != nil {
49 + t.Log(err)
50 + t.FailNow()
51 + }
52 +
53 + dispid, err = dispatch.GetIDsOfName([]string{"BeginSession"})
54 + if err != nil {
55 + t.Log(err)
56 + t.FailNow()
57 + }
58 +
59 + result, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", 2)
60 + if err != nil {
61 + t.Log(err)
62 + t.FailNow()
63 + }
64 +
65 + ticket := result.ToString()
66 +
67 + dispid, err = dispatch.GetIDsOfName([]string{"QBXMLVersionsForSession"})
68 + if err != nil {
69 + t.Log(err)
70 + t.FailNow()
71 + }
72 +
73 + result, err = dispatch.Invoke(dispid[0], DISPATCH_PROPERTYGET, ticket)
74 + if err != nil {
75 + t.Log(err)
76 + t.FailNow()
77 + }
78 +
79 + // Where the real tests begin.
80 + conversion := result.ToArray()
81 +
82 + totalElements, _ := conversion.TotalElements(0)
83 + if totalElements != 13 {
84 + t.Log(fmt.Sprintf("%d total elements does not equal 13\n", totalElements))
85 + t.Fail()
86 + }
87 +
88 + versions := conversion.ToStringArray()
89 + if len(versions) != 13 {
90 + t.Log(fmt.Sprintf("%s\n", strings.Join(versions, ", ")))
91 + t.Fail()
92 + }
93 +
94 + conversion.Release()
95 +
96 + dispid, err = dispatch.GetIDsOfName([]string{"EndSession"})
97 + if err != nil {
98 + t.Log(err)
99 + t.FailNow()
100 + }
101 +
102 + _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, ticket)
103 + if err != nil {
104 + t.Log(err)
105 + t.FailNow()
106 + }
107 +
108 + dispid, err = dispatch.GetIDsOfName([]string{"CloseConnection"})
109 + if err != nil {
110 + t.Log(err)
111 + t.FailNow()
112 + }
113 +
114 + _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD)
115 + if err != nil {
116 + t.Log(err)
117 + t.FailNow()
118 + }
119 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayslices.go new
+33
@@ -0,0 +1,33 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "unsafe"
7 +)
8 +
9 +func safeArrayFromByteSlice(slice []byte) *SafeArray {
10 + array, _ := safeArrayCreateVector(VT_UI1, 0, uint32(len(slice)))
11 +
12 + if array == nil {
13 + panic("Could not convert []byte to SAFEARRAY")
14 + }
15 +
16 + for i, v := range slice {
17 + safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(&v)))
18 + }
19 + return array
20 +}
21 +
22 +func safeArrayFromStringSlice(slice []string) *SafeArray {
23 + array, _ := safeArrayCreateVector(VT_BSTR, 0, uint32(len(slice)))
24 +
25 + if array == nil {
26 + panic("Could not convert []string to SAFEARRAY")
27 + }
28 + // SysAllocStringLen(s)
29 + for i, v := range slice {
30 + safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(SysAllocStringLen(v))))
31 + }
32 + return array
33 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/utility.go new
+85
@@ -0,0 +1,85 @@
1 +package ole
2 +
3 +import (
4 + "unicode/utf16"
5 + "unsafe"
6 +)
7 +
8 +// BytePtrToString converts byte pointer to a Go string.
9 +func BytePtrToString(p *byte) string {
10 + a := (*[10000]uint8)(unsafe.Pointer(p))
11 + i := 0
12 + for a[i] != 0 {
13 + i++
14 + }
15 + return string(a[:i])
16 +}
17 +
18 +// UTF16PtrToString is alias for LpOleStrToString.
19 +//
20 +// Kept for compatibility reasons.
21 +func UTF16PtrToString(p *uint16) string {
22 + return LpOleStrToString(p)
23 +}
24 +
25 +// LpOleStrToString converts COM Unicode to Go string.
26 +func LpOleStrToString(p *uint16) string {
27 + if p == nil {
28 + return ""
29 + }
30 +
31 + length := lpOleStrLen(p)
32 + a := make([]uint16, length)
33 +
34 + ptr := unsafe.Pointer(p)
35 +
36 + for i := 0; i < int(length); i++ {
37 + a[i] = *(*uint16)(ptr)
38 + ptr = unsafe.Pointer(uintptr(ptr) + 2)
39 + }
40 +
41 + return string(utf16.Decode(a))
42 +}
43 +
44 +// BstrToString converts COM binary string to Go string.
45 +func BstrToString(p *uint16) string {
46 + if p == nil {
47 + return ""
48 + }
49 + length := SysStringLen((*int16)(unsafe.Pointer(p)))
50 + a := make([]uint16, length)
51 +
52 + ptr := unsafe.Pointer(p)
53 +
54 + for i := 0; i < int(length); i++ {
55 + a[i] = *(*uint16)(ptr)
56 + ptr = unsafe.Pointer(uintptr(ptr) + 2)
57 + }
58 + return string(utf16.Decode(a))
59 +}
60 +
61 +// lpOleStrLen returns the length of Unicode string.
62 +func lpOleStrLen(p *uint16) (length int64) {
63 + if p == nil {
64 + return 0
65 + }
66 +
67 + ptr := unsafe.Pointer(p)
68 +
69 + for i := 0; ; i++ {
70 + if 0 == *(*uint16)(ptr) {
71 + length = int64(i)
72 + break
73 + }
74 + ptr = unsafe.Pointer(uintptr(ptr) + 2)
75 + }
76 + return
77 +}
78 +
79 +// convertHresultToError converts syscall to error, if call is unsuccessful.
80 +func convertHresultToError(hr uintptr, r2 uintptr, ignore error) (err error) {
81 + if hr != 0 {
82 + err = NewError(hr)
83 + }
84 + return
85 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/variables.go new
+16
@@ -0,0 +1,16 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "syscall"
7 +)
8 +
9 +var (
10 + modcombase = syscall.NewLazyDLL("combase.dll")
11 + modkernel32, _ = syscall.LoadDLL("kernel32.dll")
12 + modole32, _ = syscall.LoadDLL("ole32.dll")
13 + modoleaut32, _ = syscall.LoadDLL("oleaut32.dll")
14 + modmsvcrt, _ = syscall.LoadDLL("msvcrt.dll")
15 + moduser32, _ = syscall.LoadDLL("user32.dll")
16 +)
Godeps/_workspace/src/github.com/go-ole/go-ole/variant.go new
+101
@@ -0,0 +1,101 @@
1 +package ole
2 +
3 +import "unsafe"
4 +
5 +// NewVariant returns new variant based on type and value.
6 +func NewVariant(vt VT, val int64) VARIANT {
7 + return VARIANT{VT: vt, Val: val}
8 +}
9 +
10 +// ToIUnknown converts Variant to Unknown object.
11 +func (v *VARIANT) ToIUnknown() *IUnknown {
12 + if v.VT != VT_UNKNOWN {
13 + return nil
14 + }
15 + return (*IUnknown)(unsafe.Pointer(uintptr(v.Val)))
16 +}
17 +
18 +// ToIDispatch converts variant to dispatch object.
19 +func (v *VARIANT) ToIDispatch() *IDispatch {
20 + if v.VT != VT_DISPATCH {
21 + return nil
22 + }
23 + return (*IDispatch)(unsafe.Pointer(uintptr(v.Val)))
24 +}
25 +
26 +// ToArray converts variant to SafeArray helper.
27 +func (v *VARIANT) ToArray() *SafeArrayConversion {
28 + if v.VT != VT_SAFEARRAY {
29 + return nil
30 + }
31 + var safeArray *SafeArray = (*SafeArray)(unsafe.Pointer(uintptr(v.Val)))
32 + return &SafeArrayConversion{safeArray}
33 +}
34 +
35 +// ToString converts variant to Go string.
36 +func (v *VARIANT) ToString() string {
37 + if v.VT != VT_BSTR {
38 + return ""
39 + }
40 + return BstrToString(*(**uint16)(unsafe.Pointer(&v.Val)))
41 +}
42 +
43 +// Clear the memory of variant object.
44 +func (v *VARIANT) Clear() error {
45 + return VariantClear(v)
46 +}
47 +
48 +// Value returns variant value based on its type.
49 +//
50 +// Currently supported types: 2- and 4-byte integers, strings, bools.
51 +// Note that 64-bit integers, datetimes, and other types are stored as strings
52 +// and will be returned as strings.
53 +//
54 +// Needs to be further converted, because this returns an interface{}.
55 +func (v *VARIANT) Value() interface{} {
56 + switch v.VT {
57 + case VT_I1:
58 + return int8(v.Val)
59 + case VT_UI1:
60 + return uint8(v.Val)
61 + case VT_I2:
62 + return int16(v.Val)
63 + case VT_UI2:
64 + return uint16(v.Val)
65 + case VT_I4:
66 + return int32(v.Val)
67 + case VT_UINT:
68 + return uint32(v.Val)
69 + case VT_INT_PTR:
70 + return uintptr(v.Val) // TODO
71 + case VT_UINT_PTR:
72 + return uintptr(v.Val)
73 + case VT_UI4:
74 + return uint32(v.Val)
75 + case VT_I8:
76 + return int64(v.Val)
77 + case VT_UI8:
78 + return uint64(v.Val)
79 + case VT_R4:
80 + return float32(v.Val)
81 + case VT_R8:
82 + return float64(v.Val)
83 + case VT_BSTR:
84 + return v.ToString()
85 + case VT_DATE:
86 + // VT_DATE type will either return float64 or time.Time.
87 + d := float64(v.Val)
88 + date, err := GetVariantDate(d)
89 + if err != nil {
90 + return d
91 + }
92 + return date
93 + case VT_UNKNOWN:
94 + return v.ToIUnknown()
95 + case VT_DISPATCH:
96 + return v.ToIDispatch()
97 + case VT_BOOL:
98 + return v.Val != 0
99 + }
100 + return nil
101 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/variant_386.go new
+11
@@ -0,0 +1,11 @@
1 +// +build 386
2 +
3 +package ole
4 +
5 +type VARIANT struct {
6 + VT VT // 2
7 + wReserved1 uint16 // 4
8 + wReserved2 uint16 // 6
9 + wReserved3 uint16 // 8
10 + Val int64 // 16
11 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/variant_amd64.go new
+12
@@ -0,0 +1,12 @@
1 +// +build amd64
2 +
3 +package ole
4 +
5 +type VARIANT struct {
6 + VT VT // 2
7 + wReserved1 uint16 // 4
8 + wReserved2 uint16 // 6
9 + wReserved3 uint16 // 8
10 + Val int64 // 16
11 + _ [8]byte // 24
12 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/vt_string.go new
+58
@@ -0,0 +1,58 @@
1 +// generated by stringer -output vt_string.go -type VT; DO NOT EDIT
2 +
3 +package ole
4 +
5 +import "fmt"
6 +
7 +const (
8 + _VT_name_0 = "VT_EMPTYVT_NULLVT_I2VT_I4VT_R4VT_R8VT_CYVT_DATEVT_BSTRVT_DISPATCHVT_ERRORVT_BOOLVT_VARIANTVT_UNKNOWNVT_DECIMAL"
9 + _VT_name_1 = "VT_I1VT_UI1VT_UI2VT_UI4VT_I8VT_UI8VT_INTVT_UINTVT_VOIDVT_HRESULTVT_PTRVT_SAFEARRAYVT_CARRAYVT_USERDEFINEDVT_LPSTRVT_LPWSTR"
10 + _VT_name_2 = "VT_RECORDVT_INT_PTRVT_UINT_PTR"
11 + _VT_name_3 = "VT_FILETIMEVT_BLOBVT_STREAMVT_STORAGEVT_STREAMED_OBJECTVT_STORED_OBJECTVT_BLOB_OBJECTVT_CFVT_CLSID"
12 + _VT_name_4 = "VT_BSTR_BLOBVT_VECTOR"
13 + _VT_name_5 = "VT_ARRAY"
14 + _VT_name_6 = "VT_BYREF"
15 + _VT_name_7 = "VT_RESERVED"
16 + _VT_name_8 = "VT_ILLEGAL"
17 +)
18 +
19 +var (
20 + _VT_index_0 = [...]uint8{0, 8, 15, 20, 25, 30, 35, 40, 47, 54, 65, 73, 80, 90, 100, 110}
21 + _VT_index_1 = [...]uint8{0, 5, 11, 17, 23, 28, 34, 40, 47, 54, 64, 70, 82, 91, 105, 113, 122}
22 + _VT_index_2 = [...]uint8{0, 9, 19, 30}
23 + _VT_index_3 = [...]uint8{0, 11, 18, 27, 37, 55, 71, 85, 90, 98}
24 + _VT_index_4 = [...]uint8{0, 12, 21}
25 + _VT_index_5 = [...]uint8{0, 8}
26 + _VT_index_6 = [...]uint8{0, 8}
27 + _VT_index_7 = [...]uint8{0, 11}
28 + _VT_index_8 = [...]uint8{0, 10}
29 +)
30 +
31 +func (i VT) String() string {
32 + switch {
33 + case 0 <= i && i <= 14:
34 + return _VT_name_0[_VT_index_0[i]:_VT_index_0[i+1]]
35 + case 16 <= i && i <= 31:
36 + i -= 16
37 + return _VT_name_1[_VT_index_1[i]:_VT_index_1[i+1]]
38 + case 36 <= i && i <= 38:
39 + i -= 36
40 + return _VT_name_2[_VT_index_2[i]:_VT_index_2[i+1]]
41 + case 64 <= i && i <= 72:
42 + i -= 64
43 + return _VT_name_3[_VT_index_3[i]:_VT_index_3[i+1]]
44 + case 4095 <= i && i <= 4096:
45 + i -= 4095
46 + return _VT_name_4[_VT_index_4[i]:_VT_index_4[i+1]]
47 + case i == 8192:
48 + return _VT_name_5
49 + case i == 16384:
50 + return _VT_name_6
51 + case i == 32768:
52 + return _VT_name_7
53 + case i == 65535:
54 + return _VT_name_8
55 + default:
56 + return fmt.Sprintf("VT(%d)", i)
57 + }
58 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/winrt.go new
+99
@@ -0,0 +1,99 @@
1 +// +build windows
2 +
3 +package ole
4 +
5 +import (
6 + "reflect"
7 + "syscall"
8 + "unicode/utf8"
9 + "unsafe"
10 +)
11 +
12 +var (
13 + procRoInitialize = modcombase.NewProc("RoInitialize")
14 + procRoActivateInstance = modcombase.NewProc("RoActivateInstance")
15 + procRoGetActivationFactory = modcombase.NewProc("RoGetActivationFactory")
16 + procWindowsCreateString = modcombase.NewProc("WindowsCreateString")
17 + procWindowsDeleteString = modcombase.NewProc("WindowsDeleteString")
18 + procWindowsGetStringRawBuffer = modcombase.NewProc("WindowsGetStringRawBuffer")
19 +)
20 +
21 +func RoInitialize(thread_type uint32) (err error) {
22 + hr, _, _ := procRoInitialize.Call(uintptr(thread_type))
23 + if hr != 0 {
24 + err = NewError(hr)
25 + }
26 + return
27 +}
28 +
29 +func RoActivateInstance(clsid string) (ins *IInspectable, err error) {
30 + hClsid, err := NewHString(clsid)
31 + if err != nil {
32 + return nil, err
33 + }
34 + defer DeleteHString(hClsid)
35 +
36 + hr, _, _ := procRoActivateInstance.Call(
37 + uintptr(unsafe.Pointer(hClsid)),
38 + uintptr(unsafe.Pointer(&ins)))
39 + if hr != 0 {
40 + err = NewError(hr)
41 + }
42 + return
43 +}
44 +
45 +func RoGetActivationFactory(clsid string, iid *GUID) (ins *IInspectable, err error) {
46 + hClsid, err := NewHString(clsid)
47 + if err != nil {
48 + return nil, err
49 + }
50 + defer DeleteHString(hClsid)
51 +
52 + hr, _, _ := procRoGetActivationFactory.Call(
53 + uintptr(unsafe.Pointer(hClsid)),
54 + uintptr(unsafe.Pointer(iid)),
55 + uintptr(unsafe.Pointer(&ins)))
56 + if hr != 0 {
57 + err = NewError(hr)
58 + }
59 + return
60 +}
61 +
62 +// HString is handle string for pointers.
63 +type HString uintptr
64 +
65 +// NewHString returns a new HString for Go string.
66 +func NewHString(s string) (hstring HString, err error) {
67 + u16 := syscall.StringToUTF16Ptr(s)
68 + len := uint32(utf8.RuneCountInString(s))
69 + hr, _, _ := procWindowsCreateString.Call(
70 + uintptr(unsafe.Pointer(u16)),
71 + uintptr(len),
72 + uintptr(unsafe.Pointer(&hstring)))
73 + if hr != 0 {
74 + err = NewError(hr)
75 + }
76 + return
77 +}
78 +
79 +// DeleteHString deletes HString.
80 +func DeleteHString(hstring HString) (err error) {
81 + hr, _, _ := procWindowsDeleteString.Call(uintptr(hstring))
82 + if hr != 0 {
83 + err = NewError(hr)
84 + }
85 + return
86 +}
87 +
88 +// String returns Go string value of HString.
89 +func (h HString) String() string {
90 + var u16buf uintptr
91 + var u16len uint32
92 + u16buf, _, _ = procWindowsGetStringRawBuffer.Call(
93 + uintptr(h),
94 + uintptr(unsafe.Pointer(&u16len)))
95 +
96 + u16hdr := reflect.SliceHeader{Data: u16buf, Len: int(u16len), Cap: int(u16len)}
97 + u16 := *(*[]uint16)(unsafe.Pointer(&u16hdr))
98 + return syscall.UTF16ToString(u16)
99 +}
Godeps/_workspace/src/github.com/go-ole/go-ole/winrt_doc.go new
+36
@@ -0,0 +1,36 @@
1 +// +build !windows
2 +
3 +package ole
4 +
5 +// RoInitialize
6 +func RoInitialize(thread_type uint32) (err error) {
7 + return NewError(E_NOTIMPL)
8 +}
9 +
10 +// RoActivateInstance
11 +func RoActivateInstance(clsid string) (ins *IInspectable, err error) {
12 + return nil, NewError(E_NOTIMPL)
13 +}
14 +
15 +// RoGetActivationFactory
16 +func RoGetActivationFactory(clsid string, iid *GUID) (ins *IInspectable, err error) {
17 + return nil, NewError(E_NOTIMPL)
18 +}
19 +
20 +// HString is handle string for pointers.
21 +type HString uintptr
22 +
23 +// NewHString returns a new HString for Go string.
24 +func NewHString(s string) (hstring HString, err error) {
25 + return HString(uintptr(0)), NewError(E_NOTIMPL)
26 +}
27 +
28 +// DeleteHString deletes HString.
29 +func DeleteHString(hstring HString) (err error) {
30 + return NewError(E_NOTIMPL)
31 +}
32 +
33 +// String returns Go string value of HString.
34 +func (h HString) String() string {
35 + return ""
36 +}
Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_windows.go
+1 -1
@@ -7,7 +7,7 @@ import (
7 "syscall"
8 "unsafe"
9
10 - "github.com/StackExchange/wmi"
10 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/StackExchange/wmi"
11
12 common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common"
13 )
util/sadhack/godep.go
+4
@@ -7,3 +7,7 @@ import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/dustin/go-hum
7 // imported by chegga/pb on windows, this is here so running godeps on non-windows doesnt
8 // drop it from our vendoring
9 import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/olekukonko/ts"
10 +
11 +// these two are for diagnostics on windows systems
12 +import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/StackExchange/wmi"
13 +import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"