-
Notifications
You must be signed in to change notification settings - Fork 1
/
comimpl.h
88 lines (70 loc) · 2.31 KB
/
comimpl.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef ULT_COMIMPL_H_
#define ULT_COMIMPL_H_
#include <Windows.h>
#ifndef RETURN_IF_FAILED
#define RETURN_IF_FAILED(x) { HRESULT __result_ = (x); if (FAILED(__result_)) return __result_; }
#endif
namespace ult
{
class UnknownImpl
{
public:
UnknownImpl(): ref_count_(0) {}
protected:
ULONG ref_count_;
};
}
#define ULT_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \
(REFGUID iid, void **ppobj) {
#define ULT_QUERYINTERFACE_ENTRY(i) else if (iid == IID_ ## i) \
{ *ppobj = (void *)(i *)this; AddRef(); return S_OK; }
#define ULT_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \
{ *ppobj = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; }
#define ULT_QUERYINTERFACE_BEGIN2(i) ULT_QUERYINTERFACE_BEGIN \
ULT_QUERYINTERFACE_ENTRY_UNKNOWN(i) \
ULT_QUERYINTERFACE_ENTRY(i)
#define ULT_QUERYINTERFACE_END return E_NOINTERFACE; }
#define ULT_ADDREF_RELEASE \
STDMETHOD_(ULONG, AddRef)() { return ++ref_count_; } \
STDMETHOD_(ULONG, Release)() { if (--ref_count_ != 0) \
return ref_count_; delete this; return 0; }
#define ULT_UNKNOWN_IMP_SPEC(i) \
ULT_QUERYINTERFACE_BEGIN \
i \
ULT_QUERYINTERFACE_END \
ULT_ADDREF_RELEASE
#define ULT_UNKNOWN_IMP ULT_QUERYINTERFACE_BEGIN \
ULT_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \
ULT_QUERYINTERFACE_END \
ULT_ADDREF_RELEASE
#define ULT_UNKNOWN_IMP1(i) ULT_UNKNOWN_IMP_SPEC( \
ULT_QUERYINTERFACE_ENTRY_UNKNOWN(i) \
ULT_QUERYINTERFACE_ENTRY(i) \
)
#define ULT_UNKNOWN_IMP2(i1, i2) ULT_UNKNOWN_IMP_SPEC( \
ULT_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
ULT_QUERYINTERFACE_ENTRY(i1) \
ULT_QUERYINTERFACE_ENTRY(i2) \
)
#define ULT_UNKNOWN_IMP3(i1, i2, i3) ULT_UNKNOWN_IMP_SPEC( \
ULT_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
ULT_QUERYINTERFACE_ENTRY(i1) \
ULT_QUERYINTERFACE_ENTRY(i2) \
ULT_QUERYINTERFACE_ENTRY(i3) \
)
#define ULT_UNKNOWN_IMP4(i1, i2, i3, i4) ULT_UNKNOWN_IMP_SPEC( \
ULT_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
ULT_QUERYINTERFACE_ENTRY(i1) \
ULT_QUERYINTERFACE_ENTRY(i2) \
ULT_QUERYINTERFACE_ENTRY(i3) \
ULT_QUERYINTERFACE_ENTRY(i4) \
)
#define ULT_UNKNOWN_IMP5(i1, i2, i3, i4, i5) ULT_UNKNOWN_IMP_SPEC( \
ULT_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \
ULT_QUERYINTERFACE_ENTRY(i1) \
ULT_QUERYINTERFACE_ENTRY(i2) \
ULT_QUERYINTERFACE_ENTRY(i3) \
ULT_QUERYINTERFACE_ENTRY(i4) \
ULT_QUERYINTERFACE_ENTRY(i5) \
)
#endif