2001-08-16 00:50:02 +00:00
|
|
|
#ifndef DS_IUNK_H
|
|
|
|
#define DS_IUNK_H
|
|
|
|
|
2001-03-20 00:05:27 +00:00
|
|
|
#include "guids.h"
|
2001-11-21 19:12:39 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define INHERIT_IUNKNOWN() \
|
|
|
|
long STDCALL ( *QueryInterface )(IUnknown * This, GUID* riid, void **ppvObject); \
|
|
|
|
long STDCALL ( *AddRef )(IUnknown * This); \
|
|
|
|
long STDCALL ( *Release )(IUnknown * This);
|
|
|
|
|
|
|
|
#define DECLARE_IUNKNOWN() \
|
|
|
|
int refcount;
|
2001-08-16 00:50:02 +00:00
|
|
|
|
2001-03-20 00:05:27 +00:00
|
|
|
#define IMPLEMENT_IUNKNOWN(CLASSNAME) \
|
2001-11-21 19:12:39 +00:00
|
|
|
static long STDCALL CLASSNAME ## _QueryInterface(IUnknown * This, \
|
|
|
|
GUID* riid, void **ppvObject) \
|
2001-03-20 00:05:27 +00:00
|
|
|
{ \
|
2001-08-16 00:50:02 +00:00
|
|
|
CLASSNAME * me = (CLASSNAME *)This; \
|
2001-11-21 19:12:39 +00:00
|
|
|
GUID* r; unsigned int i = 0; \
|
|
|
|
Debug printf(#CLASSNAME "_QueryInterface(%p) called\n", This);\
|
|
|
|
if (!ppvObject) return 0x80004003; \
|
|
|
|
for(r=me->interfaces; i<sizeof(me->interfaces)/sizeof(me->interfaces[0]); r++, i++) \
|
|
|
|
if(!memcmp(r, riid, sizeof(*r))) \
|
2001-03-20 00:05:27 +00:00
|
|
|
{ \
|
2001-11-21 19:12:39 +00:00
|
|
|
me->vt->AddRef((IUnknown*)This); \
|
2001-03-20 00:05:27 +00:00
|
|
|
*ppvObject=This; \
|
|
|
|
return 0; \
|
|
|
|
} \
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("Query failed!\n"); \
|
2001-08-16 00:50:02 +00:00
|
|
|
return E_NOINTERFACE; \
|
2001-03-20 00:05:27 +00:00
|
|
|
} \
|
|
|
|
\
|
2001-11-21 19:12:39 +00:00
|
|
|
static long STDCALL CLASSNAME ## _AddRef(IUnknown * This) \
|
2001-03-20 00:05:27 +00:00
|
|
|
{ \
|
|
|
|
CLASSNAME * me=( CLASSNAME *)This; \
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf(#CLASSNAME "_AddRef(%p) called (ref:%d)\n", This, me->refcount); \
|
2001-03-20 00:05:27 +00:00
|
|
|
return ++(me->refcount); \
|
|
|
|
} \
|
|
|
|
\
|
2001-11-21 19:12:39 +00:00
|
|
|
static long STDCALL CLASSNAME ## _Release(IUnknown * This) \
|
2001-03-20 00:05:27 +00:00
|
|
|
{ \
|
|
|
|
CLASSNAME* me=( CLASSNAME *)This; \
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf(#CLASSNAME "_Release(%p) called (new ref:%d)\n", This, me->refcount - 1); \
|
|
|
|
if(--(me->refcount) == 0) \
|
|
|
|
CLASSNAME ## _Destroy(me); \
|
2001-03-20 00:05:27 +00:00
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
|
2001-08-16 00:50:02 +00:00
|
|
|
#endif /* DS_IUNK_H */
|