msvcrt/tests: Make qsort_comp() static.
[wine/multimedia.git] / dlls / wshom.ocx / wshom_main.c
blob8400f837a64fe296fc11f1b46f0951dc9e9b837b
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_IWshShell3,
39 &IID_IWshShortcut
42 static HRESULT load_typelib(void)
44 HRESULT hres;
45 ITypeLib *tl;
47 hres = LoadRegTypeLib(&LIBID_IWshRuntimeLibrary, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
48 if(FAILED(hres)) {
49 ERR("LoadRegTypeLib failed: %08x\n", hres);
50 return hres;
53 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
54 ITypeLib_Release(tl);
55 return hres;
58 HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
60 HRESULT hres;
62 if (!typelib)
63 hres = load_typelib();
64 if (!typelib)
65 return hres;
67 if(!typeinfos[tid]) {
68 ITypeInfo *ti;
70 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
71 if(FAILED(hres)) {
72 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
73 return hres;
76 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
77 ITypeInfo_Release(ti);
80 *typeinfo = typeinfos[tid];
81 ITypeInfo_AddRef(*typeinfo);
82 return S_OK;
85 static
86 void release_typelib(void)
88 unsigned i;
90 if(!typelib)
91 return;
93 for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
94 if(typeinfos[i])
95 ITypeInfo_Release(typeinfos[i]);
97 ITypeLib_Release(typelib);
100 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
102 *ppv = NULL;
104 if(IsEqualGUID(&IID_IUnknown, riid)) {
105 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
106 *ppv = iface;
107 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
108 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
109 *ppv = iface;
112 if(*ppv) {
113 IUnknown_AddRef((IUnknown*)*ppv);
114 return S_OK;
117 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
118 return E_NOINTERFACE;
121 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
123 TRACE("(%p)\n", iface);
124 return 2;
127 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
129 TRACE("(%p)\n", iface);
130 return 1;
133 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
135 TRACE("(%p)->(%x)\n", iface, fLock);
136 return S_OK;
139 static const IClassFactoryVtbl WshShellFactoryVtbl = {
140 ClassFactory_QueryInterface,
141 ClassFactory_AddRef,
142 ClassFactory_Release,
143 WshShellFactory_CreateInstance,
144 ClassFactory_LockServer
147 static IClassFactory WshShellFactory = { &WshShellFactoryVtbl };
149 /******************************************************************
150 * DllMain (wshom.ocx.@)
152 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
154 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
156 switch(fdwReason)
158 case DLL_WINE_PREATTACH:
159 return FALSE; /* prefer native version */
160 case DLL_PROCESS_ATTACH:
161 wshom_instance = hInstDLL;
162 DisableThreadLibraryCalls(wshom_instance);
163 break;
164 case DLL_PROCESS_DETACH:
165 if (lpv) break;
166 release_typelib();
167 break;
170 return TRUE;
173 /***********************************************************************
174 * DllGetClassObject (wshom.ocx.@)
176 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
178 if(IsEqualGUID(&CLSID_WshShell, rclsid)) {
179 TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid), ppv);
180 return IClassFactory_QueryInterface(&WshShellFactory, riid, ppv);
183 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
184 return CLASS_E_CLASSNOTAVAILABLE;
187 /***********************************************************************
188 * DllCanUnloadNow (wshom.ocx.@)
190 HRESULT WINAPI DllCanUnloadNow(void)
192 return S_FALSE;
195 /***********************************************************************
196 * DllRegisterServer (wshom.ocx.@)
198 HRESULT WINAPI DllRegisterServer(void)
200 TRACE("()\n");
201 return __wine_register_resources(wshom_instance);
204 /***********************************************************************
205 * DllUnregisterServer (wshom.ocx.@)
207 HRESULT WINAPI DllUnregisterServer(void)
209 TRACE("()\n");
210 return __wine_unregister_resources(wshom_instance);