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 20 inline void PropVarEm_Set_UInt32(PROPVARIANT *p, UInt32 v) throw() 21 { 22 p->vt = VT_UI4; 23 p->ulVal = v; 24 } 25 26 inline void PropVarEm_Set_UInt64(PROPVARIANT *p, UInt64 v) throw() 27 { 28 p->vt = VT_UI8; 29 p->uhVal.QuadPart = v; 30 } 31 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 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: 49 CPropVariant() 50 { 51 vt = VT_EMPTY; 52 wReserved1 = 0; 53 // wReserved2 = 0; 54 // wReserved3 = 0; 55 // uhVal.QuadPart = 0; 56 bstrVal = 0; 57 } 58 ~CPropVariant() throw() { Clear(); } 59 CPropVariant(const PROPVARIANT &varSrc); 60 CPropVariant(const CPropVariant &varSrc); 61 CPropVariant(BSTR bstrSrc); 62 CPropVariant(LPCOLESTR lpszSrc); 63 CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); } 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: 71 CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; } 72 CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal.QuadPart = value; } 73 CPropVariant(Int64 value) { vt = VT_I8; wReserved1 = 0; hVal.QuadPart = 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 CPropVariant& operator=(const AString &s) 84 { return (*this)=(const char *)s; } 85 86 CPropVariant& operator=(bool bSrc) throw(); 87 CPropVariant& operator=(Byte value) throw(); 88 89 private: 90 CPropVariant& operator=(Int16 value) throw(); 91 92 public: 93 CPropVariant& operator=(Int32 value) throw(); 94 CPropVariant& operator=(UInt32 value) throw(); 95 CPropVariant& operator=(UInt64 value) throw(); 96 CPropVariant& operator=(Int64 value) throw(); 97 CPropVariant& operator=(const FILETIME &value) throw(); 98 99 BSTR AllocBstr(unsigned numChars); 100 101 HRESULT Clear() throw(); 102 HRESULT Copy(const PROPVARIANT *pSrc) throw(); 103 HRESULT Attach(PROPVARIANT *pSrc) throw(); 104 HRESULT Detach(PROPVARIANT *pDest) throw(); 105 106 HRESULT InternalClear() throw(); 107 void InternalCopy(const PROPVARIANT *pSrc); 108 109 int Compare(const CPropVariant &a) throw(); 110 }; 111 112 }} 113 114 #endif 115