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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(itss);
50 DEFINE_GUID(CLSID_ITStorage,0x5d02926a,0x212e,0x11d0,0x9d,0xf9,0x00,0xa0,0xc9,0x22,0xe6,0xec );
51 DEFINE_GUID(CLSID_ITSProtocol,0x9d148290,0xb9c8,0x11d0,0xa4,0xcc,0x00,0x00,0xf8,0x01,0x49,0xf6);
52 DEFINE_GUID(IID_IITStorage, 0x88cc31de, 0x27ab, 0x11d0, 0x9d, 0xf9, 0x0, 0xa0, 0xc9, 0x22, 0xe6, 0xec);
54 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj);
58 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
61 case DLL_PROCESS_ATTACH:
62 DisableThreadLibraryCalls(hInstDLL);
64 case DLL_PROCESS_DETACH:
70 /******************************************************************************
74 IClassFactory ITF_IClassFactory;
77 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
80 struct object_creation_info
84 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
87 static const struct object_creation_info object_creation[] =
89 { &CLSID_ITStorage, "ITStorage", ITSS_create },
90 { &CLSID_ITSProtocol, "ITSProtocol", ITS_IParseDisplayName_create },
94 ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
96 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
98 if (IsEqualGUID(riid, &IID_IUnknown)
99 || IsEqualGUID(riid, &IID_IClassFactory))
101 IClassFactory_AddRef(iface);
106 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
107 return E_NOINTERFACE;
110 static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
112 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
113 return InterlockedIncrement(&This->ref);
116 static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
118 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
120 ULONG ref = InterlockedDecrement(&This->ref);
123 HeapFree(GetProcessHeap(), 0, This);
124 InterlockedDecrement(&dll_count);
131 static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
132 REFIID riid, LPVOID *ppobj)
134 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
138 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
141 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
142 if (SUCCEEDED(hres)) {
143 hres = IUnknown_QueryInterface(punk, riid, ppobj);
144 IUnknown_Release(punk);
149 static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
151 TRACE("(%p)->(%d)\n", iface, dolock);
154 InterlockedIncrement(&dll_count);
156 InterlockedDecrement(&dll_count);
161 static IClassFactoryVtbl ITSSCF_Vtbl =
163 ITSSCF_QueryInterface,
166 ITSSCF_CreateInstance,
171 /***********************************************************************
172 * DllGetClassObject (ITSS.@)
174 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
177 IClassFactoryImpl *factory;
179 TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
181 if ( !IsEqualGUID( &IID_IClassFactory, iid )
182 && ! IsEqualGUID( &IID_IUnknown, iid) )
183 return E_NOINTERFACE;
185 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
187 if (IsEqualGUID(object_creation[i].clsid, rclsid))
191 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
193 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
194 return CLASS_E_CLASSNOTAVAILABLE;
197 TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
199 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
200 if (factory == NULL) return E_OUTOFMEMORY;
202 factory->ITF_IClassFactory.lpVtbl = &ITSSCF_Vtbl;
205 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
207 *ppv = &(factory->ITF_IClassFactory);
208 InterlockedIncrement(&dll_count);
210 TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
215 /*****************************************************************************/
218 IITStorageVtbl *vtbl_IITStorage;
223 HRESULT WINAPI ITStorageImpl_QueryInterface(
228 ITStorageImpl *This = (ITStorageImpl *)iface;
229 if (IsEqualGUID(riid, &IID_IUnknown)
230 || IsEqualGUID(riid, &IID_IITStorage))
232 IClassFactory_AddRef(iface);
237 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
238 return E_NOINTERFACE;
241 ULONG WINAPI ITStorageImpl_AddRef(
244 ITStorageImpl *This = (ITStorageImpl *)iface;
246 return InterlockedIncrement(&This->ref);
249 ULONG WINAPI ITStorageImpl_Release(
252 ITStorageImpl *This = (ITStorageImpl *)iface;
253 ULONG ref = InterlockedDecrement(&This->ref);
256 HeapFree(GetProcessHeap(), 0, This);
257 InterlockedDecrement(&dll_count);
263 HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
265 const WCHAR* pwcsName,
268 IStorage** ppstgOpen)
270 ITStorageImpl *This = (ITStorageImpl *)iface;
272 TRACE("%p %s %lu %lu %p\n", This,
273 debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
275 return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
276 0, reserved, ppstgOpen);
279 HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
284 IStorage** ppstgOpen)
286 ITStorageImpl *This = (ITStorageImpl *)iface;
291 HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
293 const WCHAR* pwcsName)
295 ITStorageImpl *This = (ITStorageImpl *)iface;
300 HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
304 ITStorageImpl *This = (ITStorageImpl *)iface;
309 HRESULT WINAPI ITStorageImpl_StgOpenStorage(
311 const WCHAR* pwcsName,
312 IStorage* pstgPriority,
316 IStorage** ppstgOpen)
318 ITStorageImpl *This = (ITStorageImpl *)iface;
320 TRACE("%p %s %p %ld %p\n", This, debugstr_w( pwcsName ),
321 pstgPriority, grfMode, snbExclude );
323 return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
324 snbExclude, reserved, ppstgOpen);
327 HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
330 IStorage* pStgPriority,
334 IStorage** ppstgOpen)
336 ITStorageImpl *This = (ITStorageImpl *)iface;
341 HRESULT WINAPI ITStorageImpl_StgSetTimes(
348 ITStorageImpl *This = (ITStorageImpl *)iface;
353 HRESULT WINAPI ITStorageImpl_SetControlData(
355 PITS_Control_Data pControlData)
357 ITStorageImpl *This = (ITStorageImpl *)iface;
362 HRESULT WINAPI ITStorageImpl_DefaultControlData(
364 PITS_Control_Data* ppControlData)
366 ITStorageImpl *This = (ITStorageImpl *)iface;
371 HRESULT WINAPI ITStorageImpl_Compact(
373 const WCHAR* pwcsName,
376 ITStorageImpl *This = (ITStorageImpl *)iface;
381 static IITStorageVtbl ITStorageImpl_Vtbl =
383 ITStorageImpl_QueryInterface,
384 ITStorageImpl_AddRef,
385 ITStorageImpl_Release,
386 ITStorageImpl_StgCreateDocfile,
387 ITStorageImpl_StgCreateDocfileOnILockBytes,
388 ITStorageImpl_StgIsStorageFile,
389 ITStorageImpl_StgIsStorageILockBytes,
390 ITStorageImpl_StgOpenStorage,
391 ITStorageImpl_StgOpenStorageOnILockBytes,
392 ITStorageImpl_StgSetTimes,
393 ITStorageImpl_SetControlData,
394 ITStorageImpl_DefaultControlData,
395 ITStorageImpl_Compact,
398 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
403 return CLASS_E_NOAGGREGATION;
405 its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
406 its->vtbl_IITStorage = &ITStorageImpl_Vtbl;
409 TRACE("-> %p\n", its);
410 *ppObj = (LPVOID) its;
411 InterlockedIncrement(&dll_count);
416 /*****************************************************************************/
418 HRESULT WINAPI DllRegisterServer(void)
424 HRESULT WINAPI DllCanUnloadNow(void)
426 TRACE("dll_count = %lu\n", dll_count);
427 return dll_count ? S_FALSE : S_OK;