2 ReactOS Kernel-Mode COM
3 IUnknown implementations
5 This file is in the public domain.
16 /* Helper macro to enable gcc's extension. */
17 #ifndef __GNU_EXTENSION
19 #define __GNU_EXTENSION __extension__
21 #define __GNU_EXTENSION
25 /* ===============================================================
26 INonDelegatingUnknown interface
29 DECLARE_INTERFACE(INonDelegatingUnknown
)
31 STDMETHOD_(NTSTATUS
, NonDelegatingQueryInterface
)( THIS_
35 STDMETHOD_(ULONG
, NonDelegatingAddRef
)( THIS
) PURE
;
36 STDMETHOD_(ULONG
, NonDelegatingRelease
)( THIS
) PURE
;
39 typedef INonDelegatingUnknown
*PNONDELEGATINGUNKNOWN
;
42 /* ===============================================================
43 CUnknown declaration / definition
45 There are 2 variants for this, and I'm not sure if the C
51 class CUnknown
: public INonDelegatingUnknown
55 PUNKNOWN m_outer_unknown
;
59 CUnknown(PUNKNOWN pUnknownOuter
);
62 PUNKNOWN
GetOuterUnknown()
63 { return m_outer_unknown
; }
65 /* INonDelegatingUnknown */
66 STDMETHODIMP_(ULONG
) NonDelegatingAddRef();
67 STDMETHODIMP_(ULONG
) NonDelegatingRelease();
69 STDMETHODIMP_(NTSTATUS
) NonDelegatingQueryInterface(
74 #define DECLARE_STD_UNKNOWN() \
75 STDMETHODIMP_(NTSTATUS) NonDelegatingQueryInterface( \
79 STDMETHODIMP_(NTSTATUS) QueryInterface( \
83 return GetOuterUnknown()->QueryInterface(riid, ppv); \
86 STDMETHODIMP_(ULONG) AddRef() \
88 return GetOuterUnknown()->AddRef(); \
91 STDMETHODIMP_(ULONG) Release() \
93 return GetOuterUnknown()->Release(); \
96 #define DEFINE_STD_CONSTRUCTOR(classname) \
97 classname(PUNKNOWN outer_unknown) \
98 : CUnknown(outer_unknown) \
101 #else /* Not C++ - this is probably very buggy... */
105 Unknown_QueryInterface(
113 IUnknown
* unknown_this
);
118 IUnknown
* unknown_this
);
120 typedef struct CUnknown
122 __GNU_EXTENSION
union
125 INonDelegatingUnknown INonDelegatingUnknown
;
129 PUNKNOWN m_outer_unknown
;
132 #endif /* __cplusplus */
139 /* ===============================================================
143 #define QICAST(typename) \
144 PVOID( (typename) (this) )
146 #define QICASTUNKNOWN(typename) \
147 PVOID( PUNKNOWN( (typename) (this) ) )
149 #define STD_CREATE_BODY_WITH_TAG_(classname, unknown, outer_unknown, pool_type, tag, base) \
150 classname *new_ptr = new(pool_type, tag) classname(outer_unknown); \
153 return STATUS_INSUFFICIENT_RESOURCES; \
155 *unknown = PUNKNOWN((base)(new_ptr)); \
156 (*unknown)->AddRef(); \
157 return STATUS_SUCCESS
159 #define STD_CREATE_BODY_WITH_TAG(classname, unknown, outer_unknown, pool_type, tag, base) \
160 STD_CREATE_BODY_WITH_TAG_(classname, unknown, outer_unknown, pool_type, tag, PUNKNOWN)
162 #define STD_CREATE_BODY_(classname, unknown, outer_unknown, pool_type, base) \
163 STD_CREATE_BODY_WITH_TAG_(classname, unknown, outer_unknown, pool_type, 'rCcP', base)
165 #define STD_CREATE_BODY(classname, unknown, outer_unknown, pool_type) \
166 STD_CREATE_BODY_(classname, unknown, outer_unknown, pool_type, PUNKNOWN)
169 /* ===============================================================
170 Custom "new" and "delete" C++ operators
173 #ifndef _NEW_DELETE_OPERATORS_
174 #define _NEW_DELETE_OPERATORS_
184 result
= ExAllocatePoolWithTag(pool_type
, size
, tag
);
187 RtlZeroMemory(result
, size
);
197 return KCOM_New(size
, pool_type
, 'wNcP');
206 return KCOM_New(size
, pool_type
, tag
);
216 #endif /* ALLOCATION_OPERATORS_DEFINED */
219 #else /* Being compiled with C */
222 #endif /* __cplusplus */
224 #endif /* include guard */