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
31 #include "scrrun_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(scrrun
);
37 static HINSTANCE scrrun_instance
;
39 static inline struct provideclassinfo
*impl_from_IProvideClassInfo(IProvideClassInfo
*iface
)
41 return CONTAINING_RECORD(iface
, struct provideclassinfo
, IProvideClassInfo_iface
);
44 typedef HRESULT (*fnCreateInstance
)(LPVOID
*ppObj
);
46 static HRESULT WINAPI
scrruncf_QueryInterface(IClassFactory
*iface
, REFIID riid
, LPVOID
*ppv
)
50 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
51 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
53 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
54 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
59 IUnknown_AddRef((IUnknown
*)*ppv
);
63 WARN("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
67 static ULONG WINAPI
scrruncf_AddRef(IClassFactory
*iface
)
69 TRACE("(%p)\n", iface
);
73 static ULONG WINAPI
scrruncf_Release(IClassFactory
*iface
)
75 TRACE("(%p)\n", iface
);
79 static HRESULT WINAPI
scrruncf_LockServer(IClassFactory
*iface
, BOOL fLock
)
81 TRACE("(%p)->(%x)\n", iface
, fLock
);
85 static const struct IClassFactoryVtbl scrruncf_vtbl
=
87 scrruncf_QueryInterface
,
90 FileSystem_CreateInstance
,
94 static const struct IClassFactoryVtbl dictcf_vtbl
=
96 scrruncf_QueryInterface
,
99 Dictionary_CreateInstance
,
103 static IClassFactory FileSystemFactory
= { &scrruncf_vtbl
};
104 static IClassFactory DictionaryFactory
= { &dictcf_vtbl
};
106 static ITypeLib
*typelib
;
107 static ITypeInfo
*typeinfos
[LAST_tid
];
109 static REFIID tid_ids
[] = {
113 &IID_IDriveCollection
,
115 &IID_IFileCollection
,
118 &IID_IFolderCollection
,
122 static HRESULT
load_typelib(void)
130 hres
= LoadRegTypeLib(&LIBID_Scripting
, 1, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
132 ERR("LoadRegTypeLib failed: %08x\n", hres
);
136 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
137 ITypeLib_Release(tl
);
141 static HRESULT
get_typeinfo_of_guid(const GUID
*guid
, ITypeInfo
**tinfo
)
145 if(FAILED(hres
= load_typelib()))
148 return ITypeLib_GetTypeInfoOfGuid(typelib
, guid
, tinfo
);
151 HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
155 if (FAILED(hres
= load_typelib()))
158 if(!typeinfos
[tid
]) {
161 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
163 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
167 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
168 ITypeInfo_Release(ti
);
171 *typeinfo
= typeinfos
[tid
];
172 ITypeInfo_AddRef(typeinfos
[tid
]);
176 static void release_typelib(void)
183 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
185 ITypeInfo_Release(typeinfos
[i
]);
187 ITypeLib_Release(typelib
);
190 static HRESULT WINAPI
provideclassinfo_QueryInterface(IProvideClassInfo
*iface
, REFIID riid
, void **obj
)
192 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
194 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
196 if (IsEqualIID(riid
, &IID_IProvideClassInfo
)) {
198 IProvideClassInfo_AddRef(iface
);
202 return IUnknown_QueryInterface(This
->outer
, riid
, obj
);
205 static ULONG WINAPI
provideclassinfo_AddRef(IProvideClassInfo
*iface
)
207 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
208 return IUnknown_AddRef(This
->outer
);
211 static ULONG WINAPI
provideclassinfo_Release(IProvideClassInfo
*iface
)
213 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
214 return IUnknown_Release(This
->outer
);
217 static HRESULT WINAPI
provideclassinfo_GetClassInfo(IProvideClassInfo
*iface
, ITypeInfo
**ti
)
219 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
221 TRACE("(%p)->(%p)\n", This
, ti
);
223 return get_typeinfo_of_guid(This
->guid
, ti
);
226 static const IProvideClassInfoVtbl provideclassinfovtbl
= {
227 provideclassinfo_QueryInterface
,
228 provideclassinfo_AddRef
,
229 provideclassinfo_Release
,
230 provideclassinfo_GetClassInfo
233 void init_classinfo(const GUID
*guid
, IUnknown
*outer
, struct provideclassinfo
*classinfo
)
235 classinfo
->IProvideClassInfo_iface
.lpVtbl
= &provideclassinfovtbl
;
236 classinfo
->outer
= outer
;
237 classinfo
->guid
= guid
;
240 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
242 TRACE("%p, %u, %p\n", hinst
, reason
, reserved
);
246 case DLL_WINE_PREATTACH
:
247 return FALSE
; /* prefer native version */
248 case DLL_PROCESS_ATTACH
:
249 DisableThreadLibraryCalls( hinst
);
250 scrrun_instance
= hinst
;
252 case DLL_PROCESS_DETACH
:
260 /***********************************************************************
261 * DllRegisterServer (scrrun.@)
263 HRESULT WINAPI
DllRegisterServer(void)
266 return __wine_register_resources(scrrun_instance
);
269 /***********************************************************************
270 * DllUnregisterServer (scrrun.@)
272 HRESULT WINAPI
DllUnregisterServer(void)
275 return __wine_unregister_resources(scrrun_instance
);
278 /***********************************************************************
279 * DllGetClassObject (scrrun.@)
282 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
* ppv
)
284 if(IsEqualGUID(&CLSID_FileSystemObject
, rclsid
)) {
285 TRACE("(CLSID_FileSystemObject %s %p)\n", debugstr_guid(riid
), ppv
);
286 return IClassFactory_QueryInterface(&FileSystemFactory
, riid
, ppv
);
288 else if(IsEqualGUID(&CLSID_Dictionary
, rclsid
)) {
289 TRACE("(CLSID_Dictionary %s %p)\n", debugstr_guid(riid
), ppv
);
290 return IClassFactory_QueryInterface(&DictionaryFactory
, riid
, ppv
);
293 FIXME("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
294 return CLASS_E_CLASSNOTAVAILABLE
;
297 /***********************************************************************
298 * DllCanUnloadNow (scrrun.@)
300 HRESULT WINAPI
DllCanUnloadNow(void)