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
19 #include "scrrun_private.h"
23 static HINSTANCE scrrun_instance
;
25 typedef HRESULT (*fnCreateInstance
)(LPVOID
*ppObj
);
27 static HRESULT WINAPI
scrruncf_QueryInterface(IClassFactory
*iface
, REFIID riid
, LPVOID
*ppv
)
31 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
32 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
34 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
35 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
40 IUnknown_AddRef((IUnknown
*)*ppv
);
44 WARN("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
48 static ULONG WINAPI
scrruncf_AddRef(IClassFactory
*iface
)
50 TRACE("(%p)\n", iface
);
54 static ULONG WINAPI
scrruncf_Release(IClassFactory
*iface
)
56 TRACE("(%p)\n", iface
);
60 static HRESULT WINAPI
scrruncf_LockServer(IClassFactory
*iface
, BOOL fLock
)
62 TRACE("(%p)->(%x)\n", iface
, fLock
);
66 static const struct IClassFactoryVtbl scrruncf_vtbl
=
68 scrruncf_QueryInterface
,
71 FileSystem_CreateInstance
,
75 static const struct IClassFactoryVtbl dictcf_vtbl
=
77 scrruncf_QueryInterface
,
80 Dictionary_CreateInstance
,
84 static IClassFactory FileSystemFactory
= { &scrruncf_vtbl
};
85 static IClassFactory DictionaryFactory
= { &dictcf_vtbl
};
87 static ITypeLib
*typelib
;
88 static ITypeInfo
*typeinfos
[LAST_tid
];
90 static REFIID tid_ids
[] = {
94 &IID_IDriveCollection
,
99 &IID_IFolderCollection
,
103 static HRESULT
load_typelib(void)
108 hres
= LoadRegTypeLib(&LIBID_Scripting
, 1, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
110 ERR("LoadRegTypeLib failed: %08x\n", hres
);
114 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
115 ITypeLib_Release(tl
);
119 HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
124 hres
= load_typelib();
128 if(!typeinfos
[tid
]) {
131 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
133 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
137 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
138 ITypeInfo_Release(ti
);
141 *typeinfo
= typeinfos
[tid
];
145 static void release_typelib(void)
152 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
154 ITypeInfo_Release(typeinfos
[i
]);
156 ITypeLib_Release(typelib
);
159 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
161 TRACE("%p, %u, %p\n", hinst
, reason
, reserved
);
165 case DLL_WINE_PREATTACH
:
166 return FALSE
; /* prefer native version */
167 case DLL_PROCESS_ATTACH
:
168 DisableThreadLibraryCalls( hinst
);
169 scrrun_instance
= hinst
;
171 case DLL_PROCESS_DETACH
:
179 /***********************************************************************
180 * DllRegisterServer (scrrun.@)
182 HRESULT WINAPI
DllRegisterServer(void)
185 return __wine_register_resources(scrrun_instance
);
188 /***********************************************************************
189 * DllUnregisterServer (scrrun.@)
191 HRESULT WINAPI
DllUnregisterServer(void)
194 return __wine_unregister_resources(scrrun_instance
);
197 /***********************************************************************
198 * DllGetClassObject (scrrun.@)
201 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
* ppv
)
203 if(IsEqualGUID(&CLSID_FileSystemObject
, rclsid
)) {
204 TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid
), ppv
);
205 return IClassFactory_QueryInterface(&FileSystemFactory
, riid
, ppv
);
207 else if(IsEqualGUID(&CLSID_Dictionary
, rclsid
)) {
208 TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid
), ppv
);
209 return IClassFactory_QueryInterface(&DictionaryFactory
, riid
, ppv
);
212 FIXME("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
213 return CLASS_E_CLASSNOTAVAILABLE
;
216 /***********************************************************************
217 * DllCanUnloadNow (scrrun.@)
219 HRESULT WINAPI
DllCanUnloadNow(void)