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 inline struct provideclassinfo
*impl_from_IProvideClassInfo(IProvideClassInfo
*iface
)
38 return CONTAINING_RECORD(iface
, struct provideclassinfo
, IProvideClassInfo_iface
);
41 typedef HRESULT (*fnCreateInstance
)(LPVOID
*ppObj
);
43 static HRESULT WINAPI
scrruncf_QueryInterface(IClassFactory
*iface
, REFIID riid
, LPVOID
*ppv
)
47 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
48 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
50 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
51 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
56 IUnknown_AddRef((IUnknown
*)*ppv
);
60 WARN("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
64 static ULONG WINAPI
scrruncf_AddRef(IClassFactory
*iface
)
66 TRACE("(%p)\n", iface
);
70 static ULONG WINAPI
scrruncf_Release(IClassFactory
*iface
)
72 TRACE("(%p)\n", iface
);
76 static HRESULT WINAPI
scrruncf_LockServer(IClassFactory
*iface
, BOOL fLock
)
78 TRACE("(%p)->(%x)\n", iface
, fLock
);
82 static const struct IClassFactoryVtbl scrruncf_vtbl
=
84 scrruncf_QueryInterface
,
87 FileSystem_CreateInstance
,
91 static const struct IClassFactoryVtbl dictcf_vtbl
=
93 scrruncf_QueryInterface
,
96 Dictionary_CreateInstance
,
100 static IClassFactory FileSystemFactory
= { &scrruncf_vtbl
};
101 static IClassFactory DictionaryFactory
= { &dictcf_vtbl
};
103 static ITypeLib
*typelib
;
104 static ITypeInfo
*typeinfos
[LAST_tid
];
106 static REFIID tid_ids
[] = {
110 &IID_IDriveCollection
,
112 &IID_IFileCollection
,
115 &IID_IFolderCollection
,
119 static HRESULT
load_typelib(void)
127 hres
= LoadRegTypeLib(&LIBID_Scripting
, 1, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
129 ERR("LoadRegTypeLib failed: %08x\n", hres
);
133 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
134 ITypeLib_Release(tl
);
138 static HRESULT
get_typeinfo_of_guid(const GUID
*guid
, ITypeInfo
**tinfo
)
142 if(FAILED(hres
= load_typelib()))
145 return ITypeLib_GetTypeInfoOfGuid(typelib
, guid
, tinfo
);
148 HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
152 if (FAILED(hres
= load_typelib()))
155 if(!typeinfos
[tid
]) {
158 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
160 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
164 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
165 ITypeInfo_Release(ti
);
168 *typeinfo
= typeinfos
[tid
];
169 ITypeInfo_AddRef(typeinfos
[tid
]);
173 static void release_typelib(void)
180 for (i
= 0; i
< ARRAY_SIZE(typeinfos
); i
++)
182 ITypeInfo_Release(typeinfos
[i
]);
184 ITypeLib_Release(typelib
);
187 static HRESULT WINAPI
provideclassinfo_QueryInterface(IProvideClassInfo
*iface
, REFIID riid
, void **obj
)
189 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
191 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
193 if (IsEqualIID(riid
, &IID_IProvideClassInfo
)) {
195 IProvideClassInfo_AddRef(iface
);
199 return IUnknown_QueryInterface(This
->outer
, riid
, obj
);
202 static ULONG WINAPI
provideclassinfo_AddRef(IProvideClassInfo
*iface
)
204 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
205 return IUnknown_AddRef(This
->outer
);
208 static ULONG WINAPI
provideclassinfo_Release(IProvideClassInfo
*iface
)
210 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
211 return IUnknown_Release(This
->outer
);
214 static HRESULT WINAPI
provideclassinfo_GetClassInfo(IProvideClassInfo
*iface
, ITypeInfo
**ti
)
216 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
218 TRACE("(%p)->(%p)\n", This
, ti
);
220 return get_typeinfo_of_guid(This
->guid
, ti
);
223 static const IProvideClassInfoVtbl provideclassinfovtbl
= {
224 provideclassinfo_QueryInterface
,
225 provideclassinfo_AddRef
,
226 provideclassinfo_Release
,
227 provideclassinfo_GetClassInfo
230 void init_classinfo(const GUID
*guid
, IUnknown
*outer
, struct provideclassinfo
*classinfo
)
232 classinfo
->IProvideClassInfo_iface
.lpVtbl
= &provideclassinfovtbl
;
233 classinfo
->outer
= outer
;
234 classinfo
->guid
= guid
;
237 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
239 TRACE("%p, %u, %p\n", hinst
, reason
, reserved
);
243 case DLL_PROCESS_ATTACH
:
244 DisableThreadLibraryCalls( hinst
);
246 case DLL_PROCESS_DETACH
:
254 /***********************************************************************
255 * DllGetClassObject (scrrun.@)
258 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
* ppv
)
260 if(IsEqualGUID(&CLSID_FileSystemObject
, rclsid
)) {
261 TRACE("(CLSID_FileSystemObject %s %p)\n", debugstr_guid(riid
), ppv
);
262 return IClassFactory_QueryInterface(&FileSystemFactory
, riid
, ppv
);
264 else if(IsEqualGUID(&CLSID_Dictionary
, rclsid
)) {
265 TRACE("(CLSID_Dictionary %s %p)\n", debugstr_guid(riid
), ppv
);
266 return IClassFactory_QueryInterface(&DictionaryFactory
, riid
, ppv
);
269 FIXME("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
270 return CLASS_E_CLASSNOTAVAILABLE
;