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