wshom.ocx: Added IWshShortcut stub.
[wine] / dlls / wshom.ocx / wshom_main.c
1 /*
2  * Copyright 2011 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "wshom_private.h"
20
21 #include "initguid.h"
22 #include "wshom.h"
23 #include "rpcproxy.h"
24
25 #include "wine/debug.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(wshom);
28
29 static HINSTANCE wshom_instance;
30
31 static ITypeLib *typelib;
32 static ITypeInfo *typeinfos[LAST_tid];
33
34 static REFIID tid_ids[] = {
35     &IID_NULL,
36     &IID_IWshShell3,
37     &IID_IWshCollection,
38     &IID_IWshShortcut
39 };
40
41 static HRESULT load_typelib(void)
42 {
43     HRESULT hres;
44     ITypeLib *tl;
45
46     hres = LoadRegTypeLib(&LIBID_IWshRuntimeLibrary, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
47     if(FAILED(hres)) {
48         ERR("LoadRegTypeLib failed: %08x\n", hres);
49         return hres;
50     }
51
52     if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
53         ITypeLib_Release(tl);
54     return hres;
55 }
56
57 HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
58 {
59     HRESULT hres;
60
61     if (!typelib)
62         hres = load_typelib();
63     if (!typelib)
64         return hres;
65
66     if(!typeinfos[tid]) {
67         ITypeInfo *ti;
68
69         hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
70         if(FAILED(hres)) {
71             ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
72             return hres;
73         }
74
75         if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
76             ITypeInfo_Release(ti);
77     }
78
79     *typeinfo = typeinfos[tid];
80     return S_OK;
81 }
82
83 void release_typelib(void)
84 {
85     unsigned i;
86
87     if(!typelib)
88         return;
89
90     for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
91         if(typeinfos[i])
92             ITypeInfo_Release(typeinfos[i]);
93
94     ITypeLib_Release(typelib);
95 }
96
97 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
98 {
99     *ppv = NULL;
100
101     if(IsEqualGUID(&IID_IUnknown, riid)) {
102         TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
103         *ppv = iface;
104     }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
105         TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
106         *ppv = iface;
107     }
108
109     if(*ppv) {
110         IUnknown_AddRef((IUnknown*)*ppv);
111         return S_OK;
112     }
113
114     FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
115     return E_NOINTERFACE;
116 }
117
118 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
119 {
120     TRACE("(%p)\n", iface);
121     return 2;
122 }
123
124 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
125 {
126     TRACE("(%p)\n", iface);
127     return 1;
128 }
129
130 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
131 {
132     TRACE("(%p)->(%x)\n", iface, fLock);
133     return S_OK;
134 }
135
136 static const IClassFactoryVtbl WshShellFactoryVtbl = {
137     ClassFactory_QueryInterface,
138     ClassFactory_AddRef,
139     ClassFactory_Release,
140     WshShellFactory_CreateInstance,
141     ClassFactory_LockServer
142 };
143
144 static IClassFactory WshShellFactory = { &WshShellFactoryVtbl };
145
146 /******************************************************************
147  *              DllMain (wshom.ocx.@)
148  */
149 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
150 {
151     TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
152
153     switch(fdwReason)
154     {
155     case DLL_WINE_PREATTACH:
156         return FALSE;  /* prefer native version */
157     case DLL_PROCESS_ATTACH:
158         wshom_instance = hInstDLL;
159         DisableThreadLibraryCalls(wshom_instance);
160         break;
161     case DLL_PROCESS_DETACH:
162         release_typelib();
163         break;
164     }
165
166     return TRUE;
167 }
168
169 /***********************************************************************
170  *              DllGetClassObject       (wshom.ocx.@)
171  */
172 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
173 {
174     if(IsEqualGUID(&CLSID_WshShell, rclsid)) {
175         TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid), ppv);
176         return IClassFactory_QueryInterface(&WshShellFactory, riid, ppv);
177     }
178
179     FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
180     return CLASS_E_CLASSNOTAVAILABLE;
181 }
182
183 /***********************************************************************
184  *          DllCanUnloadNow (wshom.ocx.@)
185  */
186 HRESULT WINAPI DllCanUnloadNow(void)
187 {
188     return S_FALSE;
189 }
190
191 /***********************************************************************
192  *          DllRegisterServer (wshom.ocx.@)
193  */
194 HRESULT WINAPI DllRegisterServer(void)
195 {
196     TRACE("()\n");
197     return __wine_register_resources(wshom_instance);
198 }
199
200 /***********************************************************************
201  *          DllUnregisterServer (wshom.ocx.@)
202  */
203 HRESULT WINAPI DllUnregisterServer(void)
204 {
205     TRACE("()\n");
206     return __wine_unregister_resources(wshom_instance);
207 }