Visual C++ backend for rbuild (for now just a hacked mingw backend) and related compi...
[reactos.git] / base / shell / explorer-new / comcsup.h
1 #ifndef __COMCSUP_H
2 #define __COMCSUP_H
3
4 /*
5 ******************************************************************************
6 * This header is for easier generation of IUnknown interfaces for inherited *
7 * classes and for casts from the interface to the implementation and vice *
8 * versa. *
9 ******************************************************************************
10 */
11
12 /* Generates a Iiface::AddRef() method that forwards to Iimpl::AddRef() */
13 #define METHOD_IUNKNOWN_INHERITED_ADDREF_NAME(iface,impl) impl##Impl_##iface##_AddRef
14 #define METHOD_IUNKNOWN_INHERITED_ADDREF(iface,impl) \
15 static ULONG STDMETHODCALLTYPE \
16 impl##Impl_##iface##_AddRef(IN OUT iface *ifc) { \
17 impl##Impl *This = impl##Impl_from_##iface (ifc); \
18 impl *baseiface = impl##_from_##impl##Impl(This); \
19 return impl##Impl_AddRef(baseiface); \
20 }
21
22 /* Generates a Iiface::Release() method that forwards to Iimpl::Release() */
23 #define METHOD_IUNKNOWN_INHERITED_RELEASE_NAME(iface,impl) impl##Impl_##iface##_Release
24 #define METHOD_IUNKNOWN_INHERITED_RELEASE(iface,impl) \
25 static ULONG STDMETHODCALLTYPE \
26 impl##Impl_##iface##_Release(IN OUT iface *ifc) { \
27 impl##Impl *This = impl##Impl_from_##iface (ifc); \
28 impl *baseiface = impl##_from_##impl##Impl(This); \
29 return impl##Impl_AddRef(baseiface); \
30 }
31
32 /* Generates a Iiface::QueryInterface() method that forwards to Iimpl::QueryInterface() */
33 #define METHOD_IUNKNOWN_INHERITED_QUERYINTERFACE_NAME(iface,impl) impl##Impl_##iface##_QueryInterface
34 #define METHOD_IUNKNOWN_INHERITED_QUERYINTERFACE(iface,impl) \
35 static HRESULT STDMETHODCALLTYPE \
36 impl##Impl_##iface##_QueryInterface(IN OUT iface *ifc, IN REFIID riid, OUT VOID **ppvObject) { \
37 impl##Impl *This = impl##Impl_from_##iface (ifc); \
38 impl *baseiface = impl##_from_##impl##Impl(This); \
39 return impl##Impl_QueryInterface(baseiface, riid, ppvObject); \
40 }
41
42 /* Generates a Ixxx_from_IxxxImpl() and a IxxxImpl_from_Ixxx() inline function */
43 #define IMPL_CASTS(iface,impl,vtbl) \
44 static __inline iface * \
45 iface##_from_##impl##Impl (impl##Impl *This) { \
46 return (iface *)&This->vtbl; \
47 } \
48 static __inline impl##Impl * \
49 impl##Impl_from_##iface (iface *ifc) { \
50 return (impl##Impl *)((ULONG_PTR)ifc - FIELD_OFFSET(impl##Impl, vtbl)); \
51 }
52
53 #endif /* __COMCSUP_H */