* Sync up to trunk head (r64921).
[reactos.git] / dll / win32 / itss / itss.c
1 /*
2 * ITSS Class Factory
3 *
4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2004 Mike McCormack
6 *
7 * see http://bonedaddy.net/pabs3/hhm/#chmspec
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24 #include "precomp.h"
25
26 #include <rpcproxy.h>
27
28 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj);
29
30 LONG dll_count = 0;
31 static HINSTANCE hInst;
32
33 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
34 {
35 switch(fdwReason) {
36 case DLL_PROCESS_ATTACH:
37 DisableThreadLibraryCalls(hInstDLL);
38 hInst = hInstDLL;
39 break;
40 }
41 return TRUE;
42 }
43
44 /******************************************************************************
45 * ITSS ClassFactory
46 */
47 typedef struct {
48 IClassFactory IClassFactory_iface;
49 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
50 } IClassFactoryImpl;
51
52 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
53 {
54 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
55 }
56
57 static HRESULT WINAPI
58 ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
59 {
60 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
61
62 if (IsEqualGUID(riid, &IID_IUnknown) ||
63 IsEqualGUID(riid, &IID_IClassFactory))
64 {
65 IClassFactory_AddRef(iface);
66 *ppobj = This;
67 return S_OK;
68 }
69
70 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
71 return E_NOINTERFACE;
72 }
73
74 static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
75 {
76 ITSS_LockModule();
77 return 2;
78 }
79
80 static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
81 {
82 ITSS_UnlockModule();
83 return 1;
84 }
85
86
87 static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
88 REFIID riid, LPVOID *ppobj)
89 {
90 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
91 HRESULT hres;
92 LPUNKNOWN punk;
93
94 TRACE("(%p)->(%p,%s,%p)\n", This, pOuter, debugstr_guid(riid), ppobj);
95
96 *ppobj = NULL;
97 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
98 if (SUCCEEDED(hres)) {
99 hres = IUnknown_QueryInterface(punk, riid, ppobj);
100 IUnknown_Release(punk);
101 }
102 return hres;
103 }
104
105 static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
106 {
107 TRACE("(%p)->(%d)\n", iface, dolock);
108
109 if (dolock)
110 ITSS_LockModule();
111 else
112 ITSS_UnlockModule();
113
114 return S_OK;
115 }
116
117 static const IClassFactoryVtbl ITSSCF_Vtbl =
118 {
119 ITSSCF_QueryInterface,
120 ITSSCF_AddRef,
121 ITSSCF_Release,
122 ITSSCF_CreateInstance,
123 ITSSCF_LockServer
124 };
125
126 static const IClassFactoryImpl ITStorage_factory = { { &ITSSCF_Vtbl }, ITSS_create };
127 static const IClassFactoryImpl MSITStore_factory = { { &ITSSCF_Vtbl }, ITS_IParseDisplayName_create };
128 static const IClassFactoryImpl ITSProtocol_factory = { { &ITSSCF_Vtbl }, ITSProtocol_create };
129
130 /***********************************************************************
131 * DllGetClassObject (ITSS.@)
132 */
133 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
134 {
135 const IClassFactoryImpl *factory;
136
137 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
138
139 if (IsEqualGUID(&CLSID_ITStorage, rclsid))
140 factory = &ITStorage_factory;
141 else if (IsEqualGUID(&CLSID_MSITStore, rclsid))
142 factory = &MSITStore_factory;
143 else if (IsEqualGUID(&CLSID_ITSProtocol, rclsid))
144 factory = &ITSProtocol_factory;
145 else
146 {
147 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
148 return CLASS_E_CLASSNOTAVAILABLE;
149 }
150
151 return IUnknown_QueryInterface( (IUnknown*) factory, iid, ppv );
152 }
153
154 /*****************************************************************************/
155
156 typedef struct {
157 IITStorage IITStorage_iface;
158 LONG ref;
159 } ITStorageImpl;
160
161 static inline ITStorageImpl *impl_from_IITStorage(IITStorage *iface)
162 {
163 return CONTAINING_RECORD(iface, ITStorageImpl, IITStorage_iface);
164 }
165
166
167 static HRESULT WINAPI ITStorageImpl_QueryInterface(
168 IITStorage* iface,
169 REFIID riid,
170 void** ppvObject)
171 {
172 ITStorageImpl *This = impl_from_IITStorage(iface);
173 if (IsEqualGUID(riid, &IID_IUnknown)
174 || IsEqualGUID(riid, &IID_IITStorage))
175 {
176 IITStorage_AddRef(iface);
177 *ppvObject = iface;
178 return S_OK;
179 }
180
181 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
182 return E_NOINTERFACE;
183 }
184
185 static ULONG WINAPI ITStorageImpl_AddRef(
186 IITStorage* iface)
187 {
188 ITStorageImpl *This = impl_from_IITStorage(iface);
189 TRACE("%p\n", This);
190 return InterlockedIncrement(&This->ref);
191 }
192
193 static ULONG WINAPI ITStorageImpl_Release(
194 IITStorage* iface)
195 {
196 ITStorageImpl *This = impl_from_IITStorage(iface);
197 ULONG ref = InterlockedDecrement(&This->ref);
198
199 if (ref == 0) {
200 HeapFree(GetProcessHeap(), 0, This);
201 ITSS_UnlockModule();
202 }
203
204 return ref;
205 }
206
207 static HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
208 IITStorage* iface,
209 const WCHAR* pwcsName,
210 DWORD grfMode,
211 DWORD reserved,
212 IStorage** ppstgOpen)
213 {
214 ITStorageImpl *This = impl_from_IITStorage(iface);
215
216 TRACE("%p %s %u %u %p\n", This,
217 debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
218
219 return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
220 0, reserved, ppstgOpen);
221 }
222
223 static HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
224 IITStorage* iface,
225 ILockBytes* plkbyt,
226 DWORD grfMode,
227 DWORD reserved,
228 IStorage** ppstgOpen)
229 {
230 ITStorageImpl *This = impl_from_IITStorage(iface);
231 FIXME("%p\n", This);
232 return E_NOTIMPL;
233 }
234
235 static HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
236 IITStorage* iface,
237 const WCHAR* pwcsName)
238 {
239 ITStorageImpl *This = impl_from_IITStorage(iface);
240 FIXME("%p\n", This);
241 return E_NOTIMPL;
242 }
243
244 static HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
245 IITStorage* iface,
246 ILockBytes* plkbyt)
247 {
248 ITStorageImpl *This = impl_from_IITStorage(iface);
249 FIXME("%p\n", This);
250 return E_NOTIMPL;
251 }
252
253 static HRESULT WINAPI ITStorageImpl_StgOpenStorage(
254 IITStorage* iface,
255 const WCHAR* pwcsName,
256 IStorage* pstgPriority,
257 DWORD grfMode,
258 SNB snbExclude,
259 DWORD reserved,
260 IStorage** ppstgOpen)
261 {
262 ITStorageImpl *This = impl_from_IITStorage(iface);
263
264 TRACE("%p %s %p %d %p\n", This, debugstr_w( pwcsName ),
265 pstgPriority, grfMode, snbExclude );
266
267 return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
268 snbExclude, reserved, ppstgOpen);
269 }
270
271 static HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
272 IITStorage* iface,
273 ILockBytes* plkbyt,
274 IStorage* pStgPriority,
275 DWORD grfMode,
276 SNB snbExclude,
277 DWORD reserved,
278 IStorage** ppstgOpen)
279 {
280 ITStorageImpl *This = impl_from_IITStorage(iface);
281 FIXME("%p\n", This);
282 return E_NOTIMPL;
283 }
284
285 static HRESULT WINAPI ITStorageImpl_StgSetTimes(
286 IITStorage* iface,
287 const WCHAR* lpszName,
288 const FILETIME* pctime,
289 const FILETIME* patime,
290 const FILETIME* pmtime)
291 {
292 ITStorageImpl *This = impl_from_IITStorage(iface);
293 FIXME("%p\n", This);
294 return E_NOTIMPL;
295 }
296
297 static HRESULT WINAPI ITStorageImpl_SetControlData(
298 IITStorage* iface,
299 PITS_Control_Data pControlData)
300 {
301 ITStorageImpl *This = impl_from_IITStorage(iface);
302 FIXME("%p\n", This);
303 return E_NOTIMPL;
304 }
305
306 static HRESULT WINAPI ITStorageImpl_DefaultControlData(
307 IITStorage* iface,
308 PITS_Control_Data* ppControlData)
309 {
310 ITStorageImpl *This = impl_from_IITStorage(iface);
311 FIXME("%p\n", This);
312 return E_NOTIMPL;
313 }
314
315 static HRESULT WINAPI ITStorageImpl_Compact(
316 IITStorage* iface,
317 const WCHAR* pwcsName,
318 ECompactionLev iLev)
319 {
320 ITStorageImpl *This = impl_from_IITStorage(iface);
321 FIXME("%p\n", This);
322 return E_NOTIMPL;
323 }
324
325 static const IITStorageVtbl ITStorageImpl_Vtbl =
326 {
327 ITStorageImpl_QueryInterface,
328 ITStorageImpl_AddRef,
329 ITStorageImpl_Release,
330 ITStorageImpl_StgCreateDocfile,
331 ITStorageImpl_StgCreateDocfileOnILockBytes,
332 ITStorageImpl_StgIsStorageFile,
333 ITStorageImpl_StgIsStorageILockBytes,
334 ITStorageImpl_StgOpenStorage,
335 ITStorageImpl_StgOpenStorageOnILockBytes,
336 ITStorageImpl_StgSetTimes,
337 ITStorageImpl_SetControlData,
338 ITStorageImpl_DefaultControlData,
339 ITStorageImpl_Compact,
340 };
341
342 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
343 {
344 ITStorageImpl *its;
345
346 if( pUnkOuter )
347 return CLASS_E_NOAGGREGATION;
348
349 its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
350 its->IITStorage_iface.lpVtbl = &ITStorageImpl_Vtbl;
351 its->ref = 1;
352
353 TRACE("-> %p\n", its);
354 *ppObj = its;
355
356 ITSS_LockModule();
357 return S_OK;
358 }
359
360 /*****************************************************************************/
361
362 HRESULT WINAPI DllCanUnloadNow(void)
363 {
364 TRACE("dll_count = %u\n", dll_count);
365 return dll_count ? S_FALSE : S_OK;
366 }
367
368 /***********************************************************************
369 * DllRegisterServer (ITSS.@)
370 */
371 HRESULT WINAPI DllRegisterServer(void)
372 {
373 return __wine_register_resources( hInst );
374 }
375
376 /***********************************************************************
377 * DllUnregisterServer (ITSS.@)
378 */
379 HRESULT WINAPI DllUnregisterServer(void)
380 {
381 return __wine_unregister_resources( hInst );
382 }