mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / itss / itss.c
blobe284400cf11b23780afd1dc00ed8a9389fb1372e
1 /*
2 * ITSS Class Factory
4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2004 Mike McCormack
7 * see http://bonedaddy.net/pabs3/hhm/#chmspec
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.
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.
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
25 #include <stdarg.h>
26 #include <stdio.h>
28 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winuser.h"
33 #include "winreg.h"
34 #include "ole2.h"
35 #include "rpcproxy.h"
36 #include "advpub.h"
38 #include "wine/debug.h"
40 #include "itsstor.h"
42 #include "initguid.h"
43 #include "wine/itss.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(itss);
47 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj);
49 LONG dll_count = 0;
50 static HINSTANCE hInst;
52 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
54 switch(fdwReason) {
55 case DLL_PROCESS_ATTACH:
56 DisableThreadLibraryCalls(hInstDLL);
57 hInst = hInstDLL;
58 break;
60 return TRUE;
63 /******************************************************************************
64 * ITSS ClassFactory
66 typedef struct {
67 IClassFactory IClassFactory_iface;
68 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
69 } IClassFactoryImpl;
71 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
73 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
76 static HRESULT WINAPI
77 ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
79 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
81 if (IsEqualGUID(riid, &IID_IUnknown) ||
82 IsEqualGUID(riid, &IID_IClassFactory))
84 IClassFactory_AddRef(iface);
85 *ppobj = &This->IClassFactory_iface;
86 return S_OK;
89 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
90 return E_NOINTERFACE;
93 static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
95 ITSS_LockModule();
96 return 2;
99 static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
101 ITSS_UnlockModule();
102 return 1;
106 static HRESULT WINAPI ITSSCF_CreateInstance(IClassFactory *iface, IUnknown *outer,
107 REFIID riid, void **ppv)
109 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
110 IUnknown *unk;
111 HRESULT hres;
113 TRACE("(%p)->(%p %s %p)\n", This, outer, debugstr_guid(riid), ppv);
115 if(outer && !IsEqualGUID(riid, &IID_IUnknown)) {
116 *ppv = NULL;
117 return CLASS_E_NOAGGREGATION;
120 hres = This->pfnCreateInstance(outer, (void**)&unk);
121 if(FAILED(hres)) {
122 *ppv = NULL;
123 return hres;
126 if(!IsEqualGUID(riid, &IID_IUnknown)) {
127 hres = IUnknown_QueryInterface(unk, riid, ppv);
128 IUnknown_Release(unk);
129 }else {
130 *ppv = unk;
132 return hres;
135 static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
137 TRACE("(%p)->(%d)\n", iface, dolock);
139 if (dolock)
140 ITSS_LockModule();
141 else
142 ITSS_UnlockModule();
144 return S_OK;
147 static const IClassFactoryVtbl ITSSCF_Vtbl =
149 ITSSCF_QueryInterface,
150 ITSSCF_AddRef,
151 ITSSCF_Release,
152 ITSSCF_CreateInstance,
153 ITSSCF_LockServer
156 static const IClassFactoryImpl ITStorage_factory = { { &ITSSCF_Vtbl }, ITSS_create };
157 static const IClassFactoryImpl MSITStore_factory = { { &ITSSCF_Vtbl }, ITS_IParseDisplayName_create };
158 static const IClassFactoryImpl ITSProtocol_factory = { { &ITSSCF_Vtbl }, ITSProtocol_create };
160 /***********************************************************************
161 * DllGetClassObject (ITSS.@)
163 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
165 const IClassFactoryImpl *factory;
167 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
169 if (IsEqualGUID(&CLSID_ITStorage, rclsid))
170 factory = &ITStorage_factory;
171 else if (IsEqualGUID(&CLSID_MSITStore, rclsid))
172 factory = &MSITStore_factory;
173 else if (IsEqualGUID(&CLSID_ITSProtocol, rclsid))
174 factory = &ITSProtocol_factory;
175 else
177 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
178 return CLASS_E_CLASSNOTAVAILABLE;
181 return IUnknown_QueryInterface( (IUnknown*) factory, iid, ppv );
184 /*****************************************************************************/
186 typedef struct {
187 IITStorage IITStorage_iface;
188 LONG ref;
189 } ITStorageImpl;
191 static inline ITStorageImpl *impl_from_IITStorage(IITStorage *iface)
193 return CONTAINING_RECORD(iface, ITStorageImpl, IITStorage_iface);
197 static HRESULT WINAPI ITStorageImpl_QueryInterface(
198 IITStorage* iface,
199 REFIID riid,
200 void** ppvObject)
202 ITStorageImpl *This = impl_from_IITStorage(iface);
203 if (IsEqualGUID(riid, &IID_IUnknown)
204 || IsEqualGUID(riid, &IID_IITStorage))
206 IITStorage_AddRef(iface);
207 *ppvObject = iface;
208 return S_OK;
211 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
212 return E_NOINTERFACE;
215 static ULONG WINAPI ITStorageImpl_AddRef(
216 IITStorage* iface)
218 ITStorageImpl *This = impl_from_IITStorage(iface);
219 TRACE("%p\n", This);
220 return InterlockedIncrement(&This->ref);
223 static ULONG WINAPI ITStorageImpl_Release(
224 IITStorage* iface)
226 ITStorageImpl *This = impl_from_IITStorage(iface);
227 ULONG ref = InterlockedDecrement(&This->ref);
229 if (ref == 0) {
230 HeapFree(GetProcessHeap(), 0, This);
231 ITSS_UnlockModule();
234 return ref;
237 static HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
238 IITStorage* iface,
239 const WCHAR* pwcsName,
240 DWORD grfMode,
241 DWORD reserved,
242 IStorage** ppstgOpen)
244 ITStorageImpl *This = impl_from_IITStorage(iface);
246 TRACE("%p %s %u %u %p\n", This,
247 debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
249 return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
250 0, reserved, ppstgOpen);
253 static HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
254 IITStorage* iface,
255 ILockBytes* plkbyt,
256 DWORD grfMode,
257 DWORD reserved,
258 IStorage** ppstgOpen)
260 ITStorageImpl *This = impl_from_IITStorage(iface);
261 FIXME("%p\n", This);
262 return E_NOTIMPL;
265 static HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
266 IITStorage* iface,
267 const WCHAR* pwcsName)
269 ITStorageImpl *This = impl_from_IITStorage(iface);
270 FIXME("%p\n", This);
271 return E_NOTIMPL;
274 static HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
275 IITStorage* iface,
276 ILockBytes* plkbyt)
278 ITStorageImpl *This = impl_from_IITStorage(iface);
279 FIXME("%p\n", This);
280 return E_NOTIMPL;
283 static HRESULT WINAPI ITStorageImpl_StgOpenStorage(
284 IITStorage* iface,
285 const WCHAR* pwcsName,
286 IStorage* pstgPriority,
287 DWORD grfMode,
288 SNB snbExclude,
289 DWORD reserved,
290 IStorage** ppstgOpen)
292 ITStorageImpl *This = impl_from_IITStorage(iface);
294 TRACE("%p %s %p %d %p\n", This, debugstr_w( pwcsName ),
295 pstgPriority, grfMode, snbExclude );
297 return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
298 snbExclude, reserved, ppstgOpen);
301 static HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
302 IITStorage* iface,
303 ILockBytes* plkbyt,
304 IStorage* pStgPriority,
305 DWORD grfMode,
306 SNB snbExclude,
307 DWORD reserved,
308 IStorage** ppstgOpen)
310 ITStorageImpl *This = impl_from_IITStorage(iface);
311 FIXME("%p\n", This);
312 return E_NOTIMPL;
315 static HRESULT WINAPI ITStorageImpl_StgSetTimes(
316 IITStorage* iface,
317 const WCHAR* lpszName,
318 const FILETIME* pctime,
319 const FILETIME* patime,
320 const FILETIME* pmtime)
322 ITStorageImpl *This = impl_from_IITStorage(iface);
323 FIXME("%p\n", This);
324 return E_NOTIMPL;
327 static HRESULT WINAPI ITStorageImpl_SetControlData(
328 IITStorage* iface,
329 PITS_Control_Data pControlData)
331 ITStorageImpl *This = impl_from_IITStorage(iface);
332 FIXME("%p\n", This);
333 return E_NOTIMPL;
336 static HRESULT WINAPI ITStorageImpl_DefaultControlData(
337 IITStorage* iface,
338 PITS_Control_Data* ppControlData)
340 ITStorageImpl *This = impl_from_IITStorage(iface);
341 FIXME("%p\n", This);
342 return E_NOTIMPL;
345 static HRESULT WINAPI ITStorageImpl_Compact(
346 IITStorage* iface,
347 const WCHAR* pwcsName,
348 ECompactionLev iLev)
350 ITStorageImpl *This = impl_from_IITStorage(iface);
351 FIXME("%p\n", This);
352 return E_NOTIMPL;
355 static const IITStorageVtbl ITStorageImpl_Vtbl =
357 ITStorageImpl_QueryInterface,
358 ITStorageImpl_AddRef,
359 ITStorageImpl_Release,
360 ITStorageImpl_StgCreateDocfile,
361 ITStorageImpl_StgCreateDocfileOnILockBytes,
362 ITStorageImpl_StgIsStorageFile,
363 ITStorageImpl_StgIsStorageILockBytes,
364 ITStorageImpl_StgOpenStorage,
365 ITStorageImpl_StgOpenStorageOnILockBytes,
366 ITStorageImpl_StgSetTimes,
367 ITStorageImpl_SetControlData,
368 ITStorageImpl_DefaultControlData,
369 ITStorageImpl_Compact,
372 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
374 ITStorageImpl *its;
376 if( pUnkOuter )
377 return CLASS_E_NOAGGREGATION;
379 its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
380 its->IITStorage_iface.lpVtbl = &ITStorageImpl_Vtbl;
381 its->ref = 1;
383 TRACE("-> %p\n", its);
384 *ppObj = its;
386 ITSS_LockModule();
387 return S_OK;
390 /*****************************************************************************/
392 HRESULT WINAPI DllCanUnloadNow(void)
394 TRACE("dll_count = %u\n", dll_count);
395 return dll_count ? S_FALSE : S_OK;
398 /***********************************************************************
399 * DllRegisterServer (ITSS.@)
401 HRESULT WINAPI DllRegisterServer(void)
403 return __wine_register_resources( hInst );
406 /***********************************************************************
407 * DllUnregisterServer (ITSS.@)
409 HRESULT WINAPI DllUnregisterServer(void)
411 return __wine_unregister_resources( hInst );