2 * Copyright 2011 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "scrrun_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(scrrun
);
36 static HINSTANCE scrrun_instance
;
38 static inline struct provideclassinfo
*impl_from_IProvideClassInfo(IProvideClassInfo
*iface
)
40 return CONTAINING_RECORD(iface
, struct provideclassinfo
, IProvideClassInfo_iface
);
43 typedef HRESULT (*fnCreateInstance
)(LPVOID
*ppObj
);
45 static HRESULT WINAPI
scrruncf_QueryInterface(IClassFactory
*iface
, REFIID riid
, LPVOID
*ppv
)
49 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
50 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
52 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
53 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
58 IUnknown_AddRef((IUnknown
*)*ppv
);
62 WARN("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
66 static ULONG WINAPI
scrruncf_AddRef(IClassFactory
*iface
)
68 TRACE("(%p)\n", iface
);
72 static ULONG WINAPI
scrruncf_Release(IClassFactory
*iface
)
74 TRACE("(%p)\n", iface
);
78 static HRESULT WINAPI
scrruncf_LockServer(IClassFactory
*iface
, BOOL fLock
)
80 TRACE("(%p)->(%x)\n", iface
, fLock
);
84 static const struct IClassFactoryVtbl scrruncf_vtbl
=
86 scrruncf_QueryInterface
,
89 FileSystem_CreateInstance
,
93 static const struct IClassFactoryVtbl dictcf_vtbl
=
95 scrruncf_QueryInterface
,
98 Dictionary_CreateInstance
,
102 static IClassFactory FileSystemFactory
= { &scrruncf_vtbl
};
103 static IClassFactory DictionaryFactory
= { &dictcf_vtbl
};
105 static ITypeLib
*typelib
;
106 static ITypeInfo
*typeinfos
[LAST_tid
];
108 static REFIID tid_ids
[] = {
112 &IID_IDriveCollection
,
114 &IID_IFileCollection
,
117 &IID_IFolderCollection
,
121 static HRESULT
load_typelib(void)
129 hres
= LoadRegTypeLib(&LIBID_Scripting
, 1, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
131 ERR("LoadRegTypeLib failed: %08x\n", hres
);
135 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
136 ITypeLib_Release(tl
);
140 static HRESULT
get_typeinfo_of_guid(const GUID
*guid
, ITypeInfo
**tinfo
)
144 if(FAILED(hres
= load_typelib()))
147 return ITypeLib_GetTypeInfoOfGuid(typelib
, guid
, tinfo
);
150 HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
154 if (FAILED(hres
= load_typelib()))
157 if(!typeinfos
[tid
]) {
160 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
162 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
166 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
167 ITypeInfo_Release(ti
);
170 *typeinfo
= typeinfos
[tid
];
171 ITypeInfo_AddRef(typeinfos
[tid
]);
175 static void release_typelib(void)
182 for (i
= 0; i
< ARRAY_SIZE(typeinfos
); i
++)
184 ITypeInfo_Release(typeinfos
[i
]);
186 ITypeLib_Release(typelib
);
189 static HRESULT WINAPI
provideclassinfo_QueryInterface(IProvideClassInfo
*iface
, REFIID riid
, void **obj
)
191 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
193 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
195 if (IsEqualIID(riid
, &IID_IProvideClassInfo
)) {
197 IProvideClassInfo_AddRef(iface
);
201 return IUnknown_QueryInterface(This
->outer
, riid
, obj
);
204 static ULONG WINAPI
provideclassinfo_AddRef(IProvideClassInfo
*iface
)
206 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
207 return IUnknown_AddRef(This
->outer
);
210 static ULONG WINAPI
provideclassinfo_Release(IProvideClassInfo
*iface
)
212 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
213 return IUnknown_Release(This
->outer
);
216 static HRESULT WINAPI
provideclassinfo_GetClassInfo(IProvideClassInfo
*iface
, ITypeInfo
**ti
)
218 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
220 TRACE("(%p)->(%p)\n", This
, ti
);
222 return get_typeinfo_of_guid(This
->guid
, ti
);
225 static const IProvideClassInfoVtbl provideclassinfovtbl
= {
226 provideclassinfo_QueryInterface
,
227 provideclassinfo_AddRef
,
228 provideclassinfo_Release
,
229 provideclassinfo_GetClassInfo
232 void init_classinfo(const GUID
*guid
, IUnknown
*outer
, struct provideclassinfo
*classinfo
)
234 classinfo
->IProvideClassInfo_iface
.lpVtbl
= &provideclassinfovtbl
;
235 classinfo
->outer
= outer
;
236 classinfo
->guid
= guid
;
239 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
241 TRACE("%p, %u, %p\n", hinst
, reason
, reserved
);
245 case DLL_PROCESS_ATTACH
:
246 DisableThreadLibraryCalls( hinst
);
247 scrrun_instance
= hinst
;
249 case DLL_PROCESS_DETACH
:
257 /***********************************************************************
258 * DllRegisterServer (scrrun.@)
260 HRESULT WINAPI
DllRegisterServer(void)
263 return __wine_register_resources(scrrun_instance
);
266 /***********************************************************************
267 * DllUnregisterServer (scrrun.@)
269 HRESULT WINAPI
DllUnregisterServer(void)
272 return __wine_unregister_resources(scrrun_instance
);
275 /***********************************************************************
276 * DllGetClassObject (scrrun.@)
279 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
* ppv
)
281 if(IsEqualGUID(&CLSID_FileSystemObject
, rclsid
)) {
282 TRACE("(CLSID_FileSystemObject %s %p)\n", debugstr_guid(riid
), ppv
);
283 return IClassFactory_QueryInterface(&FileSystemFactory
, riid
, ppv
);
285 else if(IsEqualGUID(&CLSID_Dictionary
, rclsid
)) {
286 TRACE("(CLSID_Dictionary %s %p)\n", debugstr_guid(riid
), ppv
);
287 return IClassFactory_QueryInterface(&DictionaryFactory
, riid
, ppv
);
290 FIXME("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
291 return CLASS_E_CLASSNOTAVAILABLE
;
294 /***********************************************************************
295 * DllCanUnloadNow (scrrun.@)
297 HRESULT WINAPI
DllCanUnloadNow(void)