6#define INHERIT_IUNKNOWN() \
7 long STDCALL ( *QueryInterface )(IUnknown * This, const GUID* riid, void **ppvObject); \
8 long STDCALL ( *AddRef )(IUnknown * This); \
9 long STDCALL ( *Release )(IUnknown * This);
11#define DECLARE_IUNKNOWN() \
14#define IMPLEMENT_IUNKNOWN(CLASSNAME) \
15static long STDCALL CLASSNAME ## _QueryInterface(IUnknown * This, \
16 const GUID* riid, void **ppvObject) \
18 CLASSNAME * me = (CLASSNAME *)This; \
19 const GUID* r; unsigned int i = 0; \
20 Debug printf(#CLASSNAME "_QueryInterface(%p) called\n", This);\
21 if (!ppvObject) return E_POINTER; \
22 for(r=me->interfaces; i<sizeof(me->interfaces)/sizeof(me->interfaces[0]); r++, i++) \
23 if(!memcmp(r, riid, sizeof(*r))) \
25 me->vt->AddRef((IUnknown*)This); \
29 Debug printf("Query failed! (GUID: 0x%x)\n", *(const unsigned int*)riid); \
30 return E_NOINTERFACE; \
33static long STDCALL CLASSNAME ## _AddRef(IUnknown * This) \
35 CLASSNAME * me=( CLASSNAME *)This; \
36 Debug printf(#CLASSNAME "_AddRef(%p) called (ref:%d)\n", This, me->refcount); \
37 return ++(me->refcount); \
40static long STDCALL CLASSNAME ## _Release(IUnknown * This) \
42 CLASSNAME* me=( CLASSNAME *)This; \
43 Debug printf(#CLASSNAME "_Release(%p) called (new ref:%d)\n", This, me->refcount - 1); \
44 if(--(me->refcount) == 0) \
45 CLASSNAME ## _Destroy(me); \