2 ReactOS Kernel-Mode COM
3 IUnknown implementations
5 This file is in the public domain.
16 /* ===============================================================
17 INonDelegatingUnknown interface
20 DECLARE_INTERFACE(INonDelegatingUnknown
)
22 STDMETHOD_(NTSTATUS
, NonDelegatingQueryInterface
)( THIS_
26 STDMETHOD_(ULONG
, NonDelegatingAddRef
)( THIS
) PURE
;
27 STDMETHOD_(ULONG
, NonDelegatingRelease
)( THIS
) PURE
;
30 typedef INonDelegatingUnknown
*PNONDELEGATINGUNKNOWN
;
33 /* ===============================================================
34 CUnknown declaration / definition
36 There are 2 variants for this, and I'm not sure if the C
42 class CUnknown
: public INonDelegatingUnknown
46 PUNKNOWN m_outer_unknown
;
50 CUnknown(PUNKNOWN pUnknownOuter
);
53 PUNKNOWN
GetOuterUnknown()
54 { return m_outer_unknown
; }
56 /* INonDelegatingUnknown */
57 STDMETHODIMP_(ULONG
) NonDelegatingAddRef();
58 STDMETHODIMP_(ULONG
) NonDelegatingRelease();
60 STDMETHODIMP_(NTSTATUS
) NonDelegatingQueryInterface(
65 #define DECLARE_STD_UNKNOWN() \
66 STDMETHODIMP_(NTSTATUS) NonDelegatingQueryInterface( \
70 STDMETHODIMP_(NTSTATUS) QueryInterface( \
74 return GetOuterUnknown()->QueryInterface(riid, ppv); \
77 STDMETHODIMP_(ULONG) AddRef() \
79 return GetOuterUnknown()->AddRef(); \
82 STDMETHODIMP_(ULONG) Release() \
84 return GetOuterUnknown()->Release(); \
87 #define DEFINE_STD_CONSTRUCTOR(classname) \
88 classname(PUNKNOWN outer_unknown) \
89 : CUnknown(outer_unknown) \
92 #else /* Not C++ - this is probably very buggy... */
96 Unknown_QueryInterface(
104 IUnknown
* unknown_this
);
109 IUnknown
* unknown_this
);
111 typedef struct CUnknown
113 __GNU_EXTENSION
union
116 INonDelegatingUnknown INonDelegatingUnknown
;
120 PUNKNOWN m_outer_unknown
;
123 #endif /* __cplusplus */
130 /* ===============================================================
134 #define QICAST(typename) \
135 PVOID( (typename) (this) )
137 #define QICASTUNKNOWN(typename) \
138 PVOID( PUNKNOWN( (typename) (this) ) )
140 #define STD_CREATE_BODY_WITH_TAG_(classname, unknown, outer_unknown, pool_type, tag, base) \
141 classname *new_ptr = new(pool_type, tag) classname(outer_unknown); \
144 return STATUS_INSUFFICIENT_RESOURCES; \
146 *unknown = PUNKNOWN((base)(new_ptr)); \
147 (*unknown)->AddRef(); \
148 return STATUS_SUCCESS
150 #define STD_CREATE_BODY_WITH_TAG(classname, unknown, outer_unknown, pool_type, tag, base) \
151 STD_CREATE_BODY_WITH_TAG_(classname, unknown, outer_unknown, pool_type, tag, PUNKNOWN)
153 #define STD_CREATE_BODY_(classname, unknown, outer_unknown, pool_type, base) \
154 STD_CREATE_BODY_WITH_TAG_(classname, unknown, outer_unknown, pool_type, 'rCcP', base)
156 #define STD_CREATE_BODY(classname, unknown, outer_unknown, pool_type) \
157 STD_CREATE_BODY_(classname, unknown, outer_unknown, pool_type, PUNKNOWN)
160 /* ===============================================================
161 Custom "new" and "delete" C++ operators
164 #ifndef _NEW_DELETE_OPERATORS_
165 #define _NEW_DELETE_OPERATORS_
175 result
= ExAllocatePoolWithTag(pool_type
, size
, tag
);
178 RtlZeroMemory(result
, size
);
188 return KCOM_New(size
, pool_type
, 'wNcP');
197 return KCOM_New(size
, pool_type
, tag
);
207 #endif /* ALLOCATION_OPERATORS_DEFINED */
210 #else /* Being compiled with C */
213 #endif /* __cplusplus */
215 #endif /* include guard */