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