xine-lib  1.2.10
iunk.h
Go to the documentation of this file.
1 #ifndef DS_IUNK_H
2 #define DS_IUNK_H
3 
4 #include "guids.h"
5 
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);
10 
11 #define DECLARE_IUNKNOWN() \
12  int refcount;
13 
14 #define IMPLEMENT_IUNKNOWN(CLASSNAME) \
15 static long STDCALL CLASSNAME ## _QueryInterface(IUnknown * This, \
16  const GUID* riid, void **ppvObject) \
17 { \
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))) \
24  { \
25  me->vt->AddRef((IUnknown*)This); \
26  *ppvObject=This; \
27  return 0; \
28  } \
29  Debug printf("Query failed! (GUID: 0x%x)\n", *(const unsigned int*)riid); \
30  return E_NOINTERFACE; \
31 } \
32  \
33 static long STDCALL CLASSNAME ## _AddRef(IUnknown * This) \
34 { \
35  CLASSNAME * me=( CLASSNAME *)This; \
36  Debug printf(#CLASSNAME "_AddRef(%p) called (ref:%d)\n", This, me->refcount); \
37  return ++(me->refcount); \
38 } \
39  \
40 static long STDCALL CLASSNAME ## _Release(IUnknown * This) \
41 { \
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); \
46  return 0; \
47 }
48 
49 #endif /* DS_IUNK_H */
guids.h