OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
autoval.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectComponents
3// Copyright (c) 1994, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// TAutoVal implementation
7//----------------------------------------------------------------------------
8#include <ocf/pch.h>
9
10#include <ocf/autodefs.h>
11
12namespace ocf {
13
14using namespace owl;
15
16//----------------------------------------------------------------------------
17// TAutoVal assignment operators (others are inline)
18//
19
20//
21//
22void
24{
25 vt = atString;
27 SetLocale(s.GetLangId() ? s.GetLangId() : TLocaleString::NativeLangId);
28}
29
30//
31//
32void
34{
35 vt = atString;
37 SetLocale(s.GetLangId() ? s.GetLangId() : TLocaleString::NativeLangId);
38}
39
40//
41//
42void
44{
45 vt = atString;
46#if defined(_UNICODE)
47 bstrVal = ::SysAllocString(s.c_str());
48#else
50#endif
52}
53
54
55// Provides automatic conversion of const char* to BSTR
56//
63
64//
65// should add operator==(TLocaleString) which translates to proper LangId
66// this requires Set/GetLocale to be used for atVoid initialized variants
67//
68
69//----------------------------------------------------------------------------
70// TAutoVal conversion operators
71//
72
73//
74//
75//
76void
78{
79 switch (vt) {
80 case atVoid:
81 case atString:
82 case atObject:
83 p.Locale = locale;
84 };
85}
86
87//
88//
89//
92{
93 switch (vt) {
94 case atVoid:
95 case atString:
96 case atObject:
97 return p.Locale;
98 };
99 return 0;
100}
101
102//
103//
104//
107{
108 switch (vt) {
109 case atVoid:
110 case atString:
111 case atObject:
112 return LANGIDFROMLCID(p.Locale);
113 };
114 return 0;
115}
116
117//
118//
119//
120TAutoVal::operator unsigned char()
121{
122 unsigned char v;
123 switch (vt) {
124 case atByte: return bVal;
125 case atShort: if(::VarUI1FromI2(iVal, &v)) break; return v;
126 case atLong: if(::VarUI1FromI4(lVal, &v)) break; return v;
127 case atFloat: if(::VarUI1FromR4(fltVal,&v)) break; return v;
128 case atDouble: if(::VarUI1FromR8(dblVal,&v)) break; return v;
129 case atCurrency:if(::VarUI1FromCy(cyVal, &v)) break; return v;
130 case atDatetime:if(::VarUI1FromDate(date,&v)) break; return v;
131 case atString: if(::VarUI1FromStr(bstrVal,GetLocale(),0L,&v)) break; return v;
132 case atObject: if(::VarUI1FromDisp(pdispVal,GetLocale(),&v)) break; return v;
133 case atBool: return (unsigned char)(boolVal ? 1 : 0);
134 case atByRef+atByte: return *pbVal;
135 case atByRef+atShort: if(::VarUI1FromI2(*piVal, &v)) break; return v;
136 case atByRef+atLong: if(::VarUI1FromI4(*plVal, &v)) break; return v;
137 case atByRef+atFloat: if(::VarUI1FromR4(*pfltVal,&v)) break; return v;
138 case atByRef+atDouble: if(::VarUI1FromR8(*pdblVal,&v)) break; return v;
139 case atByRef+atCurrency:if(::VarUI1FromCy(*pcyVal, &v)) break; return v;
140 case atByRef+atDatetime:if(::VarUI1FromDate(*pdate,&v)) break; return v;
141 case atByRef+atString: if(::VarUI1FromStr(*pbstrVal,GetLocale(),0L,&v)) break; return v;
142 case atByRef+atBool: return (unsigned char)(*pbool ? 1 : 0);
143 }
145 return 0;
146}
147
148//
149//
150//
151TAutoVal::operator short()
152{
153 short v;
154 switch (vt) {
155 case atByte: return (short)bVal;
156 case atShort: return iVal;
157/// case atLong: if (lVal>0x7FFFL || lVal <0xFFFF8000L) break; return (short)lVal;
158 case atLong: if(::VarI2FromI4(lVal, &v)) break; return v;
159 case atFloat: if(::VarI2FromR4(fltVal,&v)) break; return v;
160 case atDouble: if(::VarI2FromR8(dblVal,&v)) break; return v;
161 case atCurrency:if(::VarI2FromCy(cyVal, &v)) break; return v;
162 case atDatetime:if(::VarI2FromDate(date,&v)) break; return v;
163 case atString: if(::VarI2FromStr(bstrVal,GetLocale(),0L,&v)) break; return v;
164 case atObject: if(::VarI2FromDisp(pdispVal,GetLocale(),&v)) break; return v;
165 case atBool: return short(boolVal ? 1 : 0);
166 case atByRef+atByte: return (short)*pbVal;
167 case atByRef+atShort: return *piVal;
168/// case atByRef+atLong: if (*plVal>0x7FFFL || *plVal <0xFFFF8000L) break; return (short)*plVal;
169 case atByRef+atLong: if(::VarI2FromI4(*plVal, &v)) break; return v;
170 case atByRef+atFloat: if(::VarI2FromR4(*pfltVal,&v)) break; return v;
171 case atByRef+atDouble: if(::VarI2FromR8(*pdblVal,&v)) break; return v;
172 case atByRef+atCurrency:if(::VarI2FromCy(*pcyVal, &v)) break; return v;
173 case atByRef+atDatetime:if(::VarI2FromDate(*pdate,&v)) break; return v;
174 case atByRef+atString: if(::VarI2FromStr(*pbstrVal,GetLocale(),0L,&v)) break; return v;
175 case atByRef+atBool: return short(*pbool ? 1 : 0);
176 }
178 return 0;
179}
180
181//
182//
183//
184TAutoVal::operator long()
185{
186 long v;
187 switch (vt) {
188 case atByte: return (long)bVal;
189 case atShort: return (long)iVal;
190 case atLong: return lVal;
191 case atFloat: if(::VarI4FromR4(fltVal,&v)) break; return v;
192 case atDouble: if(::VarI4FromR8(dblVal,&v)) break; return v;
193 case atCurrency:if(::VarI4FromCy(cyVal, &v)) break; return v;
194 case atDatetime:if(::VarI4FromDate(date,&v)) break; return v;
195 case atString: if(::VarI4FromStr(bstrVal,GetLocale(),0L,&v)) break; return v;
196 case atObject: if(::VarI4FromDisp(pdispVal,GetLocale(),&v)) break; return v;
197 case atBool: return boolVal ? 1L : 0L;
198 case atByRef+atByte: return (long)*pbVal;
199 case atByRef+atShort: return (long)*piVal;
200 case atByRef+atLong: return *plVal;
201 case atByRef+atFloat: if(::VarI4FromR4(*pfltVal,&v)) break; return v;
202 case atByRef+atDouble: if(::VarI4FromR8(*pdblVal,&v)) break; return v;
203 case atByRef+atCurrency:if(::VarI4FromCy(*pcyVal, &v)) break; return v;
204 case atByRef+atDatetime:if(::VarI4FromDate(*pdate,&v)) break; return v;
205 case atByRef+atString: if(::VarI4FromStr(*pbstrVal,GetLocale(),0L,&v)) break; return v;
206 case atByRef+atBool: return *pbool ? 1L : 0L;
207 }
209 return 0;
210}
211
212//
213//
214//
215TAutoVal::operator TBool()
216{
217 switch (vt) {
218 case atByte: return static_cast<TBool>(bVal != 0);
219 case atShort: return static_cast<TBool>(iVal != 0);
220 case atLong: return static_cast<TBool>(lVal != 0);
221 case atFloat: return static_cast<TBool>(fltVal != 0);
222 case atDouble: return static_cast<TBool>(dblVal != 0);
223 case atCurrency:return static_cast<TBool>(cyVal.Lo!=0 || cyVal.Hi != 0);
224 case atDatetime:return static_cast<TBool>(date != 0);
225 case atString: {short v; if(::VarBoolFromStr(bstrVal,GetLocale(),0L,&v)) break; return static_cast<TBool>(v!=0);}
226 case atObject: {short v; if(::VarBoolFromDisp(pdispVal,GetLocale(),&v)) break; return static_cast<TBool>(v!=0);}
227 case atBool: return static_cast<TBool>(boolVal != 0); // note: VARIANT bool TRUE is -1
228 case atByRef+atByte: return static_cast<TBool>(*pbVal != 0);
229 case atByRef+atShort: return static_cast<TBool>(*piVal != 0);
230 case atByRef+atLong: return static_cast<TBool>(*plVal != 0);
231 case atByRef+atFloat: return static_cast<TBool>(*pfltVal != 0);
232 case atByRef+atDouble: return static_cast<TBool>(*pdblVal != 0);
233 case atByRef+atCurrency:return static_cast<TBool>(pcyVal->Lo != 0 || pcyVal->Hi != 0);
234 case atByRef+atDatetime:return static_cast<TBool>(*pdate != 0);
235 case atByRef+atString: {short v; if(::VarBoolFromStr(*pbstrVal,GetLocale(),0L,&v)) break; return static_cast<TBool>(v!=0);}
236 case atByRef+atBool: return static_cast<TBool>(*pbool != 0);
237 }
239 return 0;
240}
241
242//
243//
244//
245TAutoVal::operator float()
246{
247 float v;
248 switch (vt) {
249 case atByte: if(::VarR4FromUI1(bVal,&v)) break; return v;
250 case atShort: if(::VarR4FromI2(iVal, &v)) break; return v;
251 case atLong: if(::VarR4FromI4(lVal, &v)) break; return v;
252 case atFloat: return fltVal;
253 case atDouble: if(::VarR4FromR8(dblVal,&v)) break; return v;
254 case atCurrency: if(::VarR4FromCy(cyVal, &v)) break; return v;
255 case atDatetime: if(::VarR4FromDate(date,&v)) break; return v;
256 case atString: if(::VarR4FromStr(bstrVal,GetLocale(),0L,&v)) break; return v;
257 case atObject: if(::VarR4FromDisp(pdispVal,GetLocale(),&v)) break; return v;
258 case atBool: if(::VarR4FromBool(boolVal,&v)) break; return v;
259 case atByRef+atByte: if(::VarR4FromUI1(*pbVal,&v)) break; return v;
260 case atByRef+atShort: if(::VarR4FromI2(*piVal, &v)) break; return v;
261 case atByRef+atLong: if(::VarR4FromI4(*plVal, &v)) break; return v;
262 case atByRef+atFloat: return *pfltVal;
263 case atByRef+atDouble: if(::VarR4FromR8(*pdblVal,&v)) break; return v;
264 case atByRef+atCurrency:if(::VarR4FromCy(*pcyVal, &v)) break; return v;
265 case atByRef+atDatetime:if(::VarR4FromDate(*pdate,&v)) break; return v;
266 case atByRef+atString: if(::VarR4FromStr(*pbstrVal,GetLocale(),0L,&v)) break; return v;
267 case atByRef+atBool: if(::VarR4FromBool(*pbool,&v)) break; return v;
268 }
270 return 0;
271}
272
273//
274//
275//
276TAutoVal::operator double()
277{
278 double v;
279 switch (vt) {
280 case atByte: if(::VarR8FromUI1(bVal,&v)) break; return v;
281 case atShort: if(::VarR8FromI2(iVal, &v)) break; return v;
282 case atLong: if(::VarR8FromI4(lVal, &v)) break; return v;
283 case atFloat: if(::VarR8FromR4(fltVal,&v)) break; return v;
284 case atDouble: return dblVal;
285 case atCurrency:if(::VarR8FromCy(cyVal, &v)) break; return v;
286 case atDatetime:if(::VarR8FromDate(date,&v)) break; return v;
287 case atString: if(::VarR8FromStr(bstrVal,GetLocale(),0L,&v)) break; return v;
288 case atObject: if(::VarR8FromDisp(pdispVal,GetLocale(),&v)) break; return v;
289 case atBool: if(::VarR8FromBool(boolVal,&v)) break; return v;
290 case atByRef+atByte: if(::VarR8FromUI1(*pbVal,&v)) break; return v;
291 case atByRef+atShort: if(::VarR8FromI2(*piVal, &v)) break; return v;
292 case atByRef+atLong: if(::VarR8FromI4(*plVal, &v)) break; return v;
293 case atByRef+atFloat: if(::VarR8FromR4(*pfltVal,&v)) break; return v;
294 case atByRef+atDouble: return *pdblVal;
295 case atByRef+atCurrency:if(::VarR8FromCy(*pcyVal, &v)) break; return v;
296 case atByRef+atDatetime:if(::VarR8FromDate(*pdate,&v)) break; return v;
297 case atByRef+atString: if(::VarR8FromStr(*pbstrVal,GetLocale(),0L,&v)) break; return v;
298 case atByRef+atBool: if(::VarR8FromBool(*pbool,&v)) break; return v;
299 }
301 return 0;
302}
303
304//
305//
306//
307TAutoVal::operator TAutoDate()
308{
309 DATE v;
310 switch (vt) {
311 case atByte: if(::VarDateFromUI1(bVal,&v)) break; return v;
312 case atShort: if(::VarDateFromI2(iVal, &v)) break; return v;
313 case atLong: if(::VarDateFromI4(lVal, &v)) break; return v;
314 case atFloat: if(::VarDateFromR4(fltVal,&v)) break; return v;
315 case atDouble: if(::VarDateFromR8(dblVal,&v)) break; return v;
316 case atDatetime: return date;
317 case atString: if(::VarDateFromStr(bstrVal,GetLocale(),0L,&v)) break; return v;
318 case atObject: if(::VarDateFromDisp(pdispVal,GetLocale(),&v)) break; return v;
319 case atBool: if(::VarDateFromBool(boolVal,&v)) break; return v;
320 case atByRef+atByte: if(::VarDateFromUI1(*pbVal,&v)) break; return v;
321 case atByRef+atShort: if(::VarDateFromI2(*piVal, &v)) break; return v;
322 case atByRef+atLong: if(::VarDateFromI4(*plVal, &v)) break; return v;
323 case atByRef+atFloat: if(::VarDateFromR4(*pfltVal,&v)) break; return v;
324 case atByRef+atDouble: if(::VarDateFromR8(*pdblVal,&v)) break; return v;
325 case atByRef+atDatetime:return date;
326 case atByRef+atString: if(::VarDateFromStr(*pbstrVal,GetLocale(),0L,&v)) break; return v;
327 case atByRef+atBool: if(::VarDateFromBool(*pbool,&v)) break; return v;
328 }
330 return 0;
331}
332
333//
334//
335//
336TAutoVal::operator TAutoCurrency()
337{
338 CY v;
340
341 HRESULT stat = HR_NOERROR;
342 switch (vt) {
343 case atByte: stat = ::VarCyFromUI1(bVal, &v); break;
344 case atShort: stat = ::VarCyFromI2(iVal, &v); break;
345 case atLong: stat = ::VarCyFromI4(lVal, &v); break;
346 case atFloat: stat = ::VarCyFromR4(fltVal,&v); break;
347 case atDouble: stat = ::VarCyFromR8(dblVal,&v); break;
348// case atCurrency:break; <=== Was this !!! // Y.B check !!!
349 case atCurrency: rv = cyVal; break; // Changed to this!!! RBM // suggested by Bob Miller
350
351 case atString: stat = ::VarCyFromStr(bstrVal,GetLocale(),0L,&v); break;
352 case atObject: stat = ::VarCyFromDisp(pdispVal,GetLocale(),&v); break;
353 case atBool: stat = ::VarCyFromBool(boolVal,&v); break;
354 case atByRef+atByte: stat = ::VarCyFromUI1(*pbVal, &v); break;
355 case atByRef+atShort: stat = ::VarCyFromI2(*piVal, &v); break;
356 case atByRef+atLong: stat = ::VarCyFromI4(*plVal, &v); break;
357 case atByRef+atFloat: stat = ::VarCyFromR4(*pfltVal,&v); break;
358 case atByRef+atDouble: stat = ::VarCyFromR8(*pdblVal,&v); break;
359 //case atByRef+atCurrency:break; // suggested by Bob Miller // Y.B check !!!
360 case atByRef+atCurrency: rv = *pcyVal; break; // Changed to this!!! RBM
361
362 case atByRef+atString: stat = ::VarCyFromStr(*pbstrVal,GetLocale(),0L,&v); break;
363 case atByRef+atBool: stat = ::VarCyFromBool(*pbool,&v); break;
364 default: stat = (HRESULT)-1;
365 }
366 if (stat != HR_NOERROR)
368 return rv;
369}
370
371//
372// Convert TAutoVal to TUString, used by TAutoString contructor and assignment
373//
374TAutoVal::operator TUString*()
375{
376 BSTR v;
377 HRESULT stat;
379
380 switch (vt) {
381 case atByte: stat = ::VarBstrFromUI1(bVal, lcid,0, &v); break;
382 case atShort: stat = ::VarBstrFromI2(iVal, lcid,0, &v); break;
383 case atLong: stat = ::VarBstrFromI4(lVal, lcid,0, &v); break;
384 case atFloat: stat = ::VarBstrFromR4(fltVal,lcid,0, &v); break;
385 case atDouble: stat = ::VarBstrFromR8(dblVal,lcid,0, &v); break;
386 case atCurrency: stat = ::VarBstrFromCy(cyVal ,lcid,0, &v); break;
387 case atDatetime: stat = ::VarBstrFromDate(date,lcid,0, &v); break;
388 case atString: if (bstrVal) vt = atLoanedBSTR;
389 return (s.Holder=TUString::Create(bstrVal, true, GetLanguage()));
390 case atObject: stat = ::VarBstrFromDisp(pdispVal,GetLocale(),0, &v); break;
391 case atBool: stat = ::VarBstrFromBool(boolVal,lcid,0, &v); break;
392 case atByRef+atByte: stat = ::VarBstrFromUI1(*pbVal, lcid,0, &v); break;
393 case atByRef+atShort: stat = ::VarBstrFromI2(*piVal, lcid,0, &v); break;
394 case atByRef+atLong: stat = ::VarBstrFromI4(*plVal, lcid,0, &v); break;
395 case atByRef+atFloat: stat = ::VarBstrFromR4(*pfltVal,lcid,0, &v); break;
396 case atByRef+atDouble: stat = ::VarBstrFromR8(*pdblVal,lcid,0, &v); break;
397 case atByRef+atCurrency: stat = ::VarBstrFromCy(*pcyVal ,lcid,0, &v); break;
398 case atByRef+atDatetime: stat = ::VarBstrFromDate(*pdate,lcid,0, &v); break;
399 case atByRef+atString: if (*pbstrVal) vt = atByRef+atLoanedBSTR;
400 return (s.Holder=TUString::Create(*pbstrVal, true, GetLanguage()));
401 case atByRef+atBool: stat = ::VarBstrFromBool(*pbool,lcid,0,&v);break;
402 default: stat = (HRESULT)-1;
403 }
404 if (stat != HR_NOERROR)
406 return TUString::Create(v, false, LANGIDFROMLCID(lcid));
407}
408
409//
410// Convert TAutoVal to string, high performance if already of string type
411//
412TAutoVal::operator owl::tstring()
413{
414 BSTR v;
415 HRESULT stat;
417
418 switch (vt) {
419 case atByte: stat = ::VarBstrFromUI1(bVal, lcid,0, &v); break;
420 case atShort: stat = ::VarBstrFromI2(iVal, lcid,0, &v); break;
421 case atLong: stat = ::VarBstrFromI4(lVal, lcid,0, &v); break;
422 case atFloat: stat = ::VarBstrFromR4(fltVal,lcid,0, &v); break;
423 case atDouble: stat = ::VarBstrFromR8(dblVal,lcid,0, &v); break;
424 case atCurrency: stat = ::VarBstrFromCy(cyVal ,lcid,0, &v); break;
425 case atDatetime: stat = ::VarBstrFromDate(date,lcid,0, &v); break;
426 case atString: return owl::tstring(TString(bstrVal));
427 case atObject: stat = ::VarBstrFromDisp(pdispVal,GetLocale(),0, &v); break;
428 case atBool: stat = ::VarBstrFromBool(boolVal,lcid,0, &v); break;
429 case atByRef+atByte: stat = ::VarBstrFromUI1(*pbVal, lcid,0, &v); break;
430 case atByRef+atShort: stat = ::VarBstrFromI2(*piVal, lcid,0, &v); break;
431 case atByRef+atLong: stat = ::VarBstrFromI4(*plVal, lcid,0, &v); break;
432 case atByRef+atFloat: stat = ::VarBstrFromR4(*pfltVal,lcid,0, &v); break;
433 case atByRef+atDouble: stat = ::VarBstrFromR8(*pdblVal,lcid,0, &v); break;
434 case atByRef+atCurrency: stat = ::VarBstrFromCy(*pcyVal ,lcid,0, &v); break;
435 case atByRef+atDatetime: stat = ::VarBstrFromDate(*pdate,lcid,0, &v); break;
436 case atByRef+atString: return owl::tstring(TString(*pbstrVal));
437 case atByRef+atBool: stat = ::VarBstrFromBool(*pbool,lcid,0,&v); break;
438 default: stat = (HRESULT)-1;
439 }
440 if (stat != HR_NOERROR)
443 ::SysFreeString(v);
444 return s;
445}
446
447
448//
449//
450TAutoVal::operator TAutoString()
451{
452 TAutoString str(*this);
453 return str;
454}
455
456//
457//
458//
459TAutoVal::operator TString()
460{
461 return operator owl::tstring();
462}
463
464//
465//
466//
467TAutoVal::operator unsigned short()
468{
469 long temp = operator long();
472 return (unsigned short)temp;
473}
474
475//
476// Pointer data type conversion operators
477//
478TAutoVal::operator unsigned char* ()
479{
480 ConvRef(atByte);
481 return pbVal;
482}
483
484//
485//
486TAutoVal::operator short* ()
487{
488 ConvRef(atShort);
489 return piVal;
490}
491
492//
493//
494TAutoVal::operator unsigned short* ()
495{
496 ConvRef(atShort);
497 return (unsigned short*)piVal; // NOTE: May overflow!
498}
499
500//
501//
502TAutoVal::operator long* ()
503{
504 ConvRef(atLong);
505 return plVal;
506}
507
508//
509//
510TAutoVal::operator unsigned long* ()
511{
512 ConvRef(atLong);
513 return (unsigned long*)plVal; // NOTE: May overflow!
514}
515
516//
517//
518TAutoVal::operator TBool* ()
519{
520 ConvRef(atBool);
521 return (TBool*)pbool;
522}
523
524//
525//
526TAutoVal::operator float* ()
527{
528 ConvRef(atFloat);
529 return pfltVal;
530}
531
532//
533//
534TAutoVal::operator double* ()
535{
536 ConvRef(atDouble);
537 return pdblVal;
538}
539
540//
541//
542TAutoVal::operator void* ()
543{
544 ConvRef(atVoid);
545 return byref;
546}
547
548//
549//
550TAutoVal::operator TAutoDate* ()
551{
552 ConvRef(atDatetime);
553 return (TAutoDate*)pdate;
554}
555
556//
557//
558TAutoVal::operator TAutoCurrency* ()
559{
560 ConvRef(atCurrency);
561 return pcyVal;
562}
563
564//
565//
566void TAutoVal::ConvRef(int type)
567{
568// !BB This code looks like it should read
569// !BB
570// !BB
571#if 1
572 if (vt != (type | atByRef)) { // !BB New code
573#else
574 if (type != (vt | atByRef)) { // !BB Old code
575#endif
577 }
578}
579
580//
581//
582TAutoVal::operator IDispatch*()
583{
584 if (vt == atObject) {
585 if (pdispVal)
586 pdispVal->AddRef();
587 return pdispVal;
588 }
589 if (vt == (atObject | atByRef)) {
590 if (*ppdispVal)
591 (*ppdispVal)->AddRef();
592 return *ppdispVal;
593 }
595 return 0;
596}
597
598//
599//
600//
601TAutoVal::operator IPictureDisp*()
602{
603 return STATIC_CAST(IPictureDisp*, operator IDispatch*());
604}
605
606//
607//
608//
609TAutoVal::operator IFontDisp*()
610{
611 return STATIC_CAST(IFontDisp*, operator IDispatch*());
612}
613
614//
615//
616TAutoVal::operator IUnknown*()
617{
618 if (vt == atUnknown) {
619 if (punkVal)
620 punkVal->AddRef();
621 return punkVal;
622 }
623 if (vt == (atUnknown | atByRef)) {
624 if (*ppunkVal)
625 (*ppunkVal)->AddRef();
626 return *ppunkVal;
627 }
628 if(vt == atObject){
629 if(pdispVal)
630 pdispVal->AddRef();
631 return pdispVal;
632 }
633 if (vt == (atObject | atByRef)) {
634 if (*ppdispVal)
635 (*ppdispVal)->AddRef();
636 return *ppdispVal;
637 }
639 return 0;
640}
641
642//
643//
644TAutoVal::operator IUnknown&()
645{
646 if (vt == atUnknown && punkVal)
647 return *punkVal;
648 if (vt == (atUnknown | atByRef) && *ppunkVal)
649 return **ppunkVal;
651 return *punkVal; // for stupid VC++
652}
653
654//
655//
656TAutoVal::operator IDispatch&()
657{
658 if (vt == atObject && pdispVal)
659 return *pdispVal;
660 if (vt == (atObject | atByRef) && *ppdispVal)
661 return **ppdispVal;
663 return *pdispVal;// for stupid VC++
664}
665
666//
667//
668TAutoVal::operator IPictureDisp&()
669{
670 return STATIC_CAST(IPictureDisp&, operator IDispatch&());
671}
672
673//
674//
675TAutoVal::operator IFontDisp&()
676{
677 return STATIC_CAST(IFontDisp&, operator IDispatch&());
678}
679
680
681// The following operators are added to complement the functionality of TAutoVal
682
683TAutoVal::operator BSTR()
684{
685 BSTR v;
686 HRESULT stat;
688
689 switch (vt) {
690 case atByte: stat = ::VarBstrFromUI1 (bVal, lcid, 0, &v); break;
691 case atShort: stat = ::VarBstrFromI2 (iVal, lcid, 0, &v); break;
692 case atLong: stat = ::VarBstrFromI4 (lVal, lcid, 0, &v); break;
693 case atFloat: stat = ::VarBstrFromR4 (fltVal, lcid, 0, &v); break;
694 case atDouble: stat = ::VarBstrFromR8 (dblVal, lcid, 0, &v); break;
695 case atCurrency: stat = ::VarBstrFromCy (cyVal, lcid, 0, &v); break;
696 case atDatetime: stat = ::VarBstrFromDate(date, lcid, 0, &v); break;
697 case atString: return ::SysAllocString (bstrVal);
698 case atObject: stat = ::VarBstrFromDisp(pdispVal, GetLocale(), 0, &v); break;
699 case atBool: stat = ::VarBstrFromBool(boolVal, lcid, 0, &v); break;
700 case atByRef + atByte: stat = ::VarBstrFromUI1 (*pbVal, lcid, 0, &v); break;
701 case atByRef + atShort: stat = ::VarBstrFromI2 (*piVal, lcid, 0, &v); break;
702 case atByRef + atLong: stat = ::VarBstrFromI4 (*plVal, lcid, 0, &v); break;
703 case atByRef + atFloat: stat = ::VarBstrFromR4 (*pfltVal, lcid, 0, &v); break;
704 case atByRef+atDouble: stat = ::VarBstrFromR8 (*pdblVal, lcid, 0, &v); break;
705 case atByRef + atCurrency: stat = ::VarBstrFromCy (*pcyVal, lcid, 0, &v); break;
706 case atByRef + atDatetime: stat = ::VarBstrFromDate(*pdate, lcid, 0, &v); break;
707 case atByRef + atString: return ::SysAllocString (*pbstrVal);
708 case atByRef + atBool: stat = ::VarBstrFromBool(*pbool, lcid, 0, &v); break;
709 default: stat = (HRESULT) - 1;
710 }
711
712 if (stat != HR_NOERROR)
714
715 return v;
716}
717
718TAutoVal::operator BSTR*()
719{
720 ConvRef(atString);
721 return pbstrVal;
722}
723
724TAutoVal::operator TBSTR*()
725{
726 ConvRef(atString);
727 return (TBSTR*)pbstrVal;
728}
729
730TAutoVal::operator SAFEARRAY*()
731{
732 if (vt & atSafeArray)
733 return((vt & atByRef) ? *pparray : parray);
735 return 0;
736}
737
738TAutoVal::operator IUnknown**()
739{
740 if (vt == atUnknown) {
741 punkVal->AddRef();
742 return &punkVal;
743 }
744 if (vt == (atUnknown | atByRef)) {
745 (*ppunkVal)->AddRef();
746 return ppunkVal;
747 }
749 return 0;
750}
751
752TAutoVal::operator IDispatch**()
753{
754 if (vt == atObject) {
755 pdispVal->AddRef();
756 return &pdispVal;
757 }
758 if (vt == (atObject | atByRef)) {
759 (*ppdispVal)->AddRef();
760 return ppdispVal;
761 }
763 return 0;
764}
765
766TAutoVal::operator TAutoVal*()
767{
768 return this;
769}
770
771TAutoVal::operator LARGE_INTEGER()
772{
773 if (vt == VT_I8)
774 return hVal;
776
777 // To prevent warning
778 LARGE_INTEGER dummy = {0,0};
779 return dummy;
780}
781
782TAutoVal::operator ULARGE_INTEGER()
783{
784 if (vt == VT_UI8)
785 return uhVal;
787
788 // To prevent warning
789 ULARGE_INTEGER dummy = {0,0};
790 return dummy;
791}
792
793#if defined(_WIN64)
794TAutoVal::operator ULONG_PTR()
795{
796 if (vt == VT_UI8)
797 return uptrVal;
799
800 // To prevent warning
801 ULONG_PTR dummy = 0;
802 return dummy;
803}
804#endif
805//----------------------------------------------------------------------------
806// Localized point to throw a TXAuto exception
807//
808_TCHAR*
810{
811 //Jogy - there is no much sense in using a static TAPointer, better to use simple static buffer, or return a tstring
812 static TAPointer<_TCHAR> errMsg(new _TCHAR[60]);
813 wsprintf(errMsg, _T("Automation Exception, TXAuto::ErrorCode=%d"), err);
814 return errMsg;
815}
816
817//
818//
823
824void
826{
827 throw *this;
828}
829
830void
832{
833 TXAuto(err).Throw();
834}
835
836} // OCF namespace
837
838//==============================================================================
839
OLE Automation Class Definitions.
Based on reference counted TString with added automation functionality.
Definition autodefs.h:492
Automation data element (same data as OLE/BASIC VARIANT)
Definition autodefs.h:526
VARIANT_BOOL boolVal
Definition autodefs.h:745
struct ocf::TAutoVal::@47::@50 s
SAFEARRAY * parray
Definition autodefs.h:752
double dblVal
Definition autodefs.h:744
LARGE_INTEGER hVal
Also support LARGE_INTEGER.
Definition autodefs.h:785
struct ocf::TAutoVal::@47::@49 p
TLocaleId GetLocale() const
Definition autoval.cpp:91
VARIANT_BOOL * pbool
Definition autodefs.h:758
TAutoCurrency cyVal
Definition autodefs.h:747
void SetLocale(TLocaleId)
Definition autoval.cpp:77
IDispatch * pdispVal
Definition autodefs.h:751
SAFEARRAY ** pparray
Definition autodefs.h:765
unsigned char * pbVal
Definition autodefs.h:753
IDispatch ** ppdispVal
Definition autodefs.h:764
ULARGE_INTEGER uhVal
Also support ULARGE_INTEGER.
Definition autodefs.h:786
unsigned char bVal
Definition autodefs.h:740
const TAutoVal & operator=(const TAutoVal &src)
Definition autodefs.h:1586
float * pfltVal
Definition autodefs.h:756
IUnknown * punkVal
Definition autodefs.h:750
double * pdblVal
Definition autodefs.h:757
BSTR * pbstrVal
Definition autodefs.h:762
short * piVal
Definition autodefs.h:754
DATE * pdate
Definition autodefs.h:761
TAutoCurrency * pcyVal
Definition autodefs.h:760
long * plVal
Definition autodefs.h:755
IUnknown ** ppunkVal
Definition autodefs.h:763
owl::TLangId GetLanguage() const
Definition autoval.cpp:106
TXAuto(TError err)
Definition autoval.cpp:819
static void Raise(TError err)
Definition autoval.cpp:831
void Throw()
Definition autoval.cpp:825
@ xConversionFailure
Definition autodefs.h:119
Reference to reference counted string object TUString Lightweight reference object consisting of a po...
Definition string.h:67
System string (BSTR) encapsulation.
Definition string.h:33
Privately used by TString to manage string pointers This is a reference counted union of various stri...
Definition string.h:145
static TUString * Create(const char *str)
Definition ustring.cpp:307
Derived from xmsg, TXBase is the base class for ObjectWindows and ObjectComponents exception-handling...
Definition exbase.h:41
#define _T(x)
Definition cygwin.h:51
Include for OC, gets common headers when precompiled headers are enabled.
Object Component Framework (COM encapsulation)
Definition appdesc.h:22
const owl::uint16 atSafeArray
Definition autodefs.h:344
TCHAR * GetAutoExceptionMsg(TXAuto::TError err)
Definition autoval.cpp:809
const owl::uint16 atByRef
Definition autodefs.h:345
unsigned long TLocaleId
Definition autodefs.h:72
@ atLong
Definition autodefs.h:326
@ atObject
Definition autodefs.h:332
@ atString
Definition autodefs.h:331
@ atByte
Definition autodefs.h:337
@ atVoid
Definition autodefs.h:323
@ atDatetime
Definition autodefs.h:330
@ atCurrency
Definition autodefs.h:329
@ atUnknown
Definition autodefs.h:336
@ atLoanedBSTR
Definition autodefs.h:340
@ atBool
Definition autodefs.h:334
@ atDouble
Definition autodefs.h:328
@ atFloat
Definition autodefs.h:327
@ atShort
Definition autodefs.h:325
TAutoString
Definition occtrl.cpp:135
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
bool TBool
Definition defs.h:288
owl::uint16 TLangId
Holds a language ID, a predefined number that represents a base language and dialect.
Definition lclstrng.h:26
const TLangId LangUserDefault
Definition lclstrng.h:31
BSTR SysAllocString(const char *str)
Definition string.h:130
std::string tstring
Definition defs.h:79
#define HR_NOERROR
Definition defs.h:73
#define STATIC_CAST(targetType, object)
Definition defs.h:271
static TLangId NativeLangId
The base language ID of non-localized strings.
Definition lclstrng.h:90