mirror of
https://github.com/reactos/reactos.git
synced 2024-11-09 16:20:37 +00:00
52e13410cb
- Make CUnknownBase constructor parameters optional svn path=/trunk/; revision=68199
47 lines
935 B
C++
47 lines
935 B
C++
#ifndef APITESTS_UNKNOWNBASE_H
|
|
#define APITESTS_UNKNOWNBASE_H
|
|
|
|
template<typename Interface>
|
|
class CUnknownBase : public Interface
|
|
{
|
|
LONG m_lRef;
|
|
bool m_AutoDelete;
|
|
protected:
|
|
virtual const QITAB* GetQITab() = 0;
|
|
public:
|
|
|
|
CUnknownBase(bool autoDelete = true, LONG initialRef = 0)
|
|
: m_lRef(initialRef),
|
|
m_AutoDelete(autoDelete)
|
|
{
|
|
}
|
|
|
|
ULONG STDMETHODCALLTYPE AddRef ()
|
|
{
|
|
return InterlockedIncrement( &m_lRef );
|
|
}
|
|
|
|
ULONG STDMETHODCALLTYPE Release()
|
|
{
|
|
long newref = InterlockedDecrement( &m_lRef );
|
|
if (m_AutoDelete && newref<=0)
|
|
{
|
|
delete this;
|
|
}
|
|
return newref;
|
|
}
|
|
|
|
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv)
|
|
{
|
|
return QISearch(this, GetQITab(), riid, ppv);
|
|
}
|
|
|
|
virtual ~CUnknownBase() {}
|
|
|
|
LONG GetRef() const
|
|
{
|
|
return m_lRef;
|
|
}
|
|
};
|
|
|
|
#endif // APITESTS_UNKNOWNBASE_H
|