scrrun: Add typelib support.
[wine/multimedia.git] / dlls / scrrun / scrrun.c
blobd5ea3696616108605b183499ed6f48d1bef1674b
1 /*
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
18 #define COBJMACROS
20 #include "config.h"
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "ole2.h"
26 #include "rpcproxy.h"
28 #include <initguid.h>
29 #include "scrrun.h"
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 )
42 *ppv = NULL;
44 if(IsEqualGUID(&IID_IUnknown, riid)) {
45 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
46 *ppv = iface;
47 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
48 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
49 *ppv = iface;
52 if(*ppv) {
53 IUnknown_AddRef((IUnknown*)*ppv);
54 return S_OK;
57 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
58 return E_NOINTERFACE;
61 static ULONG WINAPI scrruncf_AddRef(IClassFactory *iface )
63 TRACE("(%p)\n", iface);
64 return 2;
67 static ULONG WINAPI scrruncf_Release(IClassFactory *iface )
69 TRACE("(%p)\n", iface);
70 return 1;
73 static HRESULT WINAPI scrruncf_LockServer(IClassFactory *iface, BOOL fLock)
75 TRACE("(%p)->(%x)\n", iface, fLock);
76 return S_OK;
79 static const struct IClassFactoryVtbl scrruncf_vtbl =
81 scrruncf_QueryInterface,
82 scrruncf_AddRef,
83 scrruncf_Release,
84 FileSystem_CreateInstance,
85 scrruncf_LockServer
88 static IClassFactory FileSystemFactory = { &scrruncf_vtbl };
90 static ITypeLib *typelib;
91 static ITypeInfo *typeinfos[LAST_tid];
93 static REFIID tid_ids[] = {
94 &IID_NULL,
95 &IID_IFileSystem3,
98 static HRESULT load_typelib(void)
100 HRESULT hres;
101 ITypeLib *tl;
103 hres = LoadRegTypeLib(&LIBID_Scripting, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
104 if(FAILED(hres)) {
105 ERR("LoadRegTypeLib failed: %08x\n", hres);
106 return hres;
109 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
110 ITypeLib_Release(tl);
111 return hres;
114 HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
116 HRESULT hres;
118 if (!typelib)
119 hres = load_typelib();
120 if (!typelib)
121 return hres;
123 if(!typeinfos[tid]) {
124 ITypeInfo *ti;
126 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
127 if(FAILED(hres)) {
128 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
129 return hres;
132 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
133 ITypeInfo_Release(ti);
136 *typeinfo = typeinfos[tid];
137 return S_OK;
140 static void release_typelib(void)
142 unsigned i;
144 if(!typelib)
145 return;
147 for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
148 if(typeinfos[i])
149 ITypeInfo_Release(typeinfos[i]);
151 ITypeLib_Release(typelib);
154 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
156 TRACE("%p, %u, %p\n", hinst, reason, reserved);
158 switch (reason)
160 case DLL_WINE_PREATTACH:
161 return FALSE; /* prefer native version */
162 case DLL_PROCESS_ATTACH:
163 DisableThreadLibraryCalls( hinst );
164 scrrun_instance = hinst;
165 break;
166 case DLL_PROCESS_DETACH:
167 release_typelib();
168 break;
170 return TRUE;
173 /***********************************************************************
174 * DllRegisterServer (scrrun.@)
176 HRESULT WINAPI DllRegisterServer(void)
178 TRACE("()\n");
179 return __wine_register_resources(scrrun_instance);
182 /***********************************************************************
183 * DllUnregisterServer (scrrun.@)
185 HRESULT WINAPI DllUnregisterServer(void)
187 TRACE("()\n");
188 return __wine_unregister_resources(scrrun_instance);
191 /***********************************************************************
192 * DllGetClassObject (scrrun.@)
195 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
197 if(IsEqualGUID(&CLSID_FileSystemObject, rclsid)) {
198 TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid), ppv);
199 return IClassFactory_QueryInterface(&FileSystemFactory, riid, ppv);
202 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
203 return CLASS_E_CLASSNOTAVAILABLE;
206 /***********************************************************************
207 * DllCanUnloadNow (scrrun.@)
209 HRESULT WINAPI DllCanUnloadNow(void)
211 return S_FALSE;