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 typedef HRESULT (*fnCreateInstance
)(LPVOID
*ppObj
);
40 static HRESULT WINAPI
scrruncf_QueryInterface(IClassFactory
*iface
, REFIID riid
, LPVOID
*ppv
)
44 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
45 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
47 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
48 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
53 IUnknown_AddRef((IUnknown
*)*ppv
);
57 WARN("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
61 static ULONG WINAPI
scrruncf_AddRef(IClassFactory
*iface
)
63 TRACE("(%p)\n", iface
);
67 static ULONG WINAPI
scrruncf_Release(IClassFactory
*iface
)
69 TRACE("(%p)\n", iface
);
73 static HRESULT WINAPI
scrruncf_LockServer(IClassFactory
*iface
, BOOL fLock
)
75 TRACE("(%p)->(%x)\n", iface
, fLock
);
79 static const struct IClassFactoryVtbl scrruncf_vtbl
=
81 scrruncf_QueryInterface
,
84 FileSystem_CreateInstance
,
88 static const struct IClassFactoryVtbl dictcf_vtbl
=
90 scrruncf_QueryInterface
,
93 Dictionary_CreateInstance
,
97 static IClassFactory FileSystemFactory
= { &scrruncf_vtbl
};
98 static IClassFactory DictionaryFactory
= { &dictcf_vtbl
};
100 static ITypeLib
*typelib
;
101 static ITypeInfo
*typeinfos
[LAST_tid
];
103 static REFIID tid_ids
[] = {
108 &IID_IFolderCollection
,
114 static HRESULT
load_typelib(void)
119 hres
= LoadRegTypeLib(&LIBID_Scripting
, 1, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
121 ERR("LoadRegTypeLib failed: %08x\n", hres
);
125 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
126 ITypeLib_Release(tl
);
130 HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
135 hres
= load_typelib();
139 if(!typeinfos
[tid
]) {
142 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
144 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
148 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
149 ITypeInfo_Release(ti
);
152 *typeinfo
= typeinfos
[tid
];
156 static void release_typelib(void)
163 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
165 ITypeInfo_Release(typeinfos
[i
]);
167 ITypeLib_Release(typelib
);
170 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
172 TRACE("%p, %u, %p\n", hinst
, reason
, reserved
);
176 case DLL_WINE_PREATTACH
:
177 return FALSE
; /* prefer native version */
178 case DLL_PROCESS_ATTACH
:
179 DisableThreadLibraryCalls( hinst
);
180 scrrun_instance
= hinst
;
182 case DLL_PROCESS_DETACH
:
190 /***********************************************************************
191 * DllRegisterServer (scrrun.@)
193 HRESULT WINAPI
DllRegisterServer(void)
196 return __wine_register_resources(scrrun_instance
);
199 /***********************************************************************
200 * DllUnregisterServer (scrrun.@)
202 HRESULT WINAPI
DllUnregisterServer(void)
205 return __wine_unregister_resources(scrrun_instance
);
208 /***********************************************************************
209 * DllGetClassObject (scrrun.@)
212 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
* ppv
)
214 if(IsEqualGUID(&CLSID_FileSystemObject
, rclsid
)) {
215 TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid
), ppv
);
216 return IClassFactory_QueryInterface(&FileSystemFactory
, riid
, ppv
);
218 else if(IsEqualGUID(&CLSID_Dictionary
, rclsid
)) {
219 TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid
), ppv
);
220 return IClassFactory_QueryInterface(&DictionaryFactory
, riid
, ppv
);
223 FIXME("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
224 return CLASS_E_CLASSNOTAVAILABLE
;
227 /***********************************************************************
228 * DllCanUnloadNow (scrrun.@)
230 HRESULT WINAPI
DllCanUnloadNow(void)