d3d10/effect: Add a helper to read raw variable values.
[wine.git] / dlls / scrrun / scrrun.c
blob7f39d0e642acd310d57ba2e42741cee477126884
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 <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "ole2.h"
25 #include "olectl.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 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 )
45 *ppv = NULL;
47 if(IsEqualGUID(&IID_IUnknown, riid)) {
48 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
49 *ppv = iface;
50 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
51 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
52 *ppv = iface;
55 if(*ppv) {
56 IUnknown_AddRef((IUnknown*)*ppv);
57 return S_OK;
60 WARN("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
61 return E_NOINTERFACE;
64 static ULONG WINAPI scrruncf_AddRef(IClassFactory *iface )
66 TRACE("(%p)\n", iface);
67 return 2;
70 static ULONG WINAPI scrruncf_Release(IClassFactory *iface )
72 TRACE("(%p)\n", iface);
73 return 1;
76 static HRESULT WINAPI scrruncf_LockServer(IClassFactory *iface, BOOL fLock)
78 TRACE("(%p)->(%x)\n", iface, fLock);
79 return S_OK;
82 static const struct IClassFactoryVtbl scrruncf_vtbl =
84 scrruncf_QueryInterface,
85 scrruncf_AddRef,
86 scrruncf_Release,
87 FileSystem_CreateInstance,
88 scrruncf_LockServer
91 static const struct IClassFactoryVtbl dictcf_vtbl =
93 scrruncf_QueryInterface,
94 scrruncf_AddRef,
95 scrruncf_Release,
96 Dictionary_CreateInstance,
97 scrruncf_LockServer
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[] = {
107 &IID_NULL,
108 &IID_IDictionary,
109 &IID_IDrive,
110 &IID_IDriveCollection,
111 &IID_IFile,
112 &IID_IFileCollection,
113 &IID_IFileSystem3,
114 &IID_IFolder,
115 &IID_IFolderCollection,
116 &IID_ITextStream
119 static HRESULT load_typelib(void)
121 HRESULT hres;
122 ITypeLib *tl;
124 if(typelib)
125 return S_OK;
127 hres = LoadRegTypeLib(&LIBID_Scripting, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
128 if(FAILED(hres)) {
129 ERR("LoadRegTypeLib failed: %08x\n", hres);
130 return hres;
133 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
134 ITypeLib_Release(tl);
135 return hres;
138 static HRESULT get_typeinfo_of_guid(const GUID *guid, ITypeInfo **tinfo)
140 HRESULT hres;
142 if(FAILED(hres = load_typelib()))
143 return hres;
145 return ITypeLib_GetTypeInfoOfGuid(typelib, guid, tinfo);
148 HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
150 HRESULT hres;
152 if (FAILED(hres = load_typelib()))
153 return hres;
155 if(!typeinfos[tid]) {
156 ITypeInfo *ti;
158 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
159 if(FAILED(hres)) {
160 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
161 return hres;
164 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
165 ITypeInfo_Release(ti);
168 *typeinfo = typeinfos[tid];
169 ITypeInfo_AddRef(typeinfos[tid]);
170 return S_OK;
173 static void release_typelib(void)
175 unsigned i;
177 if(!typelib)
178 return;
180 for (i = 0; i < ARRAY_SIZE(typeinfos); i++)
181 if(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)) {
194 *obj = iface;
195 IProvideClassInfo_AddRef(iface);
196 return S_OK;
198 else
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);
241 switch (reason)
243 case DLL_PROCESS_ATTACH:
244 DisableThreadLibraryCalls( hinst );
245 break;
246 case DLL_PROCESS_DETACH:
247 if (reserved) break;
248 release_typelib();
249 break;
251 return TRUE;
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;