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 const IClassFactoryVtbl *lpVtbl;
71 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
75 ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
77 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
79 if (IsEqualGUID(riid, &IID_IUnknown) ||
80 IsEqualGUID(riid, &IID_IClassFactory))
82 IClassFactory_AddRef(iface);
87 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
91 static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
97 static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
104 static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
105 REFIID riid, LPVOID *ppobj)
107 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
111 TRACE("(%p)->(%p,%s,%p)\n", This, pOuter, debugstr_guid(riid), ppobj);
114 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
115 if (SUCCEEDED(hres)) {
116 hres = IUnknown_QueryInterface(punk, riid, ppobj);
117 IUnknown_Release(punk);
122 static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
124 TRACE("(%p)->(%d)\n", iface, dolock);
134 static const IClassFactoryVtbl ITSSCF_Vtbl =
136 ITSSCF_QueryInterface,
139 ITSSCF_CreateInstance,
143 static const IClassFactoryImpl ITStorage_factory = { &ITSSCF_Vtbl, ITSS_create };
144 static const IClassFactoryImpl MSITStore_factory = { &ITSSCF_Vtbl, ITS_IParseDisplayName_create };
145 static const IClassFactoryImpl ITSProtocol_factory = { &ITSSCF_Vtbl, ITSProtocol_create };
147 /***********************************************************************
148 * DllGetClassObject (ITSS.@)
150 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
152 const IClassFactoryImpl *factory;
154 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
156 if (IsEqualGUID(&CLSID_ITStorage, rclsid))
157 factory = &ITStorage_factory;
158 else if (IsEqualGUID(&CLSID_MSITStore, rclsid))
159 factory = &MSITStore_factory;
160 else if (IsEqualGUID(&CLSID_ITSProtocol, rclsid))
161 factory = &ITSProtocol_factory;
164 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
165 return CLASS_E_CLASSNOTAVAILABLE;
168 return IUnknown_QueryInterface( (IUnknown*) factory, iid, ppv );
171 /*****************************************************************************/
174 const IITStorageVtbl *vtbl_IITStorage;
179 static HRESULT WINAPI ITStorageImpl_QueryInterface(
184 ITStorageImpl *This = (ITStorageImpl *)iface;
185 if (IsEqualGUID(riid, &IID_IUnknown)
186 || IsEqualGUID(riid, &IID_IITStorage))
188 IClassFactory_AddRef(iface);
193 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
194 return E_NOINTERFACE;
197 static ULONG WINAPI ITStorageImpl_AddRef(
200 ITStorageImpl *This = (ITStorageImpl *)iface;
202 return InterlockedIncrement(&This->ref);
205 static ULONG WINAPI ITStorageImpl_Release(
208 ITStorageImpl *This = (ITStorageImpl *)iface;
209 ULONG ref = InterlockedDecrement(&This->ref);
212 HeapFree(GetProcessHeap(), 0, This);
219 static HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
221 const WCHAR* pwcsName,
224 IStorage** ppstgOpen)
226 ITStorageImpl *This = (ITStorageImpl *)iface;
228 TRACE("%p %s %u %u %p\n", This,
229 debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
231 return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
232 0, reserved, ppstgOpen);
235 static HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
240 IStorage** ppstgOpen)
242 ITStorageImpl *This = (ITStorageImpl *)iface;
247 static HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
249 const WCHAR* pwcsName)
251 ITStorageImpl *This = (ITStorageImpl *)iface;
256 static HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
260 ITStorageImpl *This = (ITStorageImpl *)iface;
265 static HRESULT WINAPI ITStorageImpl_StgOpenStorage(
267 const WCHAR* pwcsName,
268 IStorage* pstgPriority,
272 IStorage** ppstgOpen)
274 ITStorageImpl *This = (ITStorageImpl *)iface;
276 TRACE("%p %s %p %d %p\n", This, debugstr_w( pwcsName ),
277 pstgPriority, grfMode, snbExclude );
279 return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
280 snbExclude, reserved, ppstgOpen);
283 static HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
286 IStorage* pStgPriority,
290 IStorage** ppstgOpen)
292 ITStorageImpl *This = (ITStorageImpl *)iface;
297 static HRESULT WINAPI ITStorageImpl_StgSetTimes(
299 const WCHAR* lpszName,
300 const FILETIME* pctime,
301 const FILETIME* patime,
302 const FILETIME* pmtime)
304 ITStorageImpl *This = (ITStorageImpl *)iface;
309 static HRESULT WINAPI ITStorageImpl_SetControlData(
311 PITS_Control_Data pControlData)
313 ITStorageImpl *This = (ITStorageImpl *)iface;
318 static HRESULT WINAPI ITStorageImpl_DefaultControlData(
320 PITS_Control_Data* ppControlData)
322 ITStorageImpl *This = (ITStorageImpl *)iface;
327 static HRESULT WINAPI ITStorageImpl_Compact(
329 const WCHAR* pwcsName,
332 ITStorageImpl *This = (ITStorageImpl *)iface;
337 static const IITStorageVtbl ITStorageImpl_Vtbl =
339 ITStorageImpl_QueryInterface,
340 ITStorageImpl_AddRef,
341 ITStorageImpl_Release,
342 ITStorageImpl_StgCreateDocfile,
343 ITStorageImpl_StgCreateDocfileOnILockBytes,
344 ITStorageImpl_StgIsStorageFile,
345 ITStorageImpl_StgIsStorageILockBytes,
346 ITStorageImpl_StgOpenStorage,
347 ITStorageImpl_StgOpenStorageOnILockBytes,
348 ITStorageImpl_StgSetTimes,
349 ITStorageImpl_SetControlData,
350 ITStorageImpl_DefaultControlData,
351 ITStorageImpl_Compact,
354 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
359 return CLASS_E_NOAGGREGATION;
361 its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
362 its->vtbl_IITStorage = &ITStorageImpl_Vtbl;
365 TRACE("-> %p\n", its);
372 /*****************************************************************************/
374 HRESULT WINAPI DllCanUnloadNow(void)
376 TRACE("dll_count = %u\n", dll_count);
377 return dll_count ? S_FALSE : S_OK;
380 #define INF_SET_ID(id) \
383 static CHAR name[] = #id; \
385 pse[i].pszName = name; \
389 #define INF_SET_CLSID(clsid) INF_SET_ID(CLSID_ ## clsid)
391 static HRESULT register_server(BOOL do_register)
395 HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
398 static CLSID const *clsids[4];
401 static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
403 INF_SET_CLSID(ITStorage);
404 INF_SET_CLSID(MSFSStore);
405 INF_SET_CLSID(MSITStore);
406 INF_SET_CLSID(ITSProtocol);
408 strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
411 for(i=0; i < strtable.cEntries; i++) {
412 pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
413 sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
414 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
415 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
416 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
419 hAdvpack = LoadLibraryW(wszAdvpack);
420 pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
422 hres = pRegInstall(hInst, do_register ? "RegisterDll" : "UnregisterDll", &strtable);
424 for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
425 HeapFree(GetProcessHeap(), 0, pse[i].pszValue);
433 /***********************************************************************
434 * DllRegisterServer (ITSS.@)
436 HRESULT WINAPI DllRegisterServer(void)
438 return register_server(TRUE);
441 /***********************************************************************
442 * DllUnregisterServer (ITSS.@)
444 HRESULT WINAPI DllUnregisterServer(void)
446 return register_server(FALSE);