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