1545
|
1 #ifndef DS_IUNK_H
|
|
2 #define DS_IUNK_H
|
|
3
|
168
|
4 #include "interfaces.h"
|
|
5 #include "guids.h"
|
1545
|
6
|
168
|
7 #define DECLARE_IUNKNOWN(CLASSNAME) \
|
|
8 int refcount; \
|
1545
|
9 static long STDCALL QueryInterface(IUnknown * This, GUID* riid, void **ppvObject); \
|
168
|
10 static long STDCALL AddRef (IUnknown * This); \
|
|
11 static long STDCALL Release (IUnknown * This);
|
|
12
|
|
13 #define IMPLEMENT_IUNKNOWN(CLASSNAME) \
|
1545
|
14 long STDCALL CLASSNAME ::QueryInterface(IUnknown * This, GUID* riid, void **ppvObject) \
|
168
|
15 { \
|
|
16 Debug printf(#CLASSNAME "::QueryInterface() called\n");\
|
1545
|
17 if (!ppvObject) return 0x80004003; \
|
|
18 CLASSNAME * me = (CLASSNAME *)This; \
|
|
19 unsigned int i = 0; \
|
168
|
20 for(const GUID* r=me->interfaces; i<sizeof(CLASSNAME ::interfaces)/sizeof(CLASSNAME ::interfaces[0]); r++, i++) \
|
|
21 if(!memcmp(r, riid, 16)) \
|
|
22 { \
|
|
23 This->vt->AddRef((IUnknown*)This); \
|
|
24 *ppvObject=This; \
|
|
25 return 0; \
|
|
26 } \
|
|
27 Debug printf("Failed\n"); \
|
1545
|
28 return E_NOINTERFACE; \
|
168
|
29 } \
|
|
30 \
|
|
31 long STDCALL CLASSNAME ::AddRef ( \
|
|
32 IUnknown * This) \
|
|
33 { \
|
|
34 Debug printf(#CLASSNAME "::AddRef() called\n"); \
|
|
35 CLASSNAME * me=( CLASSNAME *)This; \
|
|
36 return ++(me->refcount); \
|
|
37 } \
|
|
38 \
|
|
39 long STDCALL CLASSNAME ::Release ( \
|
|
40 IUnknown * This) \
|
|
41 { \
|
|
42 Debug printf(#CLASSNAME "::Release() called\n"); \
|
|
43 CLASSNAME* me=( CLASSNAME *)This; \
|
|
44 if(--(me->refcount) ==0) \
|
|
45 delete ( CLASSNAME *) This; \
|
|
46 return 0; \
|
|
47 }
|
|
48
|
1545
|
49 #endif /* DS_IUNK_H */
|