PropVar.h
Upload User: geng8029
Upload Date: 2021-01-30
Package Size: 187k
Code Size: 3k
Category:

Audio program

Development Platform:

Visual C++

  1. #pragma once
  2. #include <propsys.h>
  3. #include <propvarutil.h>
  4. ///////////////////////////////////////////////////////////////////////////////
  5. //
  6. // PropVariant Class
  7. //
  8. // Wrapper class for PROPVARIANT types. 
  9. //
  10. // Notes: 
  11. //    This class offers accessor functions for a subset of the PROPVARIANT
  12. //    data types, designed to handle all of the types in actual use by 
  13. //    Media Foundation at this time.
  14. // 
  15. ///////////////////////////////////////////////////////////////////////////////
  16. class PropVariant : public PROPVARIANT
  17. {
  18. public:
  19.     PropVariant()
  20.     {
  21.         PropVariantInit(this);
  22.     }
  23.     ~PropVariant()
  24.     {
  25.         PropVariantClear(this);
  26.     }
  27.     void Clear()
  28.     {
  29.         PropVariantClear(this);
  30.     }
  31.     HRESULT SetBlob(DWORD cbSize, BYTE *pBuffer)    // VT_BLOB
  32.     {
  33.         Clear();
  34.         BYTE *pb = (BYTE*)CoTaskMemAlloc(cbSize);
  35.         if (pb == NULL)
  36.         {
  37.             return E_OUTOFMEMORY;
  38.         }
  39.         this->blob.cbSize = cbSize;
  40.         CopyMemory(this->blob.pBlobData, pBuffer, cbSize);
  41.         return S_OK;
  42.     }
  43.     HRESULT SetBOOL(BOOL val)   // VT_BOOL
  44.     { 
  45.         Clear();
  46.         return InitPropVariantFromBoolean(val, this); 
  47.     }             
  48.     HRESULT SetGUID(const GUID guid)    // VT_CLSID
  49.     {
  50.         Clear();
  51.         return InitPropVariantFromCLSID(guid, this);
  52.     }
  53.     HRESULT SetInt32(LONG val)  // VT_I4
  54.     {    
  55.         Clear();
  56.         return InitPropVariantFromInt32(val, this); 
  57.     }              
  58.     HRESULT SetString(const WCHAR *str) // VT_LPWSTR    
  59.     { 
  60.         return InitPropVariantFromString(str, this); 
  61.     }    
  62.     HRESULT SetStringVector(const WCHAR **ppstr, ULONG cElems)  // VT_LPWSTR | VT_VECTOR
  63.     {
  64.         Clear();
  65.         return InitPropVariantFromStringVector(ppstr, cElems, this);
  66.     }
  67.     HRESULT SetUInt32(ULONG val)    // VT_UI4
  68.     {
  69.         Clear();
  70.         return InitPropVariantFromUInt32(val, this); 
  71.     }           
  72.     HRESULT SetUInt32Vector(const ULONG *pVals, ULONG cElems)   // VT_UI4 | VT_VECTOR
  73.     {
  74.         Clear();
  75.         return InitPropVariantFromUInt32Vector(pVals, cElems, this);
  76.     }
  77.     HRESULT SetUnknown(IUnknown *pUnk)  // VT_UNKNOWN
  78.     {
  79.         if (pUnk == NULL) { return E_POINTER; }
  80.         Clear();
  81.         this->punkVal = pUnk;
  82.         this->punkVal->AddRef();
  83.         this->vt = VT_UNKNOWN;
  84.         return S_OK;
  85.     }
  86. private:
  87.     PropVariant& operator=(const PropVariant& var);
  88.     PropVariant(const PropVariant &var);
  89. };