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 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
152 FIXME("(%p)->(%d),stub!\n",This,dolock);
156 static IClassFactoryVtbl ITSSCF_Vtbl =
158 ITSSCF_QueryInterface,
161 ITSSCF_CreateInstance,
166 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
169 IClassFactoryImpl *factory;
171 TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
173 if ( !IsEqualGUID( &IID_IClassFactory, iid )
174 && ! IsEqualGUID( &IID_IUnknown, iid) )
175 return E_NOINTERFACE;
177 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
179 if (IsEqualGUID(object_creation[i].clsid, rclsid))
183 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
185 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
186 return CLASS_E_CLASSNOTAVAILABLE;
189 TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
191 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
192 if (factory == NULL) return E_OUTOFMEMORY;
194 factory->ITF_IClassFactory.lpVtbl = &ITSSCF_Vtbl;
197 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
199 *ppv = &(factory->ITF_IClassFactory);
200 InterlockedIncrement(&dll_count);
202 TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
207 /*****************************************************************************/
210 IITStorageVtbl *vtbl_IITStorage;
215 HRESULT WINAPI ITStorageImpl_QueryInterface(
220 ITStorageImpl *This = (ITStorageImpl *)iface;
221 if (IsEqualGUID(riid, &IID_IUnknown)
222 || IsEqualGUID(riid, &IID_IITStorage))
224 IClassFactory_AddRef(iface);
229 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
230 return E_NOINTERFACE;
233 ULONG WINAPI ITStorageImpl_AddRef(
236 ITStorageImpl *This = (ITStorageImpl *)iface;
238 return InterlockedIncrement(&This->ref);
241 ULONG WINAPI ITStorageImpl_Release(
244 ITStorageImpl *This = (ITStorageImpl *)iface;
245 ULONG ref = InterlockedDecrement(&This->ref);
248 HeapFree(GetProcessHeap(), 0, This);
249 InterlockedDecrement(&dll_count);
255 HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
257 const WCHAR* pwcsName,
260 IStorage** ppstgOpen)
262 ITStorageImpl *This = (ITStorageImpl *)iface;
264 TRACE("%p %s %lu %lu %p\n", This,
265 debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
267 return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
268 0, reserved, ppstgOpen);
271 HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
276 IStorage** ppstgOpen)
278 ITStorageImpl *This = (ITStorageImpl *)iface;
283 HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
285 const WCHAR* pwcsName)
287 ITStorageImpl *This = (ITStorageImpl *)iface;
292 HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
296 ITStorageImpl *This = (ITStorageImpl *)iface;
301 HRESULT WINAPI ITStorageImpl_StgOpenStorage(
303 const WCHAR* pwcsName,
304 IStorage* pstgPriority,
308 IStorage** ppstgOpen)
310 ITStorageImpl *This = (ITStorageImpl *)iface;
312 TRACE("%p %s %p %ld %p\n", This, debugstr_w( pwcsName ),
313 pstgPriority, grfMode, snbExclude );
315 return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
316 snbExclude, reserved, ppstgOpen);
319 HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
322 IStorage* pStgPriority,
326 IStorage** ppstgOpen)
328 ITStorageImpl *This = (ITStorageImpl *)iface;
333 HRESULT WINAPI ITStorageImpl_StgSetTimes(
340 ITStorageImpl *This = (ITStorageImpl *)iface;
345 HRESULT WINAPI ITStorageImpl_SetControlData(
347 PITS_Control_Data pControlData)
349 ITStorageImpl *This = (ITStorageImpl *)iface;
354 HRESULT WINAPI ITStorageImpl_DefaultControlData(
356 PITS_Control_Data* ppControlData)
358 ITStorageImpl *This = (ITStorageImpl *)iface;
363 HRESULT WINAPI ITStorageImpl_Compact(
365 const WCHAR* pwcsName,
368 ITStorageImpl *This = (ITStorageImpl *)iface;
373 static IITStorageVtbl ITStorageImpl_Vtbl =
375 ITStorageImpl_QueryInterface,
376 ITStorageImpl_AddRef,
377 ITStorageImpl_Release,
378 ITStorageImpl_StgCreateDocfile,
379 ITStorageImpl_StgCreateDocfileOnILockBytes,
380 ITStorageImpl_StgIsStorageFile,
381 ITStorageImpl_StgIsStorageILockBytes,
382 ITStorageImpl_StgOpenStorage,
383 ITStorageImpl_StgOpenStorageOnILockBytes,
384 ITStorageImpl_StgSetTimes,
385 ITStorageImpl_SetControlData,
386 ITStorageImpl_DefaultControlData,
387 ITStorageImpl_Compact,
390 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
395 return CLASS_E_NOAGGREGATION;
397 its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
398 its->vtbl_IITStorage = &ITStorageImpl_Vtbl;
401 TRACE("-> %p\n", its);
402 *ppObj = (LPVOID) its;
403 InterlockedIncrement(&dll_count);
408 /*****************************************************************************/
410 HRESULT WINAPI DllRegisterServer(void)
416 HRESULT WINAPI DllCanUnloadNow(void)
418 TRACE("dll_count = %lu\n", dll_count);
419 return dll_count ? S_FALSE : S_OK;