Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenstdunk.h
Go to the documentation of this file.
00001 /* 00002 ReactOS Kernel-Mode COM 00003 IUnknown implementations 00004 00005 This file is in the public domain. 00006 00007 AUTHORS 00008 Andrew Greenwood 00009 */ 00010 00011 #ifndef STDUNK_H 00012 #define STDUNK_H 00013 00014 #include <punknown.h> 00015 00016 /* =============================================================== 00017 INonDelegatingUnknown interface 00018 */ 00019 00020 DECLARE_INTERFACE(INonDelegatingUnknown) 00021 { 00022 STDMETHOD_(NTSTATUS, NonDelegatingQueryInterface)( THIS_ 00023 IN REFIID, 00024 OUT PVOID*) PURE; 00025 00026 STDMETHOD_(ULONG, NonDelegatingAddRef)( THIS ) PURE; 00027 STDMETHOD_(ULONG, NonDelegatingRelease)( THIS ) PURE; 00028 }; 00029 00030 typedef INonDelegatingUnknown *PNONDELEGATINGUNKNOWN; 00031 00032 00033 /* =============================================================== 00034 CUnknown declaration / definition 00035 00036 There are 2 variants for this, and I'm not sure if the C 00037 version is correct. 00038 */ 00039 00040 #ifdef __cplusplus 00041 00042 class CUnknown : public INonDelegatingUnknown 00043 { 00044 private : 00045 LONG m_ref_count; 00046 PUNKNOWN m_outer_unknown; 00047 00048 public : 00049 /* CUnknown */ 00050 CUnknown(PUNKNOWN pUnknownOuter); 00051 virtual ~CUnknown(); 00052 00053 PUNKNOWN GetOuterUnknown() 00054 { return m_outer_unknown; } 00055 00056 /* INonDelegatingUnknown */ 00057 STDMETHODIMP_(ULONG) NonDelegatingAddRef(); 00058 STDMETHODIMP_(ULONG) NonDelegatingRelease(); 00059 00060 STDMETHODIMP_(NTSTATUS) NonDelegatingQueryInterface( 00061 REFIID rIID, 00062 PVOID* ppVoid); 00063 }; 00064 00065 #define DECLARE_STD_UNKNOWN() \ 00066 STDMETHODIMP_(NTSTATUS) NonDelegatingQueryInterface( \ 00067 REFIID iid, \ 00068 PVOID* ppvObject); \ 00069 \ 00070 STDMETHODIMP_(NTSTATUS) QueryInterface( \ 00071 REFIID riid, \ 00072 void** ppv) \ 00073 { \ 00074 return GetOuterUnknown()->QueryInterface(riid, ppv); \ 00075 } \ 00076 \ 00077 STDMETHODIMP_(ULONG) AddRef() \ 00078 { \ 00079 return GetOuterUnknown()->AddRef(); \ 00080 } \ 00081 \ 00082 STDMETHODIMP_(ULONG) Release() \ 00083 { \ 00084 return GetOuterUnknown()->Release(); \ 00085 } 00086 00087 #define DEFINE_STD_CONSTRUCTOR(classname) \ 00088 classname(PUNKNOWN outer_unknown) \ 00089 : CUnknown(outer_unknown) \ 00090 { } 00091 00092 #else /* Not C++ - this is probably very buggy... */ 00093 00094 NTSTATUS 00095 STDMETHODCALLTYPE 00096 Unknown_QueryInterface( 00097 IUnknown* this, 00098 IN REFIID refiid, 00099 OUT PVOID* output); 00100 00101 ULONG 00102 STDMETHODCALLTYPE 00103 Unknown_AddRef( 00104 IUnknown* unknown_this); 00105 00106 ULONG 00107 STDMETHODCALLTYPE 00108 Unknown_Release( 00109 IUnknown* unknown_this); 00110 00111 typedef struct CUnknown 00112 { 00113 __GNU_EXTENSION union 00114 { 00115 IUnknown IUnknown; 00116 INonDelegatingUnknown INonDelegatingUnknown; 00117 }; 00118 00119 LONG m_ref_count; 00120 PUNKNOWN m_outer_unknown; 00121 } CUnknown; 00122 00123 #endif /* __cplusplus */ 00124 00125 00126 00127 #ifdef __cplusplus 00128 00129 00130 /* =============================================================== 00131 Construction helpers 00132 */ 00133 00134 #define QICAST(typename) \ 00135 PVOID( (typename) (this) ) 00136 00137 #define QICASTUNKNOWN(typename) \ 00138 PVOID( PUNKNOWN( (typename) (this) ) ) 00139 00140 #define STD_CREATE_BODY_WITH_TAG_(classname, unknown, outer_unknown, pool_type, tag, base) \ 00141 classname *new_ptr = new(pool_type, tag) classname(outer_unknown); \ 00142 \ 00143 if ( ! new_ptr ) \ 00144 return STATUS_INSUFFICIENT_RESOURCES; \ 00145 \ 00146 *unknown = PUNKNOWN((base)(new_ptr)); \ 00147 (*unknown)->AddRef(); \ 00148 return STATUS_SUCCESS 00149 00150 #define STD_CREATE_BODY_WITH_TAG(classname, unknown, outer_unknown, pool_type, tag, base) \ 00151 STD_CREATE_BODY_WITH_TAG_(classname, unknown, outer_unknown, pool_type, tag, PUNKNOWN) 00152 00153 #define STD_CREATE_BODY_(classname, unknown, outer_unknown, pool_type, base) \ 00154 STD_CREATE_BODY_WITH_TAG_(classname, unknown, outer_unknown, pool_type, 'rCcP', base) 00155 00156 #define STD_CREATE_BODY(classname, unknown, outer_unknown, pool_type) \ 00157 STD_CREATE_BODY_(classname, unknown, outer_unknown, pool_type, PUNKNOWN) 00158 00159 00160 /* =============================================================== 00161 Custom "new" and "delete" C++ operators 00162 */ 00163 00164 #ifndef _NEW_DELETE_OPERATORS_ 00165 #define _NEW_DELETE_OPERATORS_ 00166 00167 inline PVOID 00168 KCOM_New( 00169 size_t size, 00170 POOL_TYPE pool_type, 00171 ULONG tag) 00172 { 00173 PVOID result; 00174 00175 result = ExAllocatePoolWithTag(pool_type, size, tag); 00176 00177 if ( result ) 00178 RtlZeroMemory(result, size); 00179 00180 return result; 00181 } 00182 00183 inline PVOID 00184 operator new ( 00185 size_t size, 00186 POOL_TYPE pool_type) 00187 { 00188 return KCOM_New(size, pool_type, 'wNcP'); 00189 } 00190 00191 inline PVOID 00192 operator new ( 00193 size_t size, 00194 POOL_TYPE pool_type, 00195 ULONG tag) 00196 { 00197 return KCOM_New(size, pool_type, tag); 00198 } 00199 00200 inline void __cdecl 00201 operator delete( 00202 PVOID ptr) 00203 { 00204 ExFreePool(ptr); 00205 } 00206 00207 #endif /* ALLOCATION_OPERATORS_DEFINED */ 00208 00209 00210 #else /* Being compiled with C */ 00211 00212 00213 #endif /* __cplusplus */ 00214 00215 #endif /* include guard */ Generated on Sun May 27 2012 04:30:16 for ReactOS by
1.7.6.1
|