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