-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomstuff.h
61 lines (51 loc) · 1.36 KB
/
comstuff.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
#ifndef COMUTIL_H
#define COMUTIL_H
#include <comip.h>
#include <comdef.h>
#include <QObject>
template<typename T>
class RegisterMetatype {
int reg_id;
public:
RegisterMetatype() {
reg_id = qRegisterMetaType<T>();
}
const int id() const { return reg_id; }
};
#define REGISTER_METATYPE(typ) \
namespace MetaTypeId { \
static RegisterMetatype<typ> typ; \
}
#define COM_SMARTPTR(typ) \
_COM_SMARTPTR_TYPEDEF(typ, __uuidof(typ))
#define COM_IMPL_REFCOUNT(typ) \
ULONG STDMETHODCALLTYPE typ::AddRef() { \
return InterlockedIncrement(&refcount); \
} \
\
ULONG STDMETHODCALLTYPE typ::Release() { \
ULONG ulRef = InterlockedDecrement(&refcount); \
if (0 == ulRef) { \
delete this; \
} \
return ulRef; \
}
#define COM_IMPL_QUERYINTERFACE(typ, calls) \
HRESULT STDMETHODCALLTYPE typ::QueryInterface(REFIID riid, void **ppvInterface) { \
if (IID_IUnknown == riid) { \
AddRef(); \
*ppvInterface = (IUnknown*)this; \
} \
calls \
else { \
*ppvInterface = NULL; \
return E_NOINTERFACE; \
} \
return S_OK; \
}
#define COM_IMPL_QICASE(iid) \
else if (__uuidof(iid) == riid) { \
AddRef(); \
*ppvInterface = (iid*)this; \
}
#endif // COMUTIL_H