aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-ole/go-ole/ole.go
blob: e2ae4f4bbfeb55d009cd4eef2f5ebe348452a5f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package ole

import (
    "fmt"
    "strings"
)

// DISPPARAMS are the arguments that passed to methods or property.
type DISPPARAMS struct {
    rgvarg            uintptr
    rgdispidNamedArgs uintptr
    cArgs             uint32
    cNamedArgs        uint32
}

// EXCEPINFO defines exception info.
type EXCEPINFO struct {
    wCode             uint16
    wReserved         uint16
    bstrSource        *uint16
    bstrDescription   *uint16
    bstrHelpFile      *uint16
    dwHelpContext     uint32
    pvReserved        uintptr
    pfnDeferredFillIn uintptr
    scode             uint32
}

// WCode return wCode in EXCEPINFO.
func (e EXCEPINFO) WCode() uint16 {
    return e.wCode
}

// SCODE return scode in EXCEPINFO.
func (e EXCEPINFO) SCODE() uint32 {
    return e.scode
}

// String convert EXCEPINFO to string.
func (e EXCEPINFO) String() string {
    var src, desc, hlp string
    if e.bstrSource == nil {
        src = "<nil>"
    } else {
        src = BstrToString(e.bstrSource)
    }

    if e.bstrDescription == nil {
        desc = "<nil>"
    } else {
        desc = BstrToString(e.bstrDescription)
    }

    if e.bstrHelpFile == nil {
        hlp = "<nil>"
    } else {
        hlp = BstrToString(e.bstrHelpFile)
    }

    return fmt.Sprintf(
        "wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x",
        e.wCode, src, desc, hlp, e.dwHelpContext, e.scode,
    )
}

// Error implements error interface and returns error string.
func (e EXCEPINFO) Error() string {
    if e.bstrDescription != nil {
        return strings.TrimSpace(BstrToString(e.bstrDescription))
    }

    src := "Unknown"
    if e.bstrSource != nil {
        src = BstrToString(e.bstrSource)
    }

    code := e.scode
    if e.wCode != 0 {
        code = uint32(e.wCode)
    }

    return fmt.Sprintf("%v: %#x", src, code)
}

// PARAMDATA defines parameter data type.
type PARAMDATA struct {
    Name *int16
    Vt   uint16
}

// METHODDATA defines method info.
type METHODDATA struct {
    Name     *uint16
    Data     *PARAMDATA
    Dispid   int32
    Meth     uint32
    CC       int32
    CArgs    uint32
    Flags    uint16
    VtReturn uint32
}

// INTERFACEDATA defines interface info.
type INTERFACEDATA struct {
    MethodData *METHODDATA
    CMembers   uint32
}

// Point is 2D vector type.
type Point struct {
    X int32
    Y int32
}

// Msg is message between processes.
type Msg struct {
    Hwnd    uint32
    Message uint32
    Wparam  int32
    Lparam  int32
    Time    uint32
    Pt      Point
}

// TYPEDESC defines data type.
type TYPEDESC struct {
    Hreftype uint32
    VT       uint16
}

// IDLDESC defines IDL info.
type IDLDESC struct {
    DwReserved uint32
    WIDLFlags  uint16
}

// TYPEATTR defines type info.
type TYPEATTR struct {
    Guid             GUID
    Lcid             uint32
    dwReserved       uint32
    MemidConstructor int32
    MemidDestructor  int32
    LpstrSchema      *uint16
    CbSizeInstance   uint32
    Typekind         int32
    CFuncs           uint16
    CVars            uint16
    CImplTypes       uint16
    CbSizeVft        uint16
    CbAlignment      uint16
    WTypeFlags       uint16
    WMajorVerNum     uint16
    WMinorVerNum     uint16
    TdescAlias       TYPEDESC
    IdldescType      IDLDESC
}