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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
/***
*cdisp.cpp
*
* Copyright (C) 1992-93, Microsoft Corporation. All Rights Reserved.
* Information Contained Herein Is Proprietary and Confidential.
*
*Purpose:
* This file implements a trivial class that supports IDispatch, and
* exposes a single property.
*
*Revision History:
*
* [00] 10-Apr-93 bradlo: Created.
*
*Implementation Notes:
*
*****************************************************************************/
#include "common.h"
#include "cdisp.h"
CDisp::CDisp()
{
m_refs = 0;
V_VT(&m_var) = VT_BSTR;
V_BSTR(&m_var) = SysAllocString(OLESTR("13.14"));
}
HRESULT
CDisp::Create(IDispatch FAR* FAR* ppdisp)
{
CDisp FAR* pdisp;
if((pdisp = new FAR CDisp()) == NULL)
return ResultFromScode(E_OUTOFMEMORY);
pdisp->AddRef();
*ppdisp = (IDispatch FAR*)pdisp;
return NOERROR;
}
STDMETHODIMP
CDisp::QueryInterface(REFIID riid, void FAR* FAR* ppv)
{
if(!IsEqualIID(riid, IID_IUnknown))
if(!IsEqualIID(riid, IID_IDispatch))
return ResultFromScode(E_NOINTERFACE);
*ppv = this;
AddRef();
return NOERROR;
}
STDMETHODIMP_(unsigned long)
CDisp::AddRef()
{
return ++m_refs;
}
STDMETHODIMP_(unsigned long)
CDisp::Release()
{
if(--m_refs == 0){
VariantClear(&m_var);
delete this;
return 0;
}
return m_refs;
}
STDMETHODIMP
CDisp::GetTypeInfoCount(unsigned int FAR* pctinfo)
{
*pctinfo = NULL;
return NOERROR;
}
STDMETHODIMP
CDisp::GetTypeInfo(
unsigned int itinfo,
LCID lcid,
ITypeInfo FAR* FAR* pptinfo)
{
UNUSED(lcid);
UNUSED(itinfo);
UNUSED(pptinfo);
return ResultFromScode(DISP_E_BADINDEX);
}
STDMETHODIMP
CDisp::GetIDsOfNames(
REFIID riid,
OLECHAR FAR* FAR* rgszNames,
unsigned int cNames,
LCID lcid,
DISPID FAR* rgdispid)
{
unsigned int u;
HRESULT hresult;
UNUSED(lcid);
if(!IsEqualIID(riid, IID_NULL))
return ResultFromScode(DISP_E_UNKNOWNINTERFACE);
if(cNames == 0)
return ResultFromScode(E_INVALIDARG);
rgdispid[0] =
(STRICMP(STRING(rgszNames[0]), TSTR("value")))
? DISPID_UNKNOWN : DISPID_VALUE;
hresult = NOERROR;
if(cNames > 1){
hresult = ResultFromScode(DISP_E_UNKNOWNNAME);
for(u = 1; u < cNames; ++u)
rgdispid[u] = DISPID_UNKNOWN;
}
return hresult;
}
STDMETHODIMP
CDisp::Invoke(
DISPID dispidMember,
REFIID riid,
LCID lcid,
unsigned short wFlags,
DISPPARAMS FAR* pdispparams,
VARIANT FAR* pvarResult,
EXCEPINFO FAR* pexcepinfo,
unsigned int FAR* puArgErr)
{
VARIANT var;
unsigned int uArgErr;
VARIANT varResult;
UNUSED(lcid);
UNUSED(pexcepinfo);
if(!IsEqualIID(riid, IID_NULL))
return ResultFromScode(DISP_E_UNKNOWNINTERFACE);
if(puArgErr == NULL)
puArgErr = &uArgErr;
if(pvarResult == NULL)
pvarResult = &varResult;
if(dispidMember == DISPID_VALUE){
if(wFlags & DISPATCH_PROPERTYPUT){
if(pdispparams->cArgs != 1)
return ResultFromScode(DISP_E_BADPARAMCOUNT);
IfFailRet(VariantCopyInd(&var, &pdispparams->rgvarg[0]));
put_value(var);
IfFailRet(VariantClear(&var));
return NOERROR;
}
if(wFlags & DISPATCH_PROPERTYGET){
if(pdispparams->cArgs != 0)
return ResultFromScode(DISP_E_BADPARAMCOUNT);
var = get_value();
IfFailRet(VariantCopy(pvarResult, &var));
IfFailRet(VariantClear(&var));
return NOERROR;
}
}
return ResultFromScode(DISP_E_MEMBERNOTFOUND);
}
STDMETHODIMP_(void)
CDisp::put_value(VARIANT var)
{
VariantClear(&m_var);
VariantCopy(&m_var, &var);
}
STDMETHODIMP_(VARIANT)
CDisp::get_value()
{
VARIANT var;
VariantInit(&var);
VariantCopy(&var, &m_var);
return var;
}
/***************************************************************/
/* WIN32 Unicode Support */
/***************************************************************/
#if OE_WIN32 && 0
CDispW::CDispW()
{
m_refs = 0;
V_VT(&m_var) = VT_WBSTR;
V_WBSTR(&m_var) = SysAllocStringW(L"13.14");
}
HRESULT
CDispW::Create(IDispatchW FAR* FAR* ppdisp)
{
CDispW FAR* pdisp;
if((pdisp = new FAR CDispW()) == NULL)
return ResultFromScode(E_OUTOFMEMORY);
pdisp->AddRef();
*ppdisp = (IDispatchW FAR*)pdisp;
return NOERROR;
}
STDMETHODIMP
CDispW::QueryInterface(REFIID riid, void FAR* FAR* ppv)
{
if(riid == IID_IUnknown || riid == IID_IDispatchW){
*ppv = this;
AddRef();
return NOERROR;
}
return ResultFromScode(E_NOINTERFACE);
}
STDMETHODIMP_(unsigned long)
CDispW::AddRef()
{
return ++m_refs;
}
STDMETHODIMP_(unsigned long)
CDispW::Release()
{
if(--m_refs == 0){
VariantClear(&m_var);
delete this;
return 0;
}
return m_refs;
}
STDMETHODIMP
CDispW::GetTypeInfoCount(unsigned int FAR* pctinfo)
{
*pctinfo = NULL;
return NOERROR;
}
STDMETHODIMP
CDispW::GetTypeInfo(
unsigned int itinfo,
LCID lcid,
ITypeInfoW FAR* FAR* pptinfo)
{
UNUSED(lcid);
UNUSED(pptinfo);
return ResultFromScode(DISP_E_BADINDEX);
}
STDMETHODIMP
CDispW::GetIDsOfNames(
REFIID riid,
WCHAR FAR* FAR* rgszNames,
unsigned int cNames,
LCID lcid,
DISPID FAR* rgdispid)
{
unsigned int u;
HRESULT hresult;
UNUSED(lcid);
if(riid != IID_NULL)
return ResultFromScode(DISP_E_UNKNOWNINTERFACE);
if(cNames == 0)
return ResultFromScode(E_INVALIDARG);
rgdispid[0] =
(lstrcmpW(rgszNames[0], L"value"))
? DISPID_UNKNOWN : DISPID_VALUE;
hresult = NOERROR;
if(cNames > 1){
hresult = ResultFromScode(DISP_E_UNKNOWNNAME);
for(u = 1; u < cNames; ++u)
rgdispid[u] = DISPID_UNKNOWN;
}
return hresult;
}
STDMETHODIMP
CDispW::Invoke(
DISPID dispidMember,
REFIID riid,
LCID lcid,
unsigned short wFlags,
DISPPARAMS FAR* pdispparams,
VARIANT FAR* pvarResult,
WEXCEPINFO FAR* pexcepinfo,
unsigned int FAR* puArgErr)
{
VARIANT var;
unsigned int uArgErr;
VARIANT varResult;
UNUSED(lcid);
if(riid != IID_NULL)
return ResultFromScode(DISP_E_UNKNOWNINTERFACE);
if(puArgErr == NULL)
puArgErr = &uArgErr;
if(pvarResult == NULL)
pvarResult = &varResult;
if(dispidMember == DISPID_VALUE){
if(wFlags & DISPATCH_PROPERTYPUT){
if(pdispparams->cArgs != 1)
return ResultFromScode(DISP_E_BADPARAMCOUNT);
IfFailRet(VariantCopyInd(&var, &pdispparams->rgvarg[0]));
put_value(var);
IfFailRet(VariantClear(&var));
return NOERROR;
}
if(wFlags & DISPATCH_PROPERTYGET){
if(pdispparams->cArgs != 0)
return ResultFromScode(DISP_E_BADPARAMCOUNT);
var = get_value();
IfFailRet(VariantCopy(pvarResult, &var));
IfFailRet(VariantClear(&var));
return NOERROR;
}
}
return ResultFromScode(DISP_E_MEMBERNOTFOUND);
}
STDMETHODIMP_(void)
CDispW::put_value(VARIANT var)
{
VariantClear(&m_var);
VariantCopy(&m_var, &var);
}
STDMETHODIMP_(VARIANT)
CDispW::get_value()
{
VARIANT var;
VariantInit(&var);
VariantCopy(&var, &m_var);
return var;
}
#endif
|