comctl32/tests: Remove win9x hacks.
[wine.git] / dlls / shdocvw / factory.c
blob32888132bfe59c055a261562a55405499b3c0696
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 static HRESULT get_ieframe_object(REFCLSID rclsid, REFIID riid, void **ppv)
133 HINSTANCE ieframe_instance;
135 static HRESULT (WINAPI *ieframe_DllGetClassObject)(REFCLSID,REFIID,void**);
137 if(!ieframe_DllGetClassObject) {
138 ieframe_instance = get_ieframe_instance();
139 if(!ieframe_instance)
140 return CLASS_E_CLASSNOTAVAILABLE;
142 ieframe_DllGetClassObject = (void*)GetProcAddress(ieframe_instance, "DllGetClassObject");
143 if(!ieframe_DllGetClassObject)
144 return CLASS_E_CLASSNOTAVAILABLE;
147 return ieframe_DllGetClassObject(rclsid, riid, ppv);
150 /*************************************************************************
151 * DllGetClassObject (SHDOCVW.@)
153 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
155 static IClassFactoryImpl WB1ClassFactory = {{&WBCF_Vtbl}, WebBrowserV1_Create};
156 static IClassFactoryImpl WB2ClassFactory = {{&WBCF_Vtbl}, WebBrowserV2_Create};
158 TRACE("\n");
160 if(IsEqualGUID(&CLSID_WebBrowser, rclsid))
161 return IClassFactory_QueryInterface(&WB2ClassFactory.IClassFactory_iface, riid, ppv);
163 if(IsEqualGUID(&CLSID_WebBrowser_V1, rclsid))
164 return IClassFactory_QueryInterface(&WB1ClassFactory.IClassFactory_iface, riid, ppv);
166 if(IsEqualGUID(&CLSID_InternetShortcut, rclsid)
167 || IsEqualGUID(&CLSID_CUrlHistory, rclsid)
168 || IsEqualGUID(&CLSID_TaskbarList, rclsid))
169 return get_ieframe_object(rclsid, riid, ppv);
171 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
172 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
175 HRESULT register_class_object(BOOL do_reg)
177 HRESULT hres;
179 static DWORD cookie;
180 static IClassFactoryImpl IEClassFactory = {{&WBCF_Vtbl}, InternetExplorer_Create};
182 if(do_reg) {
183 hres = CoRegisterClassObject(&CLSID_InternetExplorer,
184 (IUnknown*)&IEClassFactory.IClassFactory_iface, CLSCTX_SERVER,
185 REGCLS_MULTIPLEUSE|REGCLS_SUSPENDED, &cookie);
186 if (FAILED(hres)) {
187 ERR("failed to register object %08x\n", hres);
188 return hres;
191 hres = CoResumeClassObjects();
192 if(SUCCEEDED(hres))
193 return hres;
195 ERR("failed to resume object %08x\n", hres);
198 return CoRevokeClassObject(cookie);
201 static HRESULT reg_install(LPCSTR section, STRTABLEA *strtable)
203 HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
204 HMODULE hadvpack;
205 HRESULT hres;
207 static const WCHAR advpackW[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
209 hadvpack = LoadLibraryW(advpackW);
210 pRegInstall = (void *)GetProcAddress(hadvpack, "RegInstall");
212 hres = pRegInstall(shdocvw_hinstance, section, strtable);
214 FreeLibrary(hadvpack);
215 return hres;
218 #define INF_SET_CLSID(clsid) \
219 do \
221 static CHAR name[] = "CLSID_" #clsid; \
223 pse[i].pszName = name; \
224 clsids[i++] = &CLSID_ ## clsid; \
225 } while (0)
227 static HRESULT register_server(BOOL doregister)
229 STRTABLEA strtable;
230 STRENTRYA pse[3];
231 static CLSID const *clsids[3];
232 unsigned int i = 0;
233 HRESULT hres;
235 INF_SET_CLSID(Internet);
236 INF_SET_CLSID(InternetExplorer);
237 INF_SET_CLSID(InternetShortcut);
239 for(i = 0; i < sizeof(pse)/sizeof(pse[0]); i++) {
240 pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
241 sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
242 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
243 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
244 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
247 strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
248 strtable.pse = pse;
250 hres = reg_install(doregister ? "RegisterDll" : "UnregisterDll", &strtable);
252 for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
253 HeapFree(GetProcessHeap(), 0, pse[i].pszValue);
255 return hres;
258 #undef INF_SET_CLSID
260 /***********************************************************************
261 * DllRegisterServer (shdocvw.@)
263 HRESULT WINAPI DllRegisterServer(void)
265 HRESULT hres;
267 hres = __wine_register_resources( shdocvw_hinstance, NULL );
268 if(FAILED(hres))
269 return hres;
271 return register_server(TRUE);
274 /***********************************************************************
275 * DllUnregisterServer (shdocvw.@)
277 HRESULT WINAPI DllUnregisterServer(void)
279 HRESULT hres;
281 hres = register_server(FALSE);
282 if(FAILED(hres))
283 return hres;
285 return __wine_unregister_resources( shdocvw_hinstance, NULL );
288 static BOOL check_native_ie(void)
290 static const WCHAR cszPath[] = {'b','r','o','w','s','e','u','i','.','d','l','l',0};
291 DWORD handle,size;
292 BOOL ret = TRUE;
294 size = GetFileVersionInfoSizeW(cszPath,&handle);
295 if (size)
297 LPVOID buf;
298 LPWSTR lpFileDescription;
299 UINT dwBytes;
300 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};
301 static const WCHAR cszWine[] = {'W','i','n','e',0};
303 buf = HeapAlloc(GetProcessHeap(),0,size);
304 GetFileVersionInfoW(cszPath,0,size,buf);
306 if (VerQueryValueW(buf, cszFD, (LPVOID*)&lpFileDescription, &dwBytes) &&
307 strstrW(lpFileDescription,cszWine))
308 ret = FALSE;
310 HeapFree(GetProcessHeap(), 0, buf);
313 return ret;
316 DWORD register_iexplore(BOOL doregister)
318 HRESULT hres;
319 if (check_native_ie())
321 TRACE("Native IE detected, not doing registration\n");
322 return S_OK;
324 hres = reg_install(doregister ? "RegisterIE" : "UnregisterIE", NULL);
325 return FAILED(hres);