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 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
174 IClassFactoryImpl *factory;
176 TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
178 if ( !IsEqualGUID( &IID_IClassFactory, iid )
179 && ! IsEqualGUID( &IID_IUnknown, iid) )
180 return E_NOINTERFACE;
182 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
184 if (IsEqualGUID(object_creation[i].clsid, rclsid))
188 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
190 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
191 return CLASS_E_CLASSNOTAVAILABLE;
194 TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
196 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
197 if (factory == NULL) return E_OUTOFMEMORY;
199 factory->ITF_IClassFactory.lpVtbl = &ITSSCF_Vtbl;
202 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
204 *ppv = &(factory->ITF_IClassFactory);
205 InterlockedIncrement(&dll_count);
207 TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
212 /*****************************************************************************/
215 IITStorageVtbl *vtbl_IITStorage;
220 HRESULT WINAPI ITStorageImpl_QueryInterface(
225 ITStorageImpl *This = (ITStorageImpl *)iface;
226 if (IsEqualGUID(riid, &IID_IUnknown)
227 || IsEqualGUID(riid, &IID_IITStorage))
229 IClassFactory_AddRef(iface);
234 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
235 return E_NOINTERFACE;
238 ULONG WINAPI ITStorageImpl_AddRef(
241 ITStorageImpl *This = (ITStorageImpl *)iface;
243 return InterlockedIncrement(&This->ref);
246 ULONG WINAPI ITStorageImpl_Release(
249 ITStorageImpl *This = (ITStorageImpl *)iface;
250 ULONG ref = InterlockedDecrement(&This->ref);
253 HeapFree(GetProcessHeap(), 0, This);
254 InterlockedDecrement(&dll_count);
260 HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
262 const WCHAR* pwcsName,
265 IStorage** ppstgOpen)
267 ITStorageImpl *This = (ITStorageImpl *)iface;
269 TRACE("%p %s %lu %lu %p\n", This,
270 debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
272 return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
273 0, reserved, ppstgOpen);
276 HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
281 IStorage** ppstgOpen)
283 ITStorageImpl *This = (ITStorageImpl *)iface;
288 HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
290 const WCHAR* pwcsName)
292 ITStorageImpl *This = (ITStorageImpl *)iface;
297 HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
301 ITStorageImpl *This = (ITStorageImpl *)iface;
306 HRESULT WINAPI ITStorageImpl_StgOpenStorage(
308 const WCHAR* pwcsName,
309 IStorage* pstgPriority,
313 IStorage** ppstgOpen)
315 ITStorageImpl *This = (ITStorageImpl *)iface;
317 TRACE("%p %s %p %ld %p\n", This, debugstr_w( pwcsName ),
318 pstgPriority, grfMode, snbExclude );
320 return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
321 snbExclude, reserved, ppstgOpen);
324 HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
327 IStorage* pStgPriority,
331 IStorage** ppstgOpen)
333 ITStorageImpl *This = (ITStorageImpl *)iface;
338 HRESULT WINAPI ITStorageImpl_StgSetTimes(
345 ITStorageImpl *This = (ITStorageImpl *)iface;
350 HRESULT WINAPI ITStorageImpl_SetControlData(
352 PITS_Control_Data pControlData)
354 ITStorageImpl *This = (ITStorageImpl *)iface;
359 HRESULT WINAPI ITStorageImpl_DefaultControlData(
361 PITS_Control_Data* ppControlData)
363 ITStorageImpl *This = (ITStorageImpl *)iface;
368 HRESULT WINAPI ITStorageImpl_Compact(
370 const WCHAR* pwcsName,
373 ITStorageImpl *This = (ITStorageImpl *)iface;
378 static IITStorageVtbl ITStorageImpl_Vtbl =
380 ITStorageImpl_QueryInterface,
381 ITStorageImpl_AddRef,
382 ITStorageImpl_Release,
383 ITStorageImpl_StgCreateDocfile,
384 ITStorageImpl_StgCreateDocfileOnILockBytes,
385 ITStorageImpl_StgIsStorageFile,
386 ITStorageImpl_StgIsStorageILockBytes,
387 ITStorageImpl_StgOpenStorage,
388 ITStorageImpl_StgOpenStorageOnILockBytes,
389 ITStorageImpl_StgSetTimes,
390 ITStorageImpl_SetControlData,
391 ITStorageImpl_DefaultControlData,
392 ITStorageImpl_Compact,
395 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
400 return CLASS_E_NOAGGREGATION;
402 its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
403 its->vtbl_IITStorage = &ITStorageImpl_Vtbl;
406 TRACE("-> %p\n", its);
407 *ppObj = (LPVOID) its;
408 InterlockedIncrement(&dll_count);
413 /*****************************************************************************/
415 HRESULT WINAPI DllRegisterServer(void)
421 HRESULT WINAPI DllCanUnloadNow(void)
423 TRACE("dll_count = %lu\n", dll_count);
424 return dll_count ? S_FALSE : S_OK;