d3d10/effect: Use case-insensitive comparison in GetMemberTypeBySemantic().
[wine.git] / dlls / wshom.ocx / wshom_main.c
blob0439ceb072a8ff7254ebb54232abcb0e50019cda
1 /*
2 * Copyright 2011 Jacek Caban 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 "wshom_private.h"
21 #include "initguid.h"
22 #include "wshom.h"
23 #include "rpcproxy.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(wshom);
29 static inline struct provideclassinfo *impl_from_IProvideClassInfo(IProvideClassInfo *iface)
31 return CONTAINING_RECORD(iface, struct provideclassinfo, IProvideClassInfo_iface);
34 static ITypeLib *typelib;
35 static ITypeInfo *typeinfos[LAST_tid];
37 static REFIID tid_ids[] = {
38 &IID_NULL,
39 &IID_IWshCollection,
40 &IID_IWshEnvironment,
41 &IID_IWshExec,
42 &IID_IWshShell3,
43 &IID_IWshShortcut
46 static HRESULT load_typelib(void)
48 HRESULT hres;
49 ITypeLib *tl;
51 if(typelib)
52 return S_OK;
54 hres = LoadRegTypeLib(&LIBID_IWshRuntimeLibrary, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
55 if(FAILED(hres)) {
56 ERR("LoadRegTypeLib failed: %08x\n", hres);
57 return hres;
60 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
61 ITypeLib_Release(tl);
62 return hres;
65 static HRESULT get_typeinfo_of_guid(const GUID *guid, ITypeInfo **tinfo)
67 HRESULT hres;
69 if(FAILED(hres = load_typelib()))
70 return hres;
72 return ITypeLib_GetTypeInfoOfGuid(typelib, guid, tinfo);
75 HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
77 HRESULT hres;
79 if (FAILED(hres = load_typelib()))
80 return hres;
82 if(!typeinfos[tid]) {
83 ITypeInfo *ti;
85 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
86 if(FAILED(hres)) {
87 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
88 return hres;
91 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
92 ITypeInfo_Release(ti);
95 *typeinfo = typeinfos[tid];
96 ITypeInfo_AddRef(*typeinfo);
97 return S_OK;
100 static
101 void release_typelib(void)
103 unsigned i;
105 if(!typelib)
106 return;
108 for(i = 0; i < ARRAY_SIZE(typeinfos); i++)
109 if(typeinfos[i])
110 ITypeInfo_Release(typeinfos[i]);
112 ITypeLib_Release(typelib);
115 static HRESULT WINAPI provideclassinfo_QueryInterface(IProvideClassInfo *iface, REFIID riid, void **obj)
117 struct provideclassinfo *This = impl_from_IProvideClassInfo(iface);
119 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
121 if (IsEqualIID(riid, &IID_IProvideClassInfo)) {
122 *obj = iface;
123 IProvideClassInfo_AddRef(iface);
124 return S_OK;
126 else
127 return IUnknown_QueryInterface(This->outer, riid, obj);
130 static ULONG WINAPI provideclassinfo_AddRef(IProvideClassInfo *iface)
132 struct provideclassinfo *This = impl_from_IProvideClassInfo(iface);
133 return IUnknown_AddRef(This->outer);
136 static ULONG WINAPI provideclassinfo_Release(IProvideClassInfo *iface)
138 struct provideclassinfo *This = impl_from_IProvideClassInfo(iface);
139 return IUnknown_Release(This->outer);
142 static HRESULT WINAPI provideclassinfo_GetClassInfo(IProvideClassInfo *iface, ITypeInfo **ti)
144 struct provideclassinfo *This = impl_from_IProvideClassInfo(iface);
146 TRACE("(%p)->(%p)\n", This, ti);
148 return get_typeinfo_of_guid(This->guid, ti);
151 static const IProvideClassInfoVtbl provideclassinfovtbl = {
152 provideclassinfo_QueryInterface,
153 provideclassinfo_AddRef,
154 provideclassinfo_Release,
155 provideclassinfo_GetClassInfo
158 void init_classinfo(const GUID *guid, IUnknown *outer, struct provideclassinfo *classinfo)
160 classinfo->IProvideClassInfo_iface.lpVtbl = &provideclassinfovtbl;
161 classinfo->outer = outer;
162 classinfo->guid = guid;
165 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
167 *ppv = NULL;
169 if(IsEqualGUID(&IID_IUnknown, riid)) {
170 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
171 *ppv = iface;
172 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
173 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
174 *ppv = iface;
177 if(*ppv) {
178 IUnknown_AddRef((IUnknown*)*ppv);
179 return S_OK;
182 WARN("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
183 return E_NOINTERFACE;
186 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
188 TRACE("(%p)\n", iface);
189 return 2;
192 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
194 TRACE("(%p)\n", iface);
195 return 1;
198 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
200 TRACE("(%p)->(%x)\n", iface, fLock);
201 return S_OK;
204 static const IClassFactoryVtbl WshShellFactoryVtbl = {
205 ClassFactory_QueryInterface,
206 ClassFactory_AddRef,
207 ClassFactory_Release,
208 WshShellFactory_CreateInstance,
209 ClassFactory_LockServer
212 static IClassFactory WshShellFactory = { &WshShellFactoryVtbl };
214 /******************************************************************
215 * DllMain (wshom.ocx.@)
217 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
219 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
221 switch(fdwReason)
223 case DLL_PROCESS_ATTACH:
224 DisableThreadLibraryCalls(hInstDLL);
225 break;
226 case DLL_PROCESS_DETACH:
227 if (lpv) break;
228 release_typelib();
229 break;
232 return TRUE;
235 /***********************************************************************
236 * DllGetClassObject (wshom.ocx.@)
238 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
240 if(IsEqualGUID(&CLSID_WshShell, rclsid)) {
241 TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid), ppv);
242 return IClassFactory_QueryInterface(&WshShellFactory, riid, ppv);
245 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
246 return CLASS_E_CLASSNOTAVAILABLE;