IMFAttributes::Get○○系関数が、ポインタを引数に渡してそのポインタに値を渡し、
戻り値はエラーコードという、微妙は使用なので簡易ラッパーを作ってみました。
とりあえず、本来の戻り値がエラーだった場合その値をそのまま例外として投げるようにして、
通常は取得した値を戻り値で返すようにしてみました。
//——————–
// ヘッダファイル AttributesWrapper.h
#pragma once
#include
#include
#include
#include
struct IMFAttributes;
namespace MFTools
{
class AttributesWrapper
{
public:
AttributesWrapper(unsigned int cInitialSize =1);
AttributesWrapper(IMFAttributes* const pAttr,bool IsCallRelease =true);
~AttributesWrapper(void);
MF_ATTRIBUTE_TYPE GetItemType(const GUID& guidkey)const;
void DeleteAllItems();
void DeleteItem(const GUID& guidkey);
unsigned int GetCount()const;
//----------------------------------
std::vector GetBlob(const GUID& guidkey)const;
void SetBlob(const GUID& guidkey, const unsigned char*const pBuf,
unsigned int size);
void SetBlob(const GUID& guidkey,const std::vector& vec);
unsigned int GetBlobSize(const GUID& guidkey)const;
std::wstring GetString(const GUID& guidkey)const;
void SetString(const GUID& guidkey,const wchar_t*const str);
void SetString(const GUID& guidkey,const std::wstring& str );
unsigned int GetStringLength(const GUID& guidkey)const;
//-----------------------------------
double GetDouble(const GUID& guidkey)const;
void SetDouble(const GUID& guidkey,double value);
GUID GetGUID(const GUID& guidkey)const;
void SetGUID(const GUID& guidkey,const GUID& value);
unsigned int GetUINT32(const GUID& guidkey)const;
void SetUINT32(const GUID& guidkey,unsigned int);
UINT64 GetUINT64(const GUID& guidkey)const;
void SetUINT64(const GUID& guidkey,UINT64 value);
void SetUnknown(const GUID& guidkey,IUnknown *const pUnknown);
void* const GetUnknown(const GUID& guidkey,const IID &riid)const;
private:
IMFAttributes* pAttr_;
bool isCallRelease_;
};
}
//——————————————
// cppファイル AttributesWrapper.cpp
#include "AttributesWrapper.h"
#include // Mfuuid.lib
#include // Mfplat.lib
namespace MFTools
{
AttributesWrapper::AttributesWrapper(unsigned int cInitialSize)
:pAttr_(nullptr),isCallRelease_(true)
{
HRESULT hr = MFCreateAttributes(&pAttr_,cInitialSize);
if(FAILED(hr))
{
throw hr;
}
}
AttributesWrapper::AttributesWrapper(IMFAttributes* const pAttr,bool IsCallRelease)
:pAttr_(pAttr),isCallRelease_(IsCallRelease)
{
}
AttributesWrapper::~AttributesWrapper()
{
if(isCallRelease_)
{
pAttr_->Release();
}
}
MF_ATTRIBUTE_TYPE AttributesWrapper::GetItemType(const GUID& guidkey)const
{
MF_ATTRIBUTE_TYPE type;
HRESULT hr = pAttr_->GetItemType(guidkey,&type);
if(FAILED(hr))
{
throw hr;
}
return type;
}
void AttributesWrapper::DeleteAllItems()
{
pAttr_->DeleteAllItems();
}
void AttributesWrapper::DeleteItem(const GUID& guidkey)
{
pAttr_->DeleteItem(guidkey);
}
unsigned int AttributesWrapper::GetCount()const
{
unsigned int count =0;
HRESULT hr = pAttr_->GetCount(&count);
return count;
}
//--------------------
std::vector AttributesWrapper::GetBlob(const GUID& guidkey)const
{
unsigned char * pBuf=nullptr;
unsigned int size;
HRESULT hr = pAttr_->GetAllocatedBlob(guidkey,&pBuf,&size);
if(FAILED(hr))
{
throw hr;
}
std::vector v(pBuf,pBuf+size);
CoTaskMemFree(pBuf);
return v;
}
void AttributesWrapper::SetBlob(const GUID& guidkey,const unsigned char*const pBuf,unsigned int size)
{
pAttr_->SetBlob(guidkey,pBuf,size);
}
void AttributesWrapper::SetBlob(const GUID& guidkey,const std::vector& buf)
{
pAttr_->SetBlob(guidkey,&(buf[0]),buf.size());
}
unsigned int AttributesWrapper::GetBlobSize(const GUID& guidkey)const
{
unsigned int size =0;
HRESULT hr = pAttr_->GetBlobSize(guidkey,&size);
if(FAILED(hr))
{
throw hr;
}
return size;
}
//--------------------
/// @brief 文字列の長さを取得(NULL文字を含まない)
std::wstring AttributesWrapper::GetString(const GUID& guidkey)const
{
wchar_t * str = nullptr;
unsigned int size =0;
HRESULT hr = pAttr_->GetAllocatedString(guidkey,&str,&size);
if(FAILED(hr))
{
throw hr;
}
std::wstring w(str);
CoTaskMemFree(str);
return w;
}
void AttributesWrapper::SetString(const GUID& guidkey,const wchar_t* const str)
{
pAttr_->SetString(guidkey,str);
}
void AttributesWrapper::SetString(const GUID& guidkey,const std::wstring& str)
{
pAttr_->SetString(guidkey,str.c_str());
}
unsigned int AttributesWrapper::GetStringLength(const GUID& guidkey)const
{
unsigned int size =0;
HRESULT hr = pAttr_->GetStringLength(guidkey,&size);
if(FAILED(hr))
{
throw hr;
}
return size;
}
//--------------------
double AttributesWrapper::GetDouble(const GUID& guidkey)const
{
double val=0;
HRESULT hr = pAttr_->GetDouble(guidkey,&val);
if(FAILED(hr))
{
throw hr;
}
return val;
}
void AttributesWrapper::SetDouble(const GUID& guidkey,double value)
{
pAttr_->SetDouble(guidkey,value);
}
GUID AttributesWrapper::GetGUID(const GUID& guidkey)const
{
GUID val;
HRESULT hr = pAttr_->GetGUID(guidkey,&val);
if(FAILED(hr))
{
throw hr;
}
return val;
}
void AttributesWrapper::SetGUID(const GUID& guidkey,const GUID& value)
{
pAttr_->SetGUID(guidkey,value);
}
unsigned int AttributesWrapper::GetUINT32(const GUID& guidkey)const
{
unsigned int val=0;
HRESULT hr = pAttr_->GetUINT32(guidkey,&val);
if(FAILED(hr))
{
throw hr;
}
return val;
}
void AttributesWrapper::SetUINT32(const GUID& guidkey,unsigned int value)
{
pAttr_->SetUINT32(guidkey,value);
}
UINT64 AttributesWrapper::GetUINT64(const GUID& guidkey)const
{
UINT64 val=0;
HRESULT hr = pAttr_->GetUINT64(guidkey,&val);
if(FAILED(hr))
{
throw hr;
}
return val;
}
void AttributesWrapper::SetUINT64(const GUID& guidkey,UINT64 value)
{
pAttr_->SetUINT64(guidkey,value);
}
void AttributesWrapper::SetUnknown(const GUID& guidkey,IUnknown *const pUnknown)
{
pAttr_->SetUnknown(guidkey,pUnknown);
}
void* const AttributesWrapper::GetUnknown(const GUID& guidkey,const IID &riid)const
{
void* val=0;
HRESULT hr = pAttr_->GetUnknown(guidkey,riid,&val);
if(FAILED(hr))
{
throw hr;
}
return val;
}
}