summaryrefslogtreecommitdiffstats
path: root/public/sdk/inc/stgvar.hxx
blob: e0160ab899bec06f48e09728b4a58cf0e381af27 (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
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
//+-------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (C) Microsoft Corporation, 1992 - 1992.
//
//  File:       StgVar.hxx
//
//  Contents:   C++ wrapper for PROPVARIANT.
//
//  History:    01-Aug-94 KyleP     Created
//
//--------------------------------------------------------------------------

#if !defined(__STGVAR_HXX__)
#define __STGVAR_HXX__

#include <objbase.h>
#include <stgvara.hxx>

//+-------------------------------------------------------------------------
//
//  Class:      CStorageVariant
//
//  Purpose:    C++ wrapper for PROPVARIANT
//
//  History:    01-Aug-94 KyleP     Created
//
//  Notes:      A couple of variant arms are not implemented below.
//              VT_BSTR because its type signature is identical to that of
//              VT_LPSTR.  VT_SAFEARRAY because I don't fully understand the
//              structure.
//
//              Some types are duplicate base types with a different variant
//              tag.  These include:
//                  VARIANT_BOOL (short)
//                  SCODE        (long)
//                  DATE         (double)
//              We cannot create trivial constructors for the above because
//              of the type collision.  You must use the Set methods.
//
//              Some types will automatically coerce and cause confusion,
//              so they don't have constructors.  You must use the Set
//              method.  These include:
//                  VT_UI2
//                  VT_UI4
//                  VT_UI8
//
//--------------------------------------------------------------------------


class CCoTaskAllocator : public PMemoryAllocator
{
public:
    virtual void *Allocate(ULONG cbSize);
    virtual void Free(void *pv);
};

#ifndef COTASKDECLSPEC
#define COTASKDECLSPEC  __declspec(dllimport)
#endif

COTASKDECLSPEC CCoTaskAllocator CoTaskAllocator;


class CStorageVariant : public CAllocStorageVariant
{
public:

    //
    // Simple types
    //

    CStorageVariant()                  { vt = VT_EMPTY; }
    CStorageVariant(short i)           { vt = VT_I2; iVal = i; }
    CStorageVariant(long l)            { vt = VT_I4; lVal = l; }
    CStorageVariant(LARGE_INTEGER h)   { vt = VT_I8; hVal = h; }
    CStorageVariant(float flt)         { vt = VT_R4; fltVal = flt; }
    CStorageVariant(double dbl)        { vt = VT_R8; dblVal = dbl; }
    CStorageVariant(CY cy)             { vt = VT_CY; cyVal = cy; }
    CStorageVariant(FILETIME ft)       { vt = VT_FILETIME; filetime = ft; }

    inline CStorageVariant & operator =(CStorageVariant const &var);

    inline CStorageVariant & operator =(short i);
    inline CStorageVariant & operator =(USHORT ui);
    inline CStorageVariant & operator =(long l);
    inline CStorageVariant & operator =(ULONG ul);
    inline CStorageVariant & operator =(LARGE_INTEGER h);
    inline CStorageVariant & operator =(ULARGE_INTEGER uh);
    inline CStorageVariant & operator =(float flt);
    inline CStorageVariant & operator =(double dbl);
    inline CStorageVariant & operator =(CY cy);
    inline CStorageVariant & operator =(FILETIME ft);

    //
    // Types with indirection
    //

    CStorageVariant(BLOB b);
    CStorageVariant(BYTE *pb, ULONG cb);
    CStorageVariant(char const *psz);
    CStorageVariant(WCHAR const *pwsz);
    CStorageVariant(CLSID const *pcid);

    inline CStorageVariant & operator =(BLOB b);
    inline CStorageVariant & operator =(char const *psz);
    inline CStorageVariant & operator =(WCHAR const *pwsz);
    inline CStorageVariant & operator =(CLSID const *pcid);

    //
    // Interface types
    //

    CStorageVariant(IStream *pstr);
    CStorageVariant(IStorage *pstor);

    //
    // Counted array types.  Elements initially zeroed.  Use Set/Get/Size
    // for access.
    //

    CStorageVariant(VARENUM vt, ULONG cElements);

    //
    // To/From C style PROPVARIANT and copy constructor
    //

    inline CStorageVariant(CStorageVariant const &var);

    CStorageVariant(PROPVARIANT &var);

    //
    // Destructor
    //

    ~CStorageVariant();


    //
    // Memory allocation.  Uses CoTaskAllocator
    //

    inline void *operator new(size_t size);
    inline void  operator delete(void *p);
    inline void *operator new(size_t size, void *p);

    //
    // Serialization
    //

    CStorageVariant(PDeSerStream &stm);

    //
    // Set/Get, all types including arrays.
    //

    inline void SetEMPTY();
    inline void SetNULL();
    inline void SetUI1(BYTE i);
    inline void SetI2(short i);
    inline void SetUI2(USHORT ui);
    inline void SetI4(long l);
    inline void SetUI4(ULONG ul);
    inline void SetR4(float f);
    inline void SetR8(double d);
    inline void SetI8(LARGE_INTEGER li);
    inline void SetUI8(ULARGE_INTEGER uli);
    inline void SetBOOL(VARIANT_BOOL b);
    inline void SetERROR(SCODE sc);
    inline void SetCY(CY cy);
    inline void SetDATE(DATE d);
    inline void SetFILETIME(FILETIME ft);


    inline void SetBSTR(BSTR b);

//    void      SetSAFEARRAY(SAFEARRAY &sa);
//    SAFEARRAY GetSAFEARRAY();

    inline void SetLPSTR(char const *psz);
    inline void SetLPWSTR(WCHAR const *pwsz);
    inline void SetBLOB(BLOB b);

    inline void SetSTREAM(IStream *ps);
    inline void SetSTREAMED_OBJECT(IStream *ps);
    inline void SetSTORAGE(IStorage *ps);
    inline void SetSTORED_OBJECT(IStorage *ps);
    inline void SetCLSID(CLSID const *pc);

    //
    // Array access
    //

    void SetUI1(BYTE i, unsigned pos);
    void SetI2(short i, unsigned pos);
    void SetUI2(USHORT ui, unsigned pos);
    void SetI4(long l, unsigned pos);
    void SetUI4(ULONG ul, unsigned pos);
    void SetI8(LARGE_INTEGER li, unsigned pos);
    void SetUI8(ULARGE_INTEGER uli, unsigned pos);
    void SetR4(float f, unsigned pos);
    void SetR8(double d, unsigned pos);
    void SetBOOL(VARIANT_BOOL b, unsigned pos);
    void SetCY(CY c, unsigned pos);
    void SetDATE(DATE d, unsigned pos);

    void SetBSTR(BSTR b, unsigned pos);

//    void            SetVARIANT(CStorageVariant var, unsigned pos);
//    CStorageVariant GetVARIANT(unsigned pos) const;

    void  SetLPSTR(char const *psz, unsigned pos);
    void  SetLPWSTR(WCHAR const *pwsz, unsigned pos);
    void  SetFILETIME(FILETIME f, unsigned pos);
    void  SetCLSID(CLSID c, unsigned pos);
};


inline
CStorageVariant::CStorageVariant(BYTE *pb, ULONG cb) :
    CAllocStorageVariant(pb, cb, CoTaskAllocator)
{
}


inline
CStorageVariant::CStorageVariant(char const *psz) :
    CAllocStorageVariant(psz, CoTaskAllocator)
{
}


inline
CStorageVariant::CStorageVariant(WCHAR const *pwsz) :
    CAllocStorageVariant(pwsz, CoTaskAllocator)
{
}


inline
CStorageVariant::CStorageVariant(CLSID const *pcid) :
    CAllocStorageVariant(pcid, CoTaskAllocator)
{
}


inline
CStorageVariant::CStorageVariant(VARENUM v, ULONG cElements) :
    CAllocStorageVariant(v, cElements, CoTaskAllocator)
{
}


inline
CStorageVariant::CStorageVariant(PROPVARIANT &var) :
    CAllocStorageVariant(var, CoTaskAllocator)
{
}


inline
CStorageVariant::CStorageVariant(PDeSerStream &MemDeSerStream) :
    CAllocStorageVariant(MemDeSerStream, CoTaskAllocator)
{
}


inline
CStorageVariant::~CStorageVariant()
{
    ResetType(CoTaskAllocator);
}


inline void
CStorageVariant::SetEMPTY()
{
    CAllocStorageVariant::SetEMPTY(CoTaskAllocator);
}


inline void
CStorageVariant::SetNULL()
{
    CAllocStorageVariant::SetNULL(CoTaskAllocator);
}


inline void
CStorageVariant::SetUI1(BYTE b)
{
    CAllocStorageVariant::SetUI1(b, CoTaskAllocator);
}


inline void
CStorageVariant::SetI2(short i)
{
    CAllocStorageVariant::SetI2(i, CoTaskAllocator);
}


inline void
CStorageVariant::SetUI2(USHORT ui)
{
    CAllocStorageVariant::SetUI2(ui, CoTaskAllocator);
}


inline void
CStorageVariant::SetI4(long l)
{
    CAllocStorageVariant::SetI4(l, CoTaskAllocator);
}


inline void
CStorageVariant::SetUI4(ULONG ul)
{
    CAllocStorageVariant::SetUI4(ul, CoTaskAllocator);
}


inline void
CStorageVariant::SetR4(float f)
{
    CAllocStorageVariant::SetR4(f, CoTaskAllocator);
}


inline void
CStorageVariant::SetR8(double d)
{
    CAllocStorageVariant::SetR8(d, CoTaskAllocator);
}


inline void
CStorageVariant::SetI8(LARGE_INTEGER li)
{
    CAllocStorageVariant::SetI8(li, CoTaskAllocator);
}


inline void
CStorageVariant::SetUI8(ULARGE_INTEGER uli)
{
    CAllocStorageVariant::SetUI8(uli, CoTaskAllocator);
}


inline void
CStorageVariant::SetBOOL(VARIANT_BOOL b)
{
    CAllocStorageVariant::SetBOOL(b, CoTaskAllocator);
}


inline void
CStorageVariant::SetERROR(SCODE sc)
{
    CAllocStorageVariant::SetERROR(sc, CoTaskAllocator);
}


inline void
CStorageVariant::SetCY(CY cy)
{
    CAllocStorageVariant::SetCY(cy, CoTaskAllocator);
}


inline void
CStorageVariant::SetDATE(DATE d)
{
    CAllocStorageVariant::SetDATE(d, CoTaskAllocator);
}


inline void
CStorageVariant::SetFILETIME(FILETIME ft)
{
    CAllocStorageVariant::SetFILETIME(ft, CoTaskAllocator);
}


inline void
CStorageVariant::SetSTREAM(IStream *ps)
{
    CAllocStorageVariant::SetSTREAM(ps, CoTaskAllocator);
}


inline void
CStorageVariant::SetSTREAMED_OBJECT(IStream *ps)
{
    CAllocStorageVariant::SetSTREAMED_OBJECT(ps, CoTaskAllocator);
}


inline void
CStorageVariant::SetSTORAGE(IStorage *ps)
{
    CAllocStorageVariant::SetSTORAGE(ps, CoTaskAllocator);
}


inline void
CStorageVariant::SetSTORED_OBJECT(IStorage *ps)
{
    CAllocStorageVariant::SetSTORED_OBJECT(ps, CoTaskAllocator);
}


inline void
CStorageVariant::SetCLSID(CLSID const *pc)
{
    CAllocStorageVariant::SetCLSID(pc, CoTaskAllocator);
}


inline CStorageVariant &
CStorageVariant::operator =(CStorageVariant const &var)
{
    ResetType(CoTaskAllocator);
    new (this) CStorageVariant((PROPVARIANT &) var);

    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(short i)
{
    CAllocStorageVariant::SetI2(i, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(USHORT ui)
{
    CAllocStorageVariant::SetUI2(ui, CoTaskAllocator);
    return(*this);
}


inline void
CStorageVariant::SetBSTR(BSTR b)
{
    CAllocStorageVariant::SetBSTR( b, CoTaskAllocator );
}


inline void
CStorageVariant::SetLPSTR(char const *psz)
{
    CAllocStorageVariant::SetLPSTR(psz, CoTaskAllocator);
}


inline void
CStorageVariant::SetLPWSTR(WCHAR const *pwsz)
{
    CAllocStorageVariant::SetLPWSTR(pwsz, CoTaskAllocator);
}


inline void
CStorageVariant::SetBLOB(BLOB b)
{
    CAllocStorageVariant::SetBLOB(b, CoTaskAllocator);
}


inline CStorageVariant &
CStorageVariant::operator =(long l)
{
    CAllocStorageVariant::SetI4(l, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(ULONG ul)
{
    CAllocStorageVariant::SetUI4(ul, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(LARGE_INTEGER h)
{
    CAllocStorageVariant::SetI8(h, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(ULARGE_INTEGER uh)
{
    CAllocStorageVariant::SetUI8(uh, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(float flt)
{
    CAllocStorageVariant::SetR4(flt, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(double dbl)
{
    CAllocStorageVariant::SetR8(dbl, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(CY cy)
{
    CAllocStorageVariant::SetCY(cy, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(FILETIME ft)
{
    CAllocStorageVariant::SetFILETIME(ft, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(BLOB b)
{
    CAllocStorageVariant::SetBLOB(b, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(char const *psz)
{
    CAllocStorageVariant::SetLPSTR(psz, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(WCHAR const *pwsz)
{
    CAllocStorageVariant::SetLPWSTR(pwsz, CoTaskAllocator);
    return(*this);
}


inline CStorageVariant &
CStorageVariant::operator =(CLSID const *pcid)
{
    CAllocStorageVariant::SetCLSID(pcid, CoTaskAllocator);
    return(*this);
}


inline void *
CStorageVariant::operator new(size_t size)
{
    void *p = CoTaskMemAlloc(size);

    return(p);
}


inline void *
CStorageVariant::operator new(size_t size, void *p)
{
    return(p);
}


inline void
CStorageVariant::operator delete(void *p)
{
    if (p != NULL)
    {
        CoTaskMemFree(p);
    }
}


inline
CStorageVariant::CStorageVariant(CStorageVariant const &var)
{
    new (this) CStorageVariant((PROPVARIANT &) var);
}

#endif // __STGVAR_HXX__