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"
46 #include "wine/itss.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(itss
);
50 static HRESULT
ITSS_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
54 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
57 case DLL_PROCESS_ATTACH
:
58 DisableThreadLibraryCalls(hInstDLL
);
60 case DLL_PROCESS_DETACH
:
66 /******************************************************************************
70 IClassFactory ITF_IClassFactory
;
73 HRESULT (*pfnCreateInstance
)(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
76 struct object_creation_info
80 HRESULT (*pfnCreateInstance
)(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
83 static const struct object_creation_info object_creation
[] =
85 { &CLSID_ITStorage
, "ITStorage", ITSS_create
},
86 { &CLSID_ITSProtocol
, "ITSProtocol", ITS_IParseDisplayName_create
},
90 ITSSCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
)
92 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
94 if (IsEqualGUID(riid
, &IID_IUnknown
)
95 || IsEqualGUID(riid
, &IID_IClassFactory
))
97 IClassFactory_AddRef(iface
);
102 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
103 return E_NOINTERFACE
;
106 static ULONG WINAPI
ITSSCF_AddRef(LPCLASSFACTORY iface
)
108 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
109 return InterlockedIncrement(&This
->ref
);
112 static ULONG WINAPI
ITSSCF_Release(LPCLASSFACTORY iface
)
114 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
116 ULONG ref
= InterlockedDecrement(&This
->ref
);
119 HeapFree(GetProcessHeap(), 0, This
);
120 InterlockedDecrement(&dll_count
);
127 static HRESULT WINAPI
ITSSCF_CreateInstance(LPCLASSFACTORY iface
, LPUNKNOWN pOuter
,
128 REFIID riid
, LPVOID
*ppobj
)
130 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
134 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
137 hres
= This
->pfnCreateInstance(pOuter
, (LPVOID
*) &punk
);
138 if (SUCCEEDED(hres
)) {
139 hres
= IUnknown_QueryInterface(punk
, riid
, ppobj
);
140 IUnknown_Release(punk
);
145 static HRESULT WINAPI
ITSSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
147 TRACE("(%p)->(%d)\n", iface
, dolock
);
150 InterlockedIncrement(&dll_count
);
152 InterlockedDecrement(&dll_count
);
157 static const IClassFactoryVtbl ITSSCF_Vtbl
=
159 ITSSCF_QueryInterface
,
162 ITSSCF_CreateInstance
,
167 /***********************************************************************
168 * DllGetClassObject (ITSS.@)
170 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
173 IClassFactoryImpl
*factory
;
175 TRACE("%s %s %p\n",debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
177 if ( !IsEqualGUID( &IID_IClassFactory
, iid
)
178 && ! IsEqualGUID( &IID_IUnknown
, iid
) )
179 return E_NOINTERFACE
;
181 for (i
=0; i
< sizeof(object_creation
)/sizeof(object_creation
[0]); i
++)
183 if (IsEqualGUID(object_creation
[i
].clsid
, rclsid
))
187 if (i
== sizeof(object_creation
)/sizeof(object_creation
[0]))
189 FIXME("%s: no class found.\n", debugstr_guid(rclsid
));
190 return CLASS_E_CLASSNOTAVAILABLE
;
193 TRACE("Creating a class factory for %s\n",object_creation
[i
].szClassName
);
195 factory
= HeapAlloc(GetProcessHeap(), 0, sizeof(*factory
));
196 if (factory
== NULL
) return E_OUTOFMEMORY
;
198 factory
->ITF_IClassFactory
.lpVtbl
= &ITSSCF_Vtbl
;
201 factory
->pfnCreateInstance
= object_creation
[i
].pfnCreateInstance
;
203 *ppv
= &(factory
->ITF_IClassFactory
);
204 InterlockedIncrement(&dll_count
);
206 TRACE("(%p) <- %p\n", ppv
, &(factory
->ITF_IClassFactory
) );
211 /*****************************************************************************/
214 const IITStorageVtbl
*vtbl_IITStorage
;
219 HRESULT WINAPI
ITStorageImpl_QueryInterface(
224 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
225 if (IsEqualGUID(riid
, &IID_IUnknown
)
226 || IsEqualGUID(riid
, &IID_IITStorage
))
228 IClassFactory_AddRef(iface
);
233 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
234 return E_NOINTERFACE
;
237 ULONG WINAPI
ITStorageImpl_AddRef(
240 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
242 return InterlockedIncrement(&This
->ref
);
245 ULONG WINAPI
ITStorageImpl_Release(
248 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
249 ULONG ref
= InterlockedDecrement(&This
->ref
);
252 HeapFree(GetProcessHeap(), 0, This
);
253 InterlockedDecrement(&dll_count
);
259 HRESULT WINAPI
ITStorageImpl_StgCreateDocfile(
261 const WCHAR
* pwcsName
,
264 IStorage
** ppstgOpen
)
266 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
268 TRACE("%p %s %lu %lu %p\n", This
,
269 debugstr_w(pwcsName
), grfMode
, reserved
, ppstgOpen
);
271 return ITSS_StgOpenStorage( pwcsName
, NULL
, grfMode
,
272 0, reserved
, ppstgOpen
);
275 HRESULT WINAPI
ITStorageImpl_StgCreateDocfileOnILockBytes(
280 IStorage
** ppstgOpen
)
282 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
287 HRESULT WINAPI
ITStorageImpl_StgIsStorageFile(
289 const WCHAR
* pwcsName
)
291 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
296 HRESULT WINAPI
ITStorageImpl_StgIsStorageILockBytes(
300 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
305 HRESULT WINAPI
ITStorageImpl_StgOpenStorage(
307 const WCHAR
* pwcsName
,
308 IStorage
* pstgPriority
,
312 IStorage
** ppstgOpen
)
314 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
316 TRACE("%p %s %p %ld %p\n", This
, debugstr_w( pwcsName
),
317 pstgPriority
, grfMode
, snbExclude
);
319 return ITSS_StgOpenStorage( pwcsName
, pstgPriority
, grfMode
,
320 snbExclude
, reserved
, ppstgOpen
);
323 HRESULT WINAPI
ITStorageImpl_StgOpenStorageOnILockBytes(
326 IStorage
* pStgPriority
,
330 IStorage
** ppstgOpen
)
332 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
337 HRESULT WINAPI
ITStorageImpl_StgSetTimes(
344 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
349 HRESULT WINAPI
ITStorageImpl_SetControlData(
351 PITS_Control_Data pControlData
)
353 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
358 HRESULT WINAPI
ITStorageImpl_DefaultControlData(
360 PITS_Control_Data
* ppControlData
)
362 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
367 HRESULT WINAPI
ITStorageImpl_Compact(
369 const WCHAR
* pwcsName
,
372 ITStorageImpl
*This
= (ITStorageImpl
*)iface
;
377 static const IITStorageVtbl ITStorageImpl_Vtbl
=
379 ITStorageImpl_QueryInterface
,
380 ITStorageImpl_AddRef
,
381 ITStorageImpl_Release
,
382 ITStorageImpl_StgCreateDocfile
,
383 ITStorageImpl_StgCreateDocfileOnILockBytes
,
384 ITStorageImpl_StgIsStorageFile
,
385 ITStorageImpl_StgIsStorageILockBytes
,
386 ITStorageImpl_StgOpenStorage
,
387 ITStorageImpl_StgOpenStorageOnILockBytes
,
388 ITStorageImpl_StgSetTimes
,
389 ITStorageImpl_SetControlData
,
390 ITStorageImpl_DefaultControlData
,
391 ITStorageImpl_Compact
,
394 static HRESULT
ITSS_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
399 return CLASS_E_NOAGGREGATION
;
401 its
= HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl
) );
402 its
->vtbl_IITStorage
= &ITStorageImpl_Vtbl
;
405 TRACE("-> %p\n", its
);
406 *ppObj
= (LPVOID
) its
;
407 InterlockedIncrement(&dll_count
);
412 /*****************************************************************************/
414 HRESULT WINAPI
DllCanUnloadNow(void)
416 TRACE("dll_count = %lu\n", dll_count
);
417 return dll_count
? S_FALSE
: S_OK
;