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
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
44 #include "wine/itss.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(itss);
48 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj);
51 static HINSTANCE hInst;
53 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
56 case DLL_PROCESS_ATTACH:
57 DisableThreadLibraryCalls(hInstDLL);
60 case DLL_PROCESS_DETACH:
66 /******************************************************************************
70 IClassFactory IClassFactory_iface;
71 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
74 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
76 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
80 ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
82 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
84 if (IsEqualGUID(riid, &IID_IUnknown) ||
85 IsEqualGUID(riid, &IID_IClassFactory))
87 IClassFactory_AddRef(iface);
92 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
96 static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
102 static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
109 static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
110 REFIID riid, LPVOID *ppobj)
112 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
116 TRACE("(%p)->(%p,%s,%p)\n", This, pOuter, debugstr_guid(riid), ppobj);
119 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
120 if (SUCCEEDED(hres)) {
121 hres = IUnknown_QueryInterface(punk, riid, ppobj);
122 IUnknown_Release(punk);
127 static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
129 TRACE("(%p)->(%d)\n", iface, dolock);
139 static const IClassFactoryVtbl ITSSCF_Vtbl =
141 ITSSCF_QueryInterface,
144 ITSSCF_CreateInstance,
148 static const IClassFactoryImpl ITStorage_factory = { { &ITSSCF_Vtbl }, ITSS_create };
149 static const IClassFactoryImpl MSITStore_factory = { { &ITSSCF_Vtbl }, ITS_IParseDisplayName_create };
150 static const IClassFactoryImpl ITSProtocol_factory = { { &ITSSCF_Vtbl }, ITSProtocol_create };
152 /***********************************************************************
153 * DllGetClassObject (ITSS.@)
155 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
157 const IClassFactoryImpl *factory;
159 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
161 if (IsEqualGUID(&CLSID_ITStorage, rclsid))
162 factory = &ITStorage_factory;
163 else if (IsEqualGUID(&CLSID_MSITStore, rclsid))
164 factory = &MSITStore_factory;
165 else if (IsEqualGUID(&CLSID_ITSProtocol, rclsid))
166 factory = &ITSProtocol_factory;
169 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
170 return CLASS_E_CLASSNOTAVAILABLE;
173 return IUnknown_QueryInterface( (IUnknown*) factory, iid, ppv );
176 /*****************************************************************************/
179 IITStorage IITStorage_iface;
183 static inline ITStorageImpl *impl_from_IITStorage(IITStorage *iface)
185 return CONTAINING_RECORD(iface, ITStorageImpl, IITStorage_iface);
189 static HRESULT WINAPI ITStorageImpl_QueryInterface(
194 ITStorageImpl *This = impl_from_IITStorage(iface);
195 if (IsEqualGUID(riid, &IID_IUnknown)
196 || IsEqualGUID(riid, &IID_IITStorage))
198 IClassFactory_AddRef(iface);
203 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
204 return E_NOINTERFACE;
207 static ULONG WINAPI ITStorageImpl_AddRef(
210 ITStorageImpl *This = impl_from_IITStorage(iface);
212 return InterlockedIncrement(&This->ref);
215 static ULONG WINAPI ITStorageImpl_Release(
218 ITStorageImpl *This = impl_from_IITStorage(iface);
219 ULONG ref = InterlockedDecrement(&This->ref);
222 HeapFree(GetProcessHeap(), 0, This);
229 static HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
231 const WCHAR* pwcsName,
234 IStorage** ppstgOpen)
236 ITStorageImpl *This = impl_from_IITStorage(iface);
238 TRACE("%p %s %u %u %p\n", This,
239 debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
241 return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
242 0, reserved, ppstgOpen);
245 static HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
250 IStorage** ppstgOpen)
252 ITStorageImpl *This = impl_from_IITStorage(iface);
257 static HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
259 const WCHAR* pwcsName)
261 ITStorageImpl *This = impl_from_IITStorage(iface);
266 static HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
270 ITStorageImpl *This = impl_from_IITStorage(iface);
275 static HRESULT WINAPI ITStorageImpl_StgOpenStorage(
277 const WCHAR* pwcsName,
278 IStorage* pstgPriority,
282 IStorage** ppstgOpen)
284 ITStorageImpl *This = impl_from_IITStorage(iface);
286 TRACE("%p %s %p %d %p\n", This, debugstr_w( pwcsName ),
287 pstgPriority, grfMode, snbExclude );
289 return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
290 snbExclude, reserved, ppstgOpen);
293 static HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
296 IStorage* pStgPriority,
300 IStorage** ppstgOpen)
302 ITStorageImpl *This = impl_from_IITStorage(iface);
307 static HRESULT WINAPI ITStorageImpl_StgSetTimes(
309 const WCHAR* lpszName,
310 const FILETIME* pctime,
311 const FILETIME* patime,
312 const FILETIME* pmtime)
314 ITStorageImpl *This = impl_from_IITStorage(iface);
319 static HRESULT WINAPI ITStorageImpl_SetControlData(
321 PITS_Control_Data pControlData)
323 ITStorageImpl *This = impl_from_IITStorage(iface);
328 static HRESULT WINAPI ITStorageImpl_DefaultControlData(
330 PITS_Control_Data* ppControlData)
332 ITStorageImpl *This = impl_from_IITStorage(iface);
337 static HRESULT WINAPI ITStorageImpl_Compact(
339 const WCHAR* pwcsName,
342 ITStorageImpl *This = impl_from_IITStorage(iface);
347 static const IITStorageVtbl ITStorageImpl_Vtbl =
349 ITStorageImpl_QueryInterface,
350 ITStorageImpl_AddRef,
351 ITStorageImpl_Release,
352 ITStorageImpl_StgCreateDocfile,
353 ITStorageImpl_StgCreateDocfileOnILockBytes,
354 ITStorageImpl_StgIsStorageFile,
355 ITStorageImpl_StgIsStorageILockBytes,
356 ITStorageImpl_StgOpenStorage,
357 ITStorageImpl_StgOpenStorageOnILockBytes,
358 ITStorageImpl_StgSetTimes,
359 ITStorageImpl_SetControlData,
360 ITStorageImpl_DefaultControlData,
361 ITStorageImpl_Compact,
364 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
369 return CLASS_E_NOAGGREGATION;
371 its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
372 its->IITStorage_iface.lpVtbl = &ITStorageImpl_Vtbl;
375 TRACE("-> %p\n", its);
382 /*****************************************************************************/
384 HRESULT WINAPI DllCanUnloadNow(void)
386 TRACE("dll_count = %u\n", dll_count);
387 return dll_count ? S_FALSE : S_OK;
390 #define INF_SET_ID(id) \
393 static CHAR name[] = #id; \
395 pse[i].pszName = name; \
399 #define INF_SET_CLSID(clsid) INF_SET_ID(CLSID_ ## clsid)
401 static HRESULT register_server(BOOL do_register)
405 HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
408 static CLSID const *clsids[4];
411 static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
413 INF_SET_CLSID(ITStorage);
414 INF_SET_CLSID(MSFSStore);
415 INF_SET_CLSID(MSITStore);
416 INF_SET_CLSID(ITSProtocol);
418 strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
421 for(i=0; i < strtable.cEntries; i++) {
422 pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
423 sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
424 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
425 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
426 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
429 hAdvpack = LoadLibraryW(wszAdvpack);
430 pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
432 hres = pRegInstall(hInst, do_register ? "RegisterDll" : "UnregisterDll", &strtable);
434 for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
435 HeapFree(GetProcessHeap(), 0, pse[i].pszValue);
443 /***********************************************************************
444 * DllRegisterServer (ITSS.@)
446 HRESULT WINAPI DllRegisterServer(void)
448 return register_server(TRUE);
451 /***********************************************************************
452 * DllUnregisterServer (ITSS.@)
454 HRESULT WINAPI DllUnregisterServer(void)
456 return register_server(FALSE);