ReactOS  0.4.14-dev-57-g333b8f1
unknownbase.h
Go to the documentation of this file.
1 #ifndef APITESTS_UNKNOWNBASE_H
2 #define APITESTS_UNKNOWNBASE_H
3 
4 template<typename Interface>
5 class CUnknownBase : public Interface
6 {
9 protected:
10  virtual const QITAB* GetQITab() = 0;
11 public:
12 
13  CUnknownBase(bool autoDelete = true, LONG initialRef = 0)
14  : m_lRef(initialRef),
15  m_AutoDelete(autoDelete)
16  {
17  }
18 
20  {
21  return InterlockedIncrement( &m_lRef );
22  }
23 
25  {
26  long newref = InterlockedDecrement( &m_lRef );
27  if (m_AutoDelete && newref<=0)
28  {
29  delete this;
30  }
31  return newref;
32  }
33 
35  {
36  return QISearch(this, GetQITab(), riid, ppv);
37  }
38 
39  virtual ~CUnknownBase() {}
40 
41  LONG GetRef() const
42  {
43  return m_lRef;
44  }
45 };
46 
47 #endif // APITESTS_UNKNOWNBASE_H
#define REFIID
Definition: guiddef.h:118
bool m_AutoDelete
Definition: unknownbase.h:8
REFIID riid
Definition: precomp.h:44
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT WINAPI QISearch(void *base, const QITAB *table, REFIID riid, void **ppv)
Definition: ordinal.c:2343
CUnknownBase(bool autoDelete=true, LONG initialRef=0)
Definition: unknownbase.h:13
long LONG
Definition: pedump.c:60
virtual const QITAB * GetQITab()=0
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
LONG HRESULT
Definition: typedefs.h:77
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
ULONG STDMETHODCALLTYPE AddRef()
Definition: unknownbase.h:19
#define InterlockedDecrement
Definition: armddk.h:52
#define InterlockedIncrement
Definition: armddk.h:53
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppv)
Definition: unknownbase.h:34
ULONG STDMETHODCALLTYPE Release()
Definition: unknownbase.h:24
unsigned int ULONG
Definition: retypes.h:1
virtual ~CUnknownBase()
Definition: unknownbase.h:39
LONG GetRef() const
Definition: unknownbase.h:41