Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
7.0 KiB

  1. /*****************************************************************************
  2. * stdunk.h - standard IUnknown implementaton definitions
  3. *****************************************************************************
  4. * Copyright (c) Microsoft Corporation. All rights reserved.
  5. */
  6. #ifndef _STDUNK_H_
  7. #define _STDUNK_H_
  8. #include "punknown.h"
  9. /*****************************************************************************
  10. * Interfaces
  11. */
  12. /*****************************************************************************
  13. * INonDelegatingUnknown
  14. *****************************************************************************
  15. * Non-delegating unknown interface.
  16. */
  17. DECLARE_INTERFACE(INonDelegatingUnknown)
  18. {
  19. STDMETHOD_(NTSTATUS,NonDelegatingQueryInterface)
  20. ( THIS_
  21. IN REFIID,
  22. OUT PVOID *
  23. ) PURE;
  24. STDMETHOD_(ULONG,NonDelegatingAddRef)
  25. ( THIS
  26. ) PURE;
  27. STDMETHOD_(ULONG,NonDelegatingRelease)
  28. ( THIS
  29. ) PURE;
  30. };
  31. typedef INonDelegatingUnknown *PNONDELEGATINGUNKNOWN;
  32. /*****************************************************************************
  33. * Classes
  34. */
  35. /*****************************************************************************
  36. * CUnknown
  37. *****************************************************************************
  38. * Base INonDelegatingUnknown implementation.
  39. */
  40. class CUnknown : public INonDelegatingUnknown
  41. {
  42. private:
  43. LONG m_lRefCount; // Reference count.
  44. PUNKNOWN m_pUnknownOuter; // Outer IUnknown.
  45. public:
  46. /*************************************************************************
  47. * CUnknown methods.
  48. */
  49. CUnknown(PUNKNOWN pUnknownOuter);
  50. virtual ~CUnknown(void);
  51. PUNKNOWN GetOuterUnknown(void)
  52. {
  53. return m_pUnknownOuter;
  54. }
  55. /*************************************************************************
  56. * INonDelegatingUnknown methods.
  57. */
  58. STDMETHODIMP_(ULONG) NonDelegatingAddRef
  59. ( void
  60. );
  61. STDMETHODIMP_(ULONG) NonDelegatingRelease
  62. ( void
  63. );
  64. STDMETHODIMP_(NTSTATUS) NonDelegatingQueryInterface
  65. (
  66. REFIID rIID,
  67. PVOID * ppVoid
  68. );
  69. };
  70. /*****************************************************************************
  71. * Macros
  72. */
  73. /*****************************************************************************
  74. * DECLARE_STD_UNKNOWN
  75. *****************************************************************************
  76. * Various declarations for standard objects based on CUnknown.
  77. */
  78. #define DECLARE_STD_UNKNOWN() \
  79. STDMETHODIMP_(NTSTATUS) NonDelegatingQueryInterface \
  80. ( \
  81. REFIID iid, \
  82. PVOID * ppvObject \
  83. ); \
  84. STDMETHODIMP_(NTSTATUS) QueryInterface(REFIID riid, void **ppv) \
  85. { \
  86. return GetOuterUnknown()->QueryInterface(riid,ppv); \
  87. }; \
  88. STDMETHODIMP_(ULONG) AddRef() \
  89. { \
  90. return GetOuterUnknown()->AddRef(); \
  91. }; \
  92. STDMETHODIMP_(ULONG) Release() \
  93. { \
  94. return GetOuterUnknown()->Release(); \
  95. };
  96. #define DEFINE_STD_CONSTRUCTOR(Class) \
  97. Class(PUNKNOWN pUnknownOuter) \
  98. : CUnknown(pUnknownOuter) \
  99. { \
  100. }
  101. #define QICAST(Type) \
  102. PVOID((Type)(this))
  103. #define QICASTUNKNOWN(Type) \
  104. PVOID(PUNKNOWN((Type)(this)))
  105. #define STD_CREATE_BODY_WITH_TAG_(Class,ppUnknown,pUnknownOuter,poolType,tag,base) \
  106. NTSTATUS ntStatus; \
  107. Class *p = new(poolType,tag) Class(pUnknownOuter); \
  108. if (p) \
  109. { \
  110. *ppUnknown = PUNKNOWN((base)(p)); \
  111. (*ppUnknown)->AddRef(); \
  112. ntStatus = STATUS_SUCCESS; \
  113. } \
  114. else \
  115. { \
  116. ntStatus = STATUS_INSUFFICIENT_RESOURCES; \
  117. } \
  118. return ntStatus
  119. #define STD_CREATE_BODY_WITH_TAG(Class,ppUnknown,pUnknownOuter,poolType,tag) \
  120. STD_CREATE_BODY_WITH_TAG_(Class,ppUnknown,pUnknownOuter,poolType,tag,PUNKNOWN)
  121. #define STD_CREATE_BODY_(Class,ppUnknown,pUnknownOuter,poolType,base) \
  122. STD_CREATE_BODY_WITH_TAG_(Class,ppUnknown,pUnknownOuter,poolType,'rCcP',base)
  123. #define STD_CREATE_BODY(Class,ppUnknown,pUnknownOuter,poolType) \
  124. STD_CREATE_BODY_(Class,ppUnknown,pUnknownOuter,poolType,PUNKNOWN)
  125. /*****************************************************************************
  126. * Functions
  127. */
  128. #ifndef PC_KDEXT // this is not needed for the KD extensions.
  129. #ifndef _NEW_DELETE_OPERATORS_
  130. #define _NEW_DELETE_OPERATORS_
  131. /*****************************************************************************
  132. * ::new()
  133. *****************************************************************************
  134. * New function for creating objects with a specified allocation tag.
  135. */
  136. inline PVOID operator new
  137. (
  138. size_t iSize,
  139. POOL_TYPE poolType
  140. )
  141. {
  142. PVOID result = ExAllocatePoolWithTag(poolType,iSize,'wNcP');
  143. if (result)
  144. {
  145. RtlZeroMemory(result,iSize);
  146. }
  147. return result;
  148. }
  149. /*****************************************************************************
  150. * ::new()
  151. *****************************************************************************
  152. * New function for creating objects with a specified allocation tag.
  153. */
  154. inline PVOID operator new
  155. (
  156. size_t iSize,
  157. POOL_TYPE poolType,
  158. ULONG tag
  159. )
  160. {
  161. PVOID result = ExAllocatePoolWithTag(poolType,iSize,tag);
  162. if (result)
  163. {
  164. RtlZeroMemory(result,iSize);
  165. }
  166. return result;
  167. }
  168. /*****************************************************************************
  169. * ::delete()
  170. *****************************************************************************
  171. * Delete function.
  172. */
  173. inline void __cdecl operator delete
  174. (
  175. PVOID pVoid
  176. )
  177. {
  178. ExFreePool(pVoid);
  179. }
  180. #endif //!_NEW_DELETE_OPERATORS_
  181. #endif // PC_KDEXT
  182. #endif