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