dinput: Ignore EV_MSC events instead of printing fixme.
[wine/multimedia.git] / dlls / shdocvw / factory.c
blob71d1e7e419d9ea663c6237487c69df14093591d6
1 /*
2 * Implementation of class factory for IE Web Browser
4 * Copyright 2001 John R. Sheets (for CodeWeavers)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <string.h>
22 #include <stdio.h>
24 #include "shdocvw.h"
25 #include "winreg.h"
26 #include "advpub.h"
27 #include "rpcproxy.h"
28 #include "isguids.h"
30 #include "winver.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
36 /**********************************************************************
37 * Implement the WebBrowser class factory
40 typedef struct
42 /* IUnknown fields */
43 IClassFactory IClassFactory_iface;
44 HRESULT (*cf)(LPUNKNOWN, REFIID, LPVOID *);
45 LONG ref;
46 } IClassFactoryImpl;
48 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
50 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
54 /**********************************************************************
55 * WBCF_QueryInterface (IUnknown)
57 static HRESULT WINAPI WBCF_QueryInterface(LPCLASSFACTORY iface,
58 REFIID riid, LPVOID *ppobj)
60 TRACE("(%s %p)\n", debugstr_guid(riid), ppobj);
62 if (!ppobj)
63 return E_POINTER;
65 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
66 *ppobj = iface;
67 IClassFactory_AddRef(iface);
68 return S_OK;
71 WARN("Not supported interface %s\n", debugstr_guid(riid));
73 *ppobj = NULL;
74 return E_NOINTERFACE;
77 /************************************************************************
78 * WBCF_AddRef (IUnknown)
80 static ULONG WINAPI WBCF_AddRef(LPCLASSFACTORY iface)
82 SHDOCVW_LockModule();
84 return 2; /* non-heap based object */
87 /************************************************************************
88 * WBCF_Release (IUnknown)
90 static ULONG WINAPI WBCF_Release(LPCLASSFACTORY iface)
92 SHDOCVW_UnlockModule();
94 return 1; /* non-heap based object */
97 /************************************************************************
98 * WBCF_CreateInstance (IClassFactory)
100 static HRESULT WINAPI WBCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
101 REFIID riid, LPVOID *ppobj)
103 IClassFactoryImpl *This = (IClassFactoryImpl *) iface;
104 return This->cf(pOuter, riid, ppobj);
107 /************************************************************************
108 * WBCF_LockServer (IClassFactory)
110 static HRESULT WINAPI WBCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
112 TRACE("(%d)\n", dolock);
114 if (dolock)
115 SHDOCVW_LockModule();
116 else
117 SHDOCVW_UnlockModule();
119 return S_OK;
122 static const IClassFactoryVtbl WBCF_Vtbl =
124 WBCF_QueryInterface,
125 WBCF_AddRef,
126 WBCF_Release,
127 WBCF_CreateInstance,
128 WBCF_LockServer
131 /*************************************************************************
132 * DllGetClassObject (SHDOCVW.@)
134 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
136 static IClassFactoryImpl WB1ClassFactory = {{&WBCF_Vtbl}, WebBrowserV1_Create};
137 static IClassFactoryImpl WB2ClassFactory = {{&WBCF_Vtbl}, WebBrowserV2_Create};
138 static IClassFactoryImpl CUHClassFactory = {{&WBCF_Vtbl}, CUrlHistory_Create};
139 static IClassFactoryImpl ISCClassFactory = {{&WBCF_Vtbl}, InternetShortcut_Create};
140 static IClassFactoryImpl TBLClassFactory = {{&WBCF_Vtbl}, TaskbarList_Create};
142 TRACE("\n");
144 if(IsEqualGUID(&CLSID_WebBrowser, rclsid))
145 return IClassFactory_QueryInterface(&WB2ClassFactory.IClassFactory_iface, riid, ppv);
147 if(IsEqualGUID(&CLSID_WebBrowser_V1, rclsid))
148 return IClassFactory_QueryInterface(&WB1ClassFactory.IClassFactory_iface, riid, ppv);
150 if(IsEqualGUID(&CLSID_CUrlHistory, rclsid))
151 return IClassFactory_QueryInterface(&CUHClassFactory.IClassFactory_iface, riid, ppv);
153 if(IsEqualGUID(&CLSID_InternetShortcut, rclsid))
154 return IClassFactory_QueryInterface(&ISCClassFactory.IClassFactory_iface, riid, ppv);
156 if(IsEqualGUID(&CLSID_TaskbarList, rclsid))
157 return IClassFactory_QueryInterface(&TBLClassFactory.IClassFactory_iface, riid, ppv);
159 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
160 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
163 HRESULT register_class_object(BOOL do_reg)
165 HRESULT hres;
167 static DWORD cookie;
168 static IClassFactoryImpl IEClassFactory = {{&WBCF_Vtbl}, InternetExplorer_Create};
170 if(do_reg) {
171 hres = CoRegisterClassObject(&CLSID_InternetExplorer,
172 (IUnknown*)&IEClassFactory.IClassFactory_iface, CLSCTX_SERVER,
173 REGCLS_MULTIPLEUSE|REGCLS_SUSPENDED, &cookie);
174 if (FAILED(hres)) {
175 ERR("failed to register object %08x\n", hres);
176 return hres;
179 hres = CoResumeClassObjects();
180 if(SUCCEEDED(hres))
181 return hres;
183 ERR("failed to resume object %08x\n", hres);
186 return CoRevokeClassObject(cookie);
189 static HRESULT reg_install(LPCSTR section, STRTABLEA *strtable)
191 HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
192 HMODULE hadvpack;
193 HRESULT hres;
195 static const WCHAR advpackW[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
197 hadvpack = LoadLibraryW(advpackW);
198 pRegInstall = (void *)GetProcAddress(hadvpack, "RegInstall");
200 hres = pRegInstall(shdocvw_hinstance, section, strtable);
202 FreeLibrary(hadvpack);
203 return hres;
206 #define INF_SET_CLSID(clsid) \
207 do \
209 static CHAR name[] = "CLSID_" #clsid; \
211 pse[i].pszName = name; \
212 clsids[i++] = &CLSID_ ## clsid; \
213 } while (0)
215 static HRESULT register_server(BOOL doregister)
217 STRTABLEA strtable;
218 STRENTRYA pse[3];
219 static CLSID const *clsids[3];
220 unsigned int i = 0;
221 HRESULT hres;
223 INF_SET_CLSID(Internet);
224 INF_SET_CLSID(InternetExplorer);
225 INF_SET_CLSID(InternetShortcut);
227 for(i = 0; i < sizeof(pse)/sizeof(pse[0]); i++) {
228 pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
229 sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
230 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
231 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
232 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
235 strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
236 strtable.pse = pse;
238 hres = reg_install(doregister ? "RegisterDll" : "UnregisterDll", &strtable);
240 for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
241 HeapFree(GetProcessHeap(), 0, pse[i].pszValue);
243 return hres;
246 #undef INF_SET_CLSID
248 /***********************************************************************
249 * DllRegisterServer (shdocvw.@)
251 HRESULT WINAPI DllRegisterServer(void)
253 HRESULT hres;
255 hres = __wine_register_resources( shdocvw_hinstance, NULL );
256 if(FAILED(hres))
257 return hres;
259 return register_server(TRUE);
262 /***********************************************************************
263 * DllUnregisterServer (shdocvw.@)
265 HRESULT WINAPI DllUnregisterServer(void)
267 HRESULT hres;
269 hres = register_server(FALSE);
270 if(FAILED(hres))
271 return hres;
273 return __wine_unregister_resources( shdocvw_hinstance, NULL );
276 static BOOL check_native_ie(void)
278 static const WCHAR cszPath[] = {'b','r','o','w','s','e','u','i','.','d','l','l',0};
279 DWORD handle,size;
280 BOOL ret = TRUE;
282 size = GetFileVersionInfoSizeW(cszPath,&handle);
283 if (size)
285 LPVOID buf;
286 LPWSTR lpFileDescription;
287 UINT dwBytes;
288 static const WCHAR cszFD[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\','0','4','0','9','0','4','e','4','\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0};
289 static const WCHAR cszWine[] = {'W','i','n','e',0};
291 buf = HeapAlloc(GetProcessHeap(),0,size);
292 GetFileVersionInfoW(cszPath,0,size,buf);
294 if (VerQueryValueW(buf, cszFD, (LPVOID*)&lpFileDescription, &dwBytes) &&
295 strstrW(lpFileDescription,cszWine))
296 ret = FALSE;
298 HeapFree(GetProcessHeap(), 0, buf);
301 return ret;
304 DWORD register_iexplore(BOOL doregister)
306 HRESULT hres;
307 if (check_native_ie())
309 TRACE("Native IE detected, not doing registration\n");
310 return S_OK;
312 hres = reg_install(doregister ? "RegisterIE" : "UnregisterIE", NULL);
313 return FAILED(hres);