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
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
47 #include "wine/itss.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(itss
);
51 static HRESULT
ITSS_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
54 static HINSTANCE hInst
;
56 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
59 case DLL_PROCESS_ATTACH
:
60 DisableThreadLibraryCalls(hInstDLL
);
63 case DLL_PROCESS_DETACH
:
69 /******************************************************************************
73 const IClassFactoryVtbl
*lpVtbl
;
74 HRESULT (*pfnCreateInstance
)(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
78 ITSSCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
)
80 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
82 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
83 IsEqualGUID(riid
, &IID_IClassFactory
))
85 IClassFactory_AddRef(iface
);
90 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
94 static ULONG WINAPI
ITSSCF_AddRef(LPCLASSFACTORY iface
)
100 static ULONG WINAPI
ITSSCF_Release(LPCLASSFACTORY iface
)
107 static HRESULT WINAPI
ITSSCF_CreateInstance(LPCLASSFACTORY iface
, LPUNKNOWN pOuter
,
108 REFIID riid
, LPVOID
*ppobj
)
110 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
114 TRACE("(%p)->(%p,%s,%p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
117 hres
= This
->pfnCreateInstance(pOuter
, (LPVOID
*) &punk
);
118 if (SUCCEEDED(hres
)) {
119 hres
= IUnknown_QueryInterface(punk
, riid
, ppobj
);
120 IUnknown_Release(punk
);
125 static HRESULT WINAPI
ITSSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
127 TRACE("(%p)->(%d)\n", iface
, dolock
);
137 static const IClassFactoryVtbl ITSSCF_Vtbl
=
139 ITSSCF_QueryInterface
,
142 ITSSCF_CreateInstance
,
146 static const IClassFactoryImpl ITStorage_factory
= { &ITSSCF_Vtbl
, ITSS_create
};
147 static const IClassFactoryImpl MSITStore_factory
= { &ITSSCF_Vtbl
, ITS_IParseDisplayName_create
};
148 static const IClassFactoryImpl ITSProtocol_factory
= { &ITSSCF_Vtbl
, ITSProtocol_create
};
150 /***********************************************************************
151 * DllGetClassObject (ITSS.@)
153 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
155 const IClassFactoryImpl
*factory
;
157 TRACE("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
159 if (IsEqualGUID(&CLSID_ITStorage
, rclsid
))
160 factory
= &ITStorage_factory
;
161 else if (IsEqualGUID(&CLSID_MSITStore
, rclsid
))
162 factory
= &MSITStore_factory
;
163 else if (IsEqualGUID(&CLSID_ITSProtocol
, rclsid
))
164 factory
= &ITSProtocol_factory
;
167 FIXME("%s: no class found.\n", debugstr_guid(rclsid
));
168 return CLASS_E_CLASSNOTAVAILABLE
;
171 return IUnknown_QueryInterface( (IUnknown
*) factory
, iid
, ppv
);
174 /*****************************************************************************/
177 const IITStorageVtbl
*vtbl_IITStorage
;
182 static HRESULT WINAPI
ITStorageImpl_QueryInterface(
187 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
188 if (IsEqualGUID(riid
, &IID_IUnknown
)
189 || IsEqualGUID(riid
, &IID_IITStorage
))
191 IClassFactory_AddRef(iface
);
196 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
197 return E_NOINTERFACE
;
200 static ULONG WINAPI
ITStorageImpl_AddRef(
203 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
205 return InterlockedIncrement(&This
->ref
);
208 static ULONG WINAPI
ITStorageImpl_Release(
211 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
212 ULONG ref
= InterlockedDecrement(&This
->ref
);
215 HeapFree(GetProcessHeap(), 0, This
);
222 static HRESULT WINAPI
ITStorageImpl_StgCreateDocfile(
224 const WCHAR
* pwcsName
,
227 IStorage
** ppstgOpen
)
229 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
231 TRACE("%p %s %u %u %p\n", This
,
232 debugstr_w(pwcsName
), grfMode
, reserved
, ppstgOpen
);
234 return ITSS_StgOpenStorage( pwcsName
, NULL
, grfMode
,
235 0, reserved
, ppstgOpen
);
238 static HRESULT WINAPI
ITStorageImpl_StgCreateDocfileOnILockBytes(
243 IStorage
** ppstgOpen
)
245 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
250 static HRESULT WINAPI
ITStorageImpl_StgIsStorageFile(
252 const WCHAR
* pwcsName
)
254 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
259 static HRESULT WINAPI
ITStorageImpl_StgIsStorageILockBytes(
263 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
268 static HRESULT WINAPI
ITStorageImpl_StgOpenStorage(
270 const WCHAR
* pwcsName
,
271 IStorage
* pstgPriority
,
275 IStorage
** ppstgOpen
)
277 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
279 TRACE("%p %s %p %d %p\n", This
, debugstr_w( pwcsName
),
280 pstgPriority
, grfMode
, snbExclude
);
282 return ITSS_StgOpenStorage( pwcsName
, pstgPriority
, grfMode
,
283 snbExclude
, reserved
, ppstgOpen
);
286 static HRESULT WINAPI
ITStorageImpl_StgOpenStorageOnILockBytes(
289 IStorage
* pStgPriority
,
293 IStorage
** ppstgOpen
)
295 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
300 static HRESULT WINAPI
ITStorageImpl_StgSetTimes(
307 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
312 static HRESULT WINAPI
ITStorageImpl_SetControlData(
314 PITS_Control_Data pControlData
)
316 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
321 static HRESULT WINAPI
ITStorageImpl_DefaultControlData(
323 PITS_Control_Data
* ppControlData
)
325 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
330 static HRESULT WINAPI
ITStorageImpl_Compact(
332 const WCHAR
* pwcsName
,
335 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
340 static const IITStorageVtbl ITStorageImpl_Vtbl
=
342 ITStorageImpl_QueryInterface
,
343 ITStorageImpl_AddRef
,
344 ITStorageImpl_Release
,
345 ITStorageImpl_StgCreateDocfile
,
346 ITStorageImpl_StgCreateDocfileOnILockBytes
,
347 ITStorageImpl_StgIsStorageFile
,
348 ITStorageImpl_StgIsStorageILockBytes
,
349 ITStorageImpl_StgOpenStorage
,
350 ITStorageImpl_StgOpenStorageOnILockBytes
,
351 ITStorageImpl_StgSetTimes
,
352 ITStorageImpl_SetControlData
,
353 ITStorageImpl_DefaultControlData
,
354 ITStorageImpl_Compact
,
357 static HRESULT
ITSS_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
362 return CLASS_E_NOAGGREGATION
;
364 its
= HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl
) );
365 its
->vtbl_IITStorage
= &ITStorageImpl_Vtbl
;
368 TRACE("-> %p\n", its
);
369 *ppObj
= (LPVOID
) its
;
375 /*****************************************************************************/
377 HRESULT WINAPI
DllCanUnloadNow(void)
379 TRACE("dll_count = %u\n", dll_count
);
380 return dll_count
? S_FALSE
: S_OK
;
383 #define INF_SET_ID(id) \
386 static CHAR name[] = #id; \
388 pse[i].pszName = name; \
392 #define INF_SET_CLSID(clsid) INF_SET_ID(CLSID_ ## clsid)
394 static HRESULT
register_server(BOOL do_register
)
398 typeof(RegInstallA
) *pRegInstall
;
401 static CLSID
const *clsids
[4];
404 static const WCHAR wszAdvpack
[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
406 INF_SET_CLSID(ITStorage
);
407 INF_SET_CLSID(MSFSStore
);
408 INF_SET_CLSID(MSITStore
);
409 INF_SET_CLSID(ITSProtocol
);
411 strtable
.cEntries
= sizeof(pse
)/sizeof(pse
[0]);
414 for(i
=0; i
< strtable
.cEntries
; i
++) {
415 pse
[i
].pszValue
= HeapAlloc(GetProcessHeap(), 0, 39);
416 sprintf(pse
[i
].pszValue
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
417 clsids
[i
]->Data1
, clsids
[i
]->Data2
, clsids
[i
]->Data3
, clsids
[i
]->Data4
[0],
418 clsids
[i
]->Data4
[1], clsids
[i
]->Data4
[2], clsids
[i
]->Data4
[3], clsids
[i
]->Data4
[4],
419 clsids
[i
]->Data4
[5], clsids
[i
]->Data4
[6], clsids
[i
]->Data4
[7]);
422 hAdvpack
= LoadLibraryW(wszAdvpack
);
423 pRegInstall
= (typeof(RegInstallA
)*)GetProcAddress(hAdvpack
, "RegInstall");
425 hres
= pRegInstall(hInst
, do_register
? "RegisterDll" : "UnregisterDll", &strtable
);
427 for(i
=0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++)
428 HeapFree(GetProcessHeap(), 0, pse
[i
].pszValue
);
436 /***********************************************************************
437 * DllRegisterServer (ITSS.@)
439 HRESULT WINAPI
DllRegisterServer(void)
441 return register_server(TRUE
);
444 /***********************************************************************
445 * DllUnregisterServer (ITSS.@)
447 HRESULT WINAPI
DllUnregisterServer(void)
449 return register_server(FALSE
);