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