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
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(itss
);
52 static HRESULT
ITSS_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
56 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
59 case DLL_PROCESS_ATTACH
:
60 DisableThreadLibraryCalls(hInstDLL
);
62 case DLL_PROCESS_DETACH
:
68 /******************************************************************************
72 IClassFactory ITF_IClassFactory
;
75 HRESULT (*pfnCreateInstance
)(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
78 struct object_creation_info
82 HRESULT (*pfnCreateInstance
)(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
85 static const struct object_creation_info object_creation
[] =
87 { &CLSID_ITStorage
, "ITStorage", ITSS_create
},
88 { &CLSID_ITSProtocol
, "ITSProtocol", ITS_IParseDisplayName_create
},
92 ITSSCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
)
94 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
96 if (IsEqualGUID(riid
, &IID_IUnknown
)
97 || IsEqualGUID(riid
, &IID_IClassFactory
))
99 IClassFactory_AddRef(iface
);
104 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
105 return E_NOINTERFACE
;
108 static ULONG WINAPI
ITSSCF_AddRef(LPCLASSFACTORY iface
)
110 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
111 return InterlockedIncrement(&This
->ref
);
114 static ULONG WINAPI
ITSSCF_Release(LPCLASSFACTORY iface
)
116 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
118 ULONG ref
= InterlockedDecrement(&This
->ref
);
121 HeapFree(GetProcessHeap(), 0, This
);
122 InterlockedDecrement(&dll_count
);
129 static HRESULT WINAPI
ITSSCF_CreateInstance(LPCLASSFACTORY iface
, LPUNKNOWN pOuter
,
130 REFIID riid
, LPVOID
*ppobj
)
132 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
136 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
139 hres
= This
->pfnCreateInstance(pOuter
, (LPVOID
*) &punk
);
140 if (SUCCEEDED(hres
)) {
141 hres
= IUnknown_QueryInterface(punk
, riid
, ppobj
);
142 IUnknown_Release(punk
);
147 static HRESULT WINAPI
ITSSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
149 TRACE("(%p)->(%d)\n", iface
, dolock
);
152 InterlockedIncrement(&dll_count
);
154 InterlockedDecrement(&dll_count
);
159 static const IClassFactoryVtbl ITSSCF_Vtbl
=
161 ITSSCF_QueryInterface
,
164 ITSSCF_CreateInstance
,
169 /***********************************************************************
170 * DllGetClassObject (ITSS.@)
172 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
175 IClassFactoryImpl
*factory
;
177 TRACE("%s %s %p\n",debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
179 if ( !IsEqualGUID( &IID_IClassFactory
, iid
)
180 && ! IsEqualGUID( &IID_IUnknown
, iid
) )
181 return E_NOINTERFACE
;
183 for (i
=0; i
< sizeof(object_creation
)/sizeof(object_creation
[0]); i
++)
185 if (IsEqualGUID(object_creation
[i
].clsid
, rclsid
))
189 if (i
== sizeof(object_creation
)/sizeof(object_creation
[0]))
191 FIXME("%s: no class found.\n", debugstr_guid(rclsid
));
192 return CLASS_E_CLASSNOTAVAILABLE
;
195 TRACE("Creating a class factory for %s\n",object_creation
[i
].szClassName
);
197 factory
= HeapAlloc(GetProcessHeap(), 0, sizeof(*factory
));
198 if (factory
== NULL
) return E_OUTOFMEMORY
;
200 factory
->ITF_IClassFactory
.lpVtbl
= &ITSSCF_Vtbl
;
203 factory
->pfnCreateInstance
= object_creation
[i
].pfnCreateInstance
;
205 *ppv
= &(factory
->ITF_IClassFactory
);
206 InterlockedIncrement(&dll_count
);
208 TRACE("(%p) <- %p\n", ppv
, &(factory
->ITF_IClassFactory
) );
213 /*****************************************************************************/
216 const IITStorageVtbl
*vtbl_IITStorage
;
221 HRESULT WINAPI
ITStorageImpl_QueryInterface(
226 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
227 if (IsEqualGUID(riid
, &IID_IUnknown
)
228 || IsEqualGUID(riid
, &IID_IITStorage
))
230 IClassFactory_AddRef(iface
);
235 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
236 return E_NOINTERFACE
;
239 ULONG WINAPI
ITStorageImpl_AddRef(
242 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
244 return InterlockedIncrement(&This
->ref
);
247 ULONG WINAPI
ITStorageImpl_Release(
250 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
251 ULONG ref
= InterlockedDecrement(&This
->ref
);
254 HeapFree(GetProcessHeap(), 0, This
);
255 InterlockedDecrement(&dll_count
);
261 HRESULT WINAPI
ITStorageImpl_StgCreateDocfile(
263 const WCHAR
* pwcsName
,
266 IStorage
** ppstgOpen
)
268 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
270 TRACE("%p %s %lu %lu %p\n", This
,
271 debugstr_w(pwcsName
), grfMode
, reserved
, ppstgOpen
);
273 return ITSS_StgOpenStorage( pwcsName
, NULL
, grfMode
,
274 0, reserved
, ppstgOpen
);
277 HRESULT WINAPI
ITStorageImpl_StgCreateDocfileOnILockBytes(
282 IStorage
** ppstgOpen
)
284 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
289 HRESULT WINAPI
ITStorageImpl_StgIsStorageFile(
291 const WCHAR
* pwcsName
)
293 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
298 HRESULT WINAPI
ITStorageImpl_StgIsStorageILockBytes(
302 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
307 HRESULT WINAPI
ITStorageImpl_StgOpenStorage(
309 const WCHAR
* pwcsName
,
310 IStorage
* pstgPriority
,
314 IStorage
** ppstgOpen
)
316 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
318 TRACE("%p %s %p %ld %p\n", This
, debugstr_w( pwcsName
),
319 pstgPriority
, grfMode
, snbExclude
);
321 return ITSS_StgOpenStorage( pwcsName
, pstgPriority
, grfMode
,
322 snbExclude
, reserved
, ppstgOpen
);
325 HRESULT WINAPI
ITStorageImpl_StgOpenStorageOnILockBytes(
328 IStorage
* pStgPriority
,
332 IStorage
** ppstgOpen
)
334 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
339 HRESULT WINAPI
ITStorageImpl_StgSetTimes(
346 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
351 HRESULT WINAPI
ITStorageImpl_SetControlData(
353 PITS_Control_Data pControlData
)
355 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
360 HRESULT WINAPI
ITStorageImpl_DefaultControlData(
362 PITS_Control_Data
* ppControlData
)
364 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
369 HRESULT WINAPI
ITStorageImpl_Compact(
371 const WCHAR
* pwcsName
,
374 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
379 static const IITStorageVtbl ITStorageImpl_Vtbl
=
381 ITStorageImpl_QueryInterface
,
382 ITStorageImpl_AddRef
,
383 ITStorageImpl_Release
,
384 ITStorageImpl_StgCreateDocfile
,
385 ITStorageImpl_StgCreateDocfileOnILockBytes
,
386 ITStorageImpl_StgIsStorageFile
,
387 ITStorageImpl_StgIsStorageILockBytes
,
388 ITStorageImpl_StgOpenStorage
,
389 ITStorageImpl_StgOpenStorageOnILockBytes
,
390 ITStorageImpl_StgSetTimes
,
391 ITStorageImpl_SetControlData
,
392 ITStorageImpl_DefaultControlData
,
393 ITStorageImpl_Compact
,
396 static HRESULT
ITSS_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
401 return CLASS_E_NOAGGREGATION
;
403 its
= HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl
) );
404 its
->vtbl_IITStorage
= &ITStorageImpl_Vtbl
;
407 TRACE("-> %p\n", its
);
408 *ppObj
= (LPVOID
) its
;
409 InterlockedIncrement(&dll_count
);
414 /*****************************************************************************/
416 HRESULT WINAPI
DllRegisterServer(void)
422 HRESULT WINAPI
DllCanUnloadNow(void)
424 TRACE("dll_count = %lu\n", dll_count
);
425 return dll_count
? S_FALSE
: S_OK
;