Leaked source code of windows server 2003
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.

297 lines
7.7 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. kcom.h
  5. Abstract:
  6. Kernel COM
  7. --*/
  8. #if !defined(_KS_)
  9. #error KS.H must be included before KCOM.H
  10. #endif // !defined(_KS_)
  11. #if !defined(_KCOM_)
  12. #define _KCOM_
  13. #if defined(__cplusplus)
  14. extern "C" {
  15. #endif // defined(__cplusplus)
  16. #define STATIC_KoCreateObject \
  17. 0x72CF721CL, 0x525A, 0x11D1, 0x9A, 0xA1, 0x00, 0xa0, 0xc9, 0x22, 0x31, 0x96
  18. DEFINE_GUIDSTRUCT("72CF721C-525A-11D1-9AA1-00A0C9223196", KoCreateObject);
  19. #define KOSTRING_CreateObject L"{72CF721C-525A-11D1-9AA1-00A0C9223196}"
  20. #ifndef CLSCTX_KERNEL_SERVER
  21. #define CLSCTX_KERNEL_SERVER 0x00000200
  22. #endif
  23. typedef
  24. NTSTATUS
  25. (*KoCreateObjectHandler)(
  26. IN REFCLSID ClassId,
  27. IN IUnknown* UnkOuter OPTIONAL,
  28. IN REFIID InterfaceId,
  29. OUT PVOID* Interface
  30. );
  31. #undef INTERFACE
  32. #define INTERFACE INonDelegatedUnknown
  33. DECLARE_INTERFACE(INonDelegatedUnknown) {
  34. STDMETHOD(NonDelegatedQueryInterface)(
  35. THIS_
  36. IN REFIID InterfaceId,
  37. OUT PVOID* Interface
  38. ) PURE;
  39. STDMETHOD_(ULONG,NonDelegatedAddRef)(
  40. THIS
  41. ) PURE;
  42. STDMETHOD_(ULONG,NonDelegatedRelease)(
  43. THIS
  44. ) PURE;
  45. };
  46. #undef INTERFACE
  47. #define INTERFACE IIndirectedUnknown
  48. DECLARE_INTERFACE(IIndirectedUnknown) {
  49. STDMETHOD(IndirectedQueryInterface)(
  50. THIS_
  51. IN REFIID InterfaceId,
  52. OUT PVOID* Interface
  53. ) PURE;
  54. STDMETHOD_(ULONG,IndirectedAddRef)(
  55. THIS
  56. ) PURE;
  57. STDMETHOD_(ULONG,IndirectedRelease)(
  58. THIS
  59. ) PURE;
  60. };
  61. #if !defined(__cplusplus) || _MSC_VER < 1100
  62. #define STATIC_IID_IKoInitializeParentDeviceObject\
  63. 0x21B36996L, 0x8DE3, 0x11D1, 0x8A, 0xE0, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
  64. DEFINE_GUIDEX(IID_IKoInitializeParentDeviceObject);
  65. #else
  66. interface __declspec(uuid("21B36996-8DE3-11D1-8AE0-00A0C9223196")) IKoInitializeParentDeviceObject;
  67. #endif
  68. #undef INTERFACE
  69. #define INTERFACE IKoInitializeParentDeviceObject
  70. DECLARE_INTERFACE_(IKoInitializeParentDeviceObject, IUnknown) {
  71. STDMETHOD(SetParentDeviceObject)(
  72. THIS_
  73. IN PDEVICE_OBJECT ParentDeviceObject
  74. ) PURE;
  75. };
  76. #ifndef COMDDKMETHOD
  77. #ifdef _COMDDK_
  78. #define COMDDKMETHOD
  79. #else // !_COMDDK_
  80. #define COMDDKMETHOD DECLSPEC_IMPORT
  81. #endif // _COMDDK_
  82. #endif // !COMDDKMETHOD
  83. #ifdef _COMDDK_
  84. #define COMDDKAPI
  85. #else // !_COMDDK_
  86. #define COMDDKAPI DECLSPEC_IMPORT
  87. #endif // _COMDDK_
  88. #if defined(__cplusplus)
  89. class CBaseUnknown : public INonDelegatedUnknown, public IIndirectedUnknown {
  90. protected:
  91. LONG m_RefCount;
  92. private:
  93. BOOLEAN m_UsingClassId;
  94. CLSID m_ClassId;
  95. protected:
  96. IUnknown* m_UnknownOuter;
  97. public:
  98. COMDDKMETHOD CBaseUnknown(
  99. IN REFCLSID ClassId,
  100. IN IUnknown* UnknownOuter OPTIONAL = NULL
  101. );
  102. COMDDKMETHOD CBaseUnknown(
  103. IN IUnknown* UnknownOuter OPTIONAL = NULL
  104. );
  105. COMDDKMETHOD virtual ~CBaseUnknown();
  106. // INonDelegatedUnknown
  107. COMDDKMETHOD STDMETHODIMP_(ULONG) NonDelegatedAddRef();
  108. COMDDKMETHOD STDMETHODIMP_(ULONG) NonDelegatedRelease();
  109. COMDDKMETHOD STDMETHODIMP NonDelegatedQueryInterface(
  110. IN REFIID InterfaceId,
  111. OUT PVOID* Interface
  112. );
  113. //IIndirectedUnknown
  114. COMDDKMETHOD STDMETHODIMP_(ULONG) IndirectedAddRef();
  115. COMDDKMETHOD STDMETHODIMP_(ULONG) IndirectedRelease();
  116. COMDDKMETHOD STDMETHODIMP IndirectedQueryInterface(
  117. IN REFIID InterfaceId,
  118. OUT PVOID* Interface
  119. );
  120. };
  121. #if !defined(DEFINE_ABSTRACT_UNKNOWN)
  122. #define DEFINE_ABSTRACT_UNKNOWN() \
  123. STDMETHOD(QueryInterface)(THIS_ \
  124. REFIID InterfaceId, \
  125. PVOID* Interface \
  126. ) PURE; \
  127. STDMETHOD_(ULONG,AddRef)(THIS) PURE; \
  128. STDMETHOD_(ULONG,Release)(THIS) PURE;
  129. #endif //!defined(DEFINE_ABSTRACT_UNKNOWN)
  130. #define DEFINE_STD_UNKNOWN() \
  131. STDMETHODIMP NonDelegatedQueryInterface( \
  132. REFIID InterfaceId, \
  133. PVOID* Interface \
  134. ); \
  135. STDMETHODIMP QueryInterface( \
  136. REFIID InterfaceId, \
  137. PVOID* Interface \
  138. ); \
  139. STDMETHODIMP_(ULONG) AddRef(); \
  140. STDMETHODIMP_(ULONG) Release();
  141. #define IMPLEMENT_STD_UNKNOWN(Class) \
  142. STDMETHODIMP Class::QueryInterface( \
  143. REFIID InterfaceId, \
  144. PVOID* Interface \
  145. ) \
  146. { \
  147. return m_UnknownOuter->QueryInterface(InterfaceId, Interface);\
  148. } \
  149. STDMETHODIMP_(ULONG) Class::AddRef() \
  150. { \
  151. return m_UnknownOuter->AddRef(); \
  152. } \
  153. STDMETHODIMP_(ULONG) Class::Release() \
  154. { \
  155. return m_UnknownOuter->Release(); \
  156. }
  157. #else // !__cplusplus
  158. COMDDKAPI
  159. void
  160. NTAPI
  161. KoRelease(
  162. IN REFCLSID ClassId
  163. );
  164. #endif // !__cplusplus
  165. COMDDKAPI
  166. NTSTATUS
  167. NTAPI
  168. KoCreateInstance(
  169. IN REFCLSID ClassId,
  170. IN IUnknown* UnkOuter OPTIONAL,
  171. IN ULONG ClsContext,
  172. IN REFIID InterfaceId,
  173. OUT PVOID* Interface
  174. );
  175. COMDDKAPI
  176. NTSTATUS
  177. NTAPI
  178. KoDriverInitialize(
  179. IN PDRIVER_OBJECT DriverObject,
  180. IN PUNICODE_STRING RegistryPathName,
  181. IN KoCreateObjectHandler CreateObjectHandler
  182. );
  183. COMDDKAPI
  184. NTSTATUS
  185. NTAPI
  186. KoDeviceInitialize(
  187. IN PDEVICE_OBJECT DeviceObject
  188. );
  189. #if defined(__cplusplus)
  190. }
  191. #endif // defined(__cplusplus)
  192. #ifdef __cplusplus
  193. #ifndef _NEW_DELETE_OPERATORS_
  194. #define _NEW_DELETE_OPERATORS_
  195. inline PVOID operator new
  196. (
  197. size_t iSize,
  198. POOL_TYPE poolType
  199. )
  200. {
  201. PVOID result = ExAllocatePoolWithTag(poolType,iSize,'wNCK');
  202. if (result) {
  203. RtlZeroMemory(result,iSize);
  204. }
  205. return result;
  206. }
  207. inline PVOID operator new
  208. (
  209. size_t iSize,
  210. POOL_TYPE poolType,
  211. ULONG tag
  212. )
  213. {
  214. PVOID result = ExAllocatePoolWithTag(poolType,iSize,tag);
  215. if (result) {
  216. RtlZeroMemory(result,iSize);
  217. }
  218. return result;
  219. }
  220. inline void __cdecl operator delete
  221. (
  222. PVOID pVoid
  223. )
  224. {
  225. ExFreePool(pVoid);
  226. }
  227. #endif //!_NEW_DELETE_OPERATORS_
  228. #if defined(_SYS_GUID_OPERATOR_EQ_)
  229. // Define _SYS_GUID_OPERATOR_EQ_ before including guiddef.h to get the aligned guid test.
  230. #define _GUID_OPERATORS_
  231. #pragma message("WARNING: Using system operator==/!= for GUIDs")
  232. #endif
  233. #ifndef _GUID_OPERATORS_
  234. #define _GUID_OPERATORS_
  235. __inline BOOL operator==(const GUID& guidOne, const GUID& guidOther)
  236. {
  237. return IsEqualGUIDAligned(guidOne,guidOther);
  238. }
  239. __inline BOOL operator!=(const GUID& guidOne, const GUID& guidOther)
  240. {
  241. return !(guidOne == guidOther);
  242. }
  243. #endif // _GUID_OPERATORS_
  244. #endif // __cplusplus
  245. #endif // !_KCOM_