secur32/tests: Use importlib for functions available since Windows XP.
[wine.git] / dlls / wshom.ocx / wshom_main.c
blobe2a30edea05deb1cd8199bb931b94198c33172d2
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 HINSTANCE wshom_instance;
31 static ITypeLib *typelib;
32 static ITypeInfo *typeinfos[LAST_tid];
34 static REFIID tid_ids[] = {
35 &IID_NULL,
36 &IID_IWshCollection,
37 &IID_IWshEnvironment,
38 &IID_IWshExec,
39 &IID_IWshShell3,
40 &IID_IWshShortcut
43 static HRESULT load_typelib(void)
45 HRESULT hres;
46 ITypeLib *tl;
48 hres = LoadRegTypeLib(&LIBID_IWshRuntimeLibrary, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
49 if(FAILED(hres)) {
50 ERR("LoadRegTypeLib failed: %08x\n", hres);
51 return hres;
54 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
55 ITypeLib_Release(tl);
56 return hres;
59 HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
61 HRESULT hres;
63 if (!typelib)
64 hres = load_typelib();
65 if (!typelib)
66 return hres;
68 if(!typeinfos[tid]) {
69 ITypeInfo *ti;
71 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
72 if(FAILED(hres)) {
73 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
74 return hres;
77 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
78 ITypeInfo_Release(ti);
81 *typeinfo = typeinfos[tid];
82 ITypeInfo_AddRef(*typeinfo);
83 return S_OK;
86 static
87 void release_typelib(void)
89 unsigned i;
91 if(!typelib)
92 return;
94 for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
95 if(typeinfos[i])
96 ITypeInfo_Release(typeinfos[i]);
98 ITypeLib_Release(typelib);
101 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
103 *ppv = NULL;
105 if(IsEqualGUID(&IID_IUnknown, riid)) {
106 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
107 *ppv = iface;
108 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
109 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
110 *ppv = iface;
113 if(*ppv) {
114 IUnknown_AddRef((IUnknown*)*ppv);
115 return S_OK;
118 WARN("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
119 return E_NOINTERFACE;
122 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
124 TRACE("(%p)\n", iface);
125 return 2;
128 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
130 TRACE("(%p)\n", iface);
131 return 1;
134 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
136 TRACE("(%p)->(%x)\n", iface, fLock);
137 return S_OK;
140 static const IClassFactoryVtbl WshShellFactoryVtbl = {
141 ClassFactory_QueryInterface,
142 ClassFactory_AddRef,
143 ClassFactory_Release,
144 WshShellFactory_CreateInstance,
145 ClassFactory_LockServer
148 static IClassFactory WshShellFactory = { &WshShellFactoryVtbl };
150 /******************************************************************
151 * DllMain (wshom.ocx.@)
153 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
155 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
157 switch(fdwReason)
159 case DLL_WINE_PREATTACH:
160 return FALSE; /* prefer native version */
161 case DLL_PROCESS_ATTACH:
162 wshom_instance = hInstDLL;
163 DisableThreadLibraryCalls(wshom_instance);
164 break;
165 case DLL_PROCESS_DETACH:
166 if (lpv) break;
167 release_typelib();
168 break;
171 return TRUE;
174 /***********************************************************************
175 * DllGetClassObject (wshom.ocx.@)
177 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
179 if(IsEqualGUID(&CLSID_WshShell, rclsid)) {
180 TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid), ppv);
181 return IClassFactory_QueryInterface(&WshShellFactory, riid, ppv);
184 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
185 return CLASS_E_CLASSNOTAVAILABLE;
188 /***********************************************************************
189 * DllCanUnloadNow (wshom.ocx.@)
191 HRESULT WINAPI DllCanUnloadNow(void)
193 return S_FALSE;
196 /***********************************************************************
197 * DllRegisterServer (wshom.ocx.@)
199 HRESULT WINAPI DllRegisterServer(void)
201 TRACE("()\n");
202 return __wine_register_resources(wshom_instance);
205 /***********************************************************************
206 * DllUnregisterServer (wshom.ocx.@)
208 HRESULT WINAPI DllUnregisterServer(void)
210 TRACE("()\n");
211 return __wine_unregister_resources(wshom_instance);