msvcp90: Rename num_get_char_ctor__Init function because it's not a constructor.
[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 static
84 void release_typelib(void)
85 {
86     unsigned i;
87
88     if(!typelib)
89         return;
90
91     for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
92         if(typeinfos[i])
93             ITypeInfo_Release(typeinfos[i]);
94
95     ITypeLib_Release(typelib);
96 }
97
98 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
99 {
100     *ppv = NULL;
101
102     if(IsEqualGUID(&IID_IUnknown, riid)) {
103         TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
104         *ppv = iface;
105     }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
106         TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
107         *ppv = iface;
108     }
109
110     if(*ppv) {
111         IUnknown_AddRef((IUnknown*)*ppv);
112         return S_OK;
113     }
114
115     FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
116     return E_NOINTERFACE;
117 }
118
119 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
120 {
121     TRACE("(%p)\n", iface);
122     return 2;
123 }
124
125 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
126 {
127     TRACE("(%p)\n", iface);
128     return 1;
129 }
130
131 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
132 {
133     TRACE("(%p)->(%x)\n", iface, fLock);
134     return S_OK;
135 }
136
137 static const IClassFactoryVtbl WshShellFactoryVtbl = {
138     ClassFactory_QueryInterface,
139     ClassFactory_AddRef,
140     ClassFactory_Release,
141     WshShellFactory_CreateInstance,
142     ClassFactory_LockServer
143 };
144
145 static IClassFactory WshShellFactory = { &WshShellFactoryVtbl };
146
147 /******************************************************************
148  *              DllMain (wshom.ocx.@)
149  */
150 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
151 {
152     TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
153
154     switch(fdwReason)
155     {
156     case DLL_WINE_PREATTACH:
157         return FALSE;  /* prefer native version */
158     case DLL_PROCESS_ATTACH:
159         wshom_instance = hInstDLL;
160         DisableThreadLibraryCalls(wshom_instance);
161         break;
162     case DLL_PROCESS_DETACH:
163         release_typelib();
164         break;
165     }
166
167     return TRUE;
168 }
169
170 /***********************************************************************
171  *              DllGetClassObject       (wshom.ocx.@)
172  */
173 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
174 {
175     if(IsEqualGUID(&CLSID_WshShell, rclsid)) {
176         TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid), ppv);
177         return IClassFactory_QueryInterface(&WshShellFactory, riid, ppv);
178     }
179
180     FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
181     return CLASS_E_CLASSNOTAVAILABLE;
182 }
183
184 /***********************************************************************
185  *          DllCanUnloadNow (wshom.ocx.@)
186  */
187 HRESULT WINAPI DllCanUnloadNow(void)
188 {
189     return S_FALSE;
190 }
191
192 /***********************************************************************
193  *          DllRegisterServer (wshom.ocx.@)
194  */
195 HRESULT WINAPI DllRegisterServer(void)
196 {
197     TRACE("()\n");
198     return __wine_register_resources(wshom_instance);
199 }
200
201 /***********************************************************************
202  *          DllUnregisterServer (wshom.ocx.@)
203  */
204 HRESULT WINAPI DllUnregisterServer(void)
205 {
206     TRACE("()\n");
207     return __wine_unregister_resources(wshom_instance);
208 }