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

#endif