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 "interfaces.h"
|
|
|
|
#include "guids.h"
|
2001-08-16 00:50:02 +00:00
|
|
|
|
2001-03-20 00:05:27 +00:00
|
|
|
#define DECLARE_IUNKNOWN(CLASSNAME) \
|
|
|
|
int refcount; \
|
2001-08-16 00:50:02 +00:00
|
|
|
static long STDCALL QueryInterface(IUnknown * This, GUID* riid, void **ppvObject); \
|
2001-03-20 00:05:27 +00:00
|
|
|
static long STDCALL AddRef (IUnknown * This); \
|
|
|
|
static long STDCALL Release (IUnknown * This);
|
|
|
|
|
|
|
|
#define IMPLEMENT_IUNKNOWN(CLASSNAME) \
|
2001-08-16 00:50:02 +00:00
|
|
|
long STDCALL CLASSNAME ::QueryInterface(IUnknown * This, GUID* riid, void **ppvObject) \
|
2001-03-20 00:05:27 +00:00
|
|
|
{ \
|
|
|
|
Debug printf(#CLASSNAME "::QueryInterface() called\n");\
|
2001-08-16 00:50:02 +00:00
|
|
|
if (!ppvObject) return 0x80004003; \
|
|
|
|
CLASSNAME * me = (CLASSNAME *)This; \
|
|
|
|
unsigned int i = 0; \
|
2001-03-20 00:05:27 +00:00
|
|
|
for(const GUID* r=me->interfaces; i<sizeof(CLASSNAME ::interfaces)/sizeof(CLASSNAME ::interfaces[0]); r++, i++) \
|
|
|
|
if(!memcmp(r, riid, 16)) \
|
|
|
|
{ \
|
|
|
|
This->vt->AddRef((IUnknown*)This); \
|
|
|
|
*ppvObject=This; \
|
|
|
|
return 0; \
|
|
|
|
} \
|
|
|
|
Debug printf("Failed\n"); \
|
2001-08-16 00:50:02 +00:00
|
|
|
return E_NOINTERFACE; \
|
2001-03-20 00:05:27 +00:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
long STDCALL CLASSNAME ::AddRef ( \
|
|
|
|
IUnknown * This) \
|
|
|
|
{ \
|
|
|
|
Debug printf(#CLASSNAME "::AddRef() called\n"); \
|
|
|
|
CLASSNAME * me=( CLASSNAME *)This; \
|
|
|
|
return ++(me->refcount); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
long STDCALL CLASSNAME ::Release ( \
|
|
|
|
IUnknown * This) \
|
|
|
|
{ \
|
|
|
|
Debug printf(#CLASSNAME "::Release() called\n"); \
|
|
|
|
CLASSNAME* me=( CLASSNAME *)This; \
|
|
|
|
if(--(me->refcount) ==0) \
|
|
|
|
delete ( CLASSNAME *) This; \
|
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
|
2001-08-16 00:50:02 +00:00
|
|
|
#endif /* DS_IUNK_H */
|