1package ole
2
3import (
4	"fmt"
5	"strings"
6)
7
8// DISPPARAMS are the arguments that passed to methods or property.
9type DISPPARAMS struct {
10	rgvarg            uintptr
11	rgdispidNamedArgs uintptr
12	cArgs             uint32
13	cNamedArgs        uint32
14}
15
16// EXCEPINFO defines exception info.
17type 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// WCode return wCode in EXCEPINFO.
30func (e EXCEPINFO) WCode() uint16 {
31	return e.wCode
32}
33
34// SCODE return scode in EXCEPINFO.
35func (e EXCEPINFO) SCODE() uint32 {
36	return e.scode
37}
38
39// String convert EXCEPINFO to string.
40func (e EXCEPINFO) String() string {
41	var src, desc, hlp string
42	if e.bstrSource == nil {
43		src = "<nil>"
44	} else {
45		src = BstrToString(e.bstrSource)
46	}
47
48	if e.bstrDescription == nil {
49		desc = "<nil>"
50	} else {
51		desc = BstrToString(e.bstrDescription)
52	}
53
54	if e.bstrHelpFile == nil {
55		hlp = "<nil>"
56	} else {
57		hlp = BstrToString(e.bstrHelpFile)
58	}
59
60	return fmt.Sprintf(
61		"wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x",
62		e.wCode, src, desc, hlp, e.dwHelpContext, e.scode,
63	)
64}
65
66// Error implements error interface and returns error string.
67func (e EXCEPINFO) Error() string {
68	if e.bstrDescription != nil {
69		return strings.TrimSpace(BstrToString(e.bstrDescription))
70	}
71
72	src := "Unknown"
73	if e.bstrSource != nil {
74		src = BstrToString(e.bstrSource)
75	}
76
77	code := e.scode
78	if e.wCode != 0 {
79		code = uint32(e.wCode)
80	}
81
82	return fmt.Sprintf("%v: %#x", src, code)
83}
84
85// PARAMDATA defines parameter data type.
86type PARAMDATA struct {
87	Name *int16
88	Vt   uint16
89}
90
91// METHODDATA defines method info.
92type METHODDATA struct {
93	Name     *uint16
94	Data     *PARAMDATA
95	Dispid   int32
96	Meth     uint32
97	CC       int32
98	CArgs    uint32
99	Flags    uint16
100	VtReturn uint32
101}
102
103// INTERFACEDATA defines interface info.
104type INTERFACEDATA struct {
105	MethodData *METHODDATA
106	CMembers   uint32
107}
108
109// Point is 2D vector type.
110type Point struct {
111	X int32
112	Y int32
113}
114
115// Msg is message between processes.
116type Msg struct {
117	Hwnd    uint32
118	Message uint32
119	Wparam  int32
120	Lparam  int32
121	Time    uint32
122	Pt      Point
123}
124
125// TYPEDESC defines data type.
126type TYPEDESC struct {
127	Hreftype uint32
128	VT       uint16
129}
130
131// IDLDESC defines IDL info.
132type IDLDESC struct {
133	DwReserved uint32
134	WIDLFlags  uint16
135}
136
137// TYPEATTR defines type info.
138type TYPEATTR struct {
139	Guid             GUID
140	Lcid             uint32
141	dwReserved       uint32
142	MemidConstructor int32
143	MemidDestructor  int32
144	LpstrSchema      *uint16
145	CbSizeInstance   uint32
146	Typekind         int32
147	CFuncs           uint16
148	CVars            uint16
149	CImplTypes       uint16
150	CbSizeVft        uint16
151	CbAlignment      uint16
152	WTypeFlags       uint16
153	WMajorVerNum     uint16
154	WMinorVerNum     uint16
155	TdescAlias       TYPEDESC
156	IdldescType      IDLDESC
157}
158