• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Windows/PropVariant.h
2 
3 #ifndef __WINDOWS_PROP_VARIANT_H
4 #define __WINDOWS_PROP_VARIANT_H
5 
6 #include "../Common/MyTypes.h"
7 #include "../Common/MyWindows.h"
8 #include "../Common/MyString.h"
9 
10 namespace NWindows {
11 namespace NCOM {
12 
13 BSTR AllocBstrFromAscii(const char *s) throw();
14 
15 HRESULT PropVariant_Clear(PROPVARIANT *p) throw();
16 
17 HRESULT PropVarEm_Alloc_Bstr(PROPVARIANT *p, unsigned numChars) throw();
18 HRESULT PropVarEm_Set_Str(PROPVARIANT *p, const char *s) throw();
19 
PropVarEm_Set_UInt32(PROPVARIANT * p,UInt32 v)20 inline void PropVarEm_Set_UInt32(PROPVARIANT *p, UInt32 v) throw()
21 {
22   p->vt = VT_UI4;
23   p->ulVal = v;
24 }
25 
PropVarEm_Set_UInt64(PROPVARIANT * p,UInt64 v)26 inline void PropVarEm_Set_UInt64(PROPVARIANT *p, UInt64 v) throw()
27 {
28   p->vt = VT_UI8;
29   p->uhVal.QuadPart = v;
30 }
31 
PropVarEm_Set_FileTime64(PROPVARIANT * p,UInt64 v)32 inline void PropVarEm_Set_FileTime64(PROPVARIANT *p, UInt64 v) throw()
33 {
34   p->vt = VT_FILETIME;
35   p->filetime.dwLowDateTime = (DWORD)v;
36   p->filetime.dwHighDateTime = (DWORD)(v >> 32);
37 }
38 
PropVarEm_Set_Bool(PROPVARIANT * p,bool b)39 inline void PropVarEm_Set_Bool(PROPVARIANT *p, bool b) throw()
40 {
41   p->vt = VT_BOOL;
42   p->boolVal = (b ? VARIANT_TRUE : VARIANT_FALSE);
43 }
44 
45 
46 class CPropVariant : public tagPROPVARIANT
47 {
48 public:
CPropVariant()49   CPropVariant()
50   {
51     vt = VT_EMPTY;
52     wReserved1 = 0;
53     // wReserved2 = 0;
54     // wReserved3 = 0;
55     // uhVal.QuadPart = 0;
56     bstrVal = 0;
57   }
throw()58   ~CPropVariant() throw() { Clear(); }
59   CPropVariant(const PROPVARIANT &varSrc);
60   CPropVariant(const CPropVariant &varSrc);
61   CPropVariant(BSTR bstrSrc);
62   CPropVariant(LPCOLESTR lpszSrc);
CPropVariant(bool bSrc)63   CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); }
CPropVariant(Byte value)64   CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }
65 
66 private:
67   CPropVariant(Int16 value); // { vt = VT_I2; wReserved1 = 0; iVal = value; }
68   CPropVariant(Int32 value); // { vt = VT_I4; wReserved1 = 0; lVal = value; }
69 
70 public:
CPropVariant(UInt32 value)71   CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }
CPropVariant(UInt64 value)72   CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal.QuadPart = value; }
CPropVariant(Int64 value)73   CPropVariant(Int64 value) { vt = VT_I8; wReserved1 = 0; hVal.QuadPart = value; }
CPropVariant(const FILETIME & value)74   CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }
75 
76   CPropVariant& operator=(const CPropVariant &varSrc);
77   CPropVariant& operator=(const PROPVARIANT &varSrc);
78   CPropVariant& operator=(BSTR bstrSrc);
79   CPropVariant& operator=(LPCOLESTR lpszSrc);
80   CPropVariant& operator=(const UString &s);
81   CPropVariant& operator=(const UString2 &s);
82   CPropVariant& operator=(const char *s);
83 
84   CPropVariant& operator=(bool bSrc) throw();
85   CPropVariant& operator=(Byte value) throw();
86 
87 private:
88   CPropVariant& operator=(Int16 value) throw();
89 
90 public:
91   CPropVariant& operator=(Int32 value) throw();
92   CPropVariant& operator=(UInt32 value) throw();
93   CPropVariant& operator=(UInt64 value) throw();
94   CPropVariant& operator=(Int64 value) throw();
95   CPropVariant& operator=(const FILETIME &value) throw();
96 
97   BSTR AllocBstr(unsigned numChars);
98 
99   HRESULT Clear() throw();
100   HRESULT Copy(const PROPVARIANT *pSrc) throw();
101   HRESULT Attach(PROPVARIANT *pSrc) throw();
102   HRESULT Detach(PROPVARIANT *pDest) throw();
103 
104   HRESULT InternalClear() throw();
105   void InternalCopy(const PROPVARIANT *pSrc);
106 
107   int Compare(const CPropVariant &a) throw();
108 };
109 
110 }}
111 
112 #endif
113