forked from AdrianEddy/AIMPYouTube
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIUnknownInterfaceImpl.h
More file actions
48 lines (34 loc) · 925 Bytes
/
IUnknownInterfaceImpl.h
File metadata and controls
48 lines (34 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#include <Unknwn.h>
//! Helper implements IUnknown interface.
template <typename T>
class IUnknownInterfaceImpl : public T
{
public:
IUnknownInterfaceImpl()
: reference_count_(0)
{}
virtual ~IUnknownInterfaceImpl() {}
virtual HRESULT WINAPI QueryInterface(REFIID riid, LPVOID* ppvObj) {
if (!ppvObj) {
return E_POINTER;
}
if (IID_IUnknown == riid) {
*ppvObj = this;
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
virtual ULONG WINAPI AddRef(void)
{ return ++reference_count_; }
virtual ULONG WINAPI Release(void) {
ULONG reference_count = --reference_count_;
if (reference_count == 0) {
delete this;
}
return reference_count;
}
private:
ULONG reference_count_;
};