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