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"
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[] = {
41 static HRESULT load_typelib(void)
46 hres = LoadRegTypeLib(&LIBID_IWshRuntimeLibrary, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
48 ERR("LoadRegTypeLib failed: %08x\n", hres);
52 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
57 HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
62 hres = load_typelib();
69 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
71 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
75 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
76 ITypeInfo_Release(ti);
79 *typeinfo = typeinfos[tid];
83 void release_typelib(void)
90 for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
92 ITypeInfo_Release(typeinfos[i]);
94 ITypeLib_Release(typelib);
97 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
101 if(IsEqualGUID(&IID_IUnknown, riid)) {
102 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
104 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
105 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
110 IUnknown_AddRef((IUnknown*)*ppv);
114 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
115 return E_NOINTERFACE;
118 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
120 TRACE("(%p)\n", iface);
124 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
126 TRACE("(%p)\n", iface);
130 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
132 TRACE("(%p)->(%x)\n", iface, fLock);
136 static const IClassFactoryVtbl WshShellFactoryVtbl = {
137 ClassFactory_QueryInterface,
139 ClassFactory_Release,
140 WshShellFactory_CreateInstance,
141 ClassFactory_LockServer
144 static IClassFactory WshShellFactory = { &WshShellFactoryVtbl };
146 /******************************************************************
147 * DllMain (wshom.ocx.@)
149 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
151 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
155 case DLL_WINE_PREATTACH:
156 return FALSE; /* prefer native version */
157 case DLL_PROCESS_ATTACH:
158 wshom_instance = hInstDLL;
159 DisableThreadLibraryCalls(wshom_instance);
161 case DLL_PROCESS_DETACH:
169 /***********************************************************************
170 * DllGetClassObject (wshom.ocx.@)
172 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
174 if(IsEqualGUID(&CLSID_WshShell, rclsid)) {
175 TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid), ppv);
176 return IClassFactory_QueryInterface(&WshShellFactory, riid, ppv);
179 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
180 return CLASS_E_CLASSNOTAVAILABLE;
183 /***********************************************************************
184 * DllCanUnloadNow (wshom.ocx.@)
186 HRESULT WINAPI DllCanUnloadNow(void)
191 /***********************************************************************
192 * DllRegisterServer (wshom.ocx.@)
194 HRESULT WINAPI DllRegisterServer(void)
197 return __wine_register_resources(wshom_instance);
200 /***********************************************************************
201 * DllUnregisterServer (wshom.ocx.@)
203 HRESULT WINAPI DllUnregisterServer(void)
206 return __wine_unregister_resources(wshom_instance);