netcfgx: Add INetCfgLock support.
[wine/multimedia.git] / dlls / ieframe / ieframe_main.c
blobffba1d7d7aaaadb8353f3d6e3e93b763731bc083
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 "ieframe.h"
21 #include "rpcproxy.h"
22 #include "shlguid.h"
23 #include "isguids.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
29 LONG module_ref = 0;
30 HINSTANCE ieframe_instance;
32 const char *debugstr_variant(const VARIANT *v)
34 if(!v)
35 return "(null)";
37 switch(V_VT(v)) {
38 case VT_EMPTY:
39 return "{VT_EMPTY}";
40 case VT_NULL:
41 return "{VT_NULL}";
42 case VT_I4:
43 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
44 case VT_R8:
45 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
46 case VT_BSTR:
47 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
48 case VT_DISPATCH:
49 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
50 case VT_BOOL:
51 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
52 default:
53 return wine_dbg_sprintf("{vt %d}", V_VT(v));
57 static ITypeLib *typelib;
58 static ITypeInfo *typeinfos[LAST_tid];
60 static REFIID tid_ids[] = {
61 #define XIID(iface) &IID_ ## iface,
62 #define XCLSID(class) &CLSID_ ## class,
63 TID_LIST
64 #undef XIID
65 #undef XCLSID
68 static HRESULT load_typelib(void)
70 HRESULT hres;
71 ITypeLib *tl;
73 hres = LoadRegTypeLib(&LIBID_SHDocVw, 1, 1, LOCALE_SYSTEM_DEFAULT, &tl);
74 if(FAILED(hres)) {
75 ERR("LoadRegTypeLib failed: %08x\n", hres);
76 return hres;
79 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
80 ITypeLib_Release(tl);
81 return hres;
84 HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
86 HRESULT hres;
88 if(!typelib)
89 hres = load_typelib();
90 if(!typelib)
91 return hres;
93 if(!typeinfos[tid]) {
94 ITypeInfo *ti;
96 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
97 if(FAILED(hres)) {
98 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
99 return hres;
102 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
103 ITypeInfo_Release(ti);
106 *typeinfo = typeinfos[tid];
107 return S_OK;
110 static void release_typelib(void)
112 unsigned i;
114 if(!typelib)
115 return;
117 for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++) {
118 if(typeinfos[i])
119 ITypeInfo_Release(typeinfos[i]);
122 ITypeLib_Release(typelib);
125 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
127 *ppv = NULL;
129 if(IsEqualGUID(&IID_IUnknown, riid)) {
130 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
131 *ppv = iface;
132 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
133 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
134 *ppv = iface;
137 if(*ppv) {
138 IUnknown_AddRef((IUnknown*)*ppv);
139 return S_OK;
142 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
143 return E_NOINTERFACE;
146 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
148 TRACE("(%p)\n", iface);
149 return 2;
152 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
154 TRACE("(%p)\n", iface);
155 return 1;
158 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
160 TRACE("(%p)->(%x)\n", iface, fLock);
161 return S_OK;
164 static const IClassFactoryVtbl WebBrowserFactoryVtbl = {
165 ClassFactory_QueryInterface,
166 ClassFactory_AddRef,
167 ClassFactory_Release,
168 WebBrowser_Create,
169 ClassFactory_LockServer
172 static IClassFactory WebBrowserFactory = { &WebBrowserFactoryVtbl };
174 static const IClassFactoryVtbl WebBrowserV1FactoryVtbl = {
175 ClassFactory_QueryInterface,
176 ClassFactory_AddRef,
177 ClassFactory_Release,
178 WebBrowserV1_Create,
179 ClassFactory_LockServer
182 static IClassFactory WebBrowserV1Factory = { &WebBrowserV1FactoryVtbl };
184 static const IClassFactoryVtbl InternetShortcutFactoryVtbl = {
185 ClassFactory_QueryInterface,
186 ClassFactory_AddRef,
187 ClassFactory_Release,
188 InternetShortcut_Create,
189 ClassFactory_LockServer
192 static IClassFactory InternetShortcutFactory = { &InternetShortcutFactoryVtbl };
194 static const IClassFactoryVtbl CUrlHistoryFactoryVtbl = {
195 ClassFactory_QueryInterface,
196 ClassFactory_AddRef,
197 ClassFactory_Release,
198 CUrlHistory_Create,
199 ClassFactory_LockServer
202 static IClassFactory CUrlHistoryFactory = { &CUrlHistoryFactoryVtbl };
204 /******************************************************************
205 * DllMain (ieframe.@)
207 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
209 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
211 switch(fdwReason)
213 case DLL_WINE_PREATTACH:
214 return FALSE; /* prefer native version */
215 case DLL_PROCESS_ATTACH:
216 ieframe_instance = hInstDLL;
217 register_iewindow_class();
218 DisableThreadLibraryCalls(ieframe_instance);
219 break;
220 case DLL_PROCESS_DETACH:
221 if (lpv) break;
222 unregister_iewindow_class();
223 release_typelib();
226 return TRUE;
229 /***********************************************************************
230 * DllGetClassObject (ieframe.@)
232 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
234 if(IsEqualGUID(&CLSID_WebBrowser, rclsid)) {
235 TRACE("(CLSID_WebBrowser %s %p)\n", debugstr_guid(riid), ppv);
236 return IClassFactory_QueryInterface(&WebBrowserFactory, riid, ppv);
239 if(IsEqualGUID(&CLSID_WebBrowser_V1, rclsid)) {
240 TRACE("(CLSID_WebBrowser_V1 %s %p)\n", debugstr_guid(riid), ppv);
241 return IClassFactory_QueryInterface(&WebBrowserV1Factory, riid, ppv);
244 if(IsEqualGUID(rclsid, &CLSID_InternetShortcut)) {
245 TRACE("(CLSID_InternetShortcut %s %p)\n", debugstr_guid(riid), ppv);
246 return IClassFactory_QueryInterface(&InternetShortcutFactory, riid, ppv);
249 if(IsEqualGUID(&CLSID_CUrlHistory, rclsid)) {
250 TRACE("(CLSID_CUrlHistory %s %p)\n", debugstr_guid(riid), ppv);
251 return IClassFactory_QueryInterface(&CUrlHistoryFactory, riid, ppv);
254 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
255 return CLASS_E_CLASSNOTAVAILABLE;
258 static const IClassFactoryVtbl InternetExplorerFactoryVtbl = {
259 ClassFactory_QueryInterface,
260 ClassFactory_AddRef,
261 ClassFactory_Release,
262 InternetExplorer_Create,
263 ClassFactory_LockServer
266 static IClassFactory InternetExplorerFactory = { &InternetExplorerFactoryVtbl };
268 HRESULT register_class_object(BOOL do_reg)
270 HRESULT hres;
272 static DWORD cookie;
274 if(do_reg) {
275 hres = CoRegisterClassObject(&CLSID_InternetExplorer,
276 (IUnknown*)&InternetExplorerFactory, CLSCTX_SERVER,
277 REGCLS_MULTIPLEUSE|REGCLS_SUSPENDED, &cookie);
278 if (FAILED(hres)) {
279 ERR("failed to register object %08x\n", hres);
280 return hres;
283 hres = CoResumeClassObjects();
284 if(SUCCEEDED(hres))
285 return hres;
287 ERR("failed to resume object %08x\n", hres);
290 return CoRevokeClassObject(cookie);
293 /***********************************************************************
294 * DllCanUnloadNow (ieframe.@)
296 HRESULT WINAPI DllCanUnloadNow(void)
298 TRACE("()\n");
299 return module_ref ? S_FALSE : S_OK;
302 /***********************************************************************
303 * DllRegisterServer (ieframe.@)
305 HRESULT WINAPI DllRegisterServer(void)
307 TRACE("()\n");
308 return __wine_register_resources(ieframe_instance);
311 /***********************************************************************
312 * DllUnregisterServer (ieframe.@)
314 HRESULT WINAPI DllUnregisterServer(void)
316 TRACE("()\n");
317 return __wine_unregister_resources(ieframe_instance);
320 /***********************************************************************
321 * IEGetWriteableHKCU (ieframe.@)
323 HRESULT WINAPI IEGetWriteableHKCU(HKEY *pkey)
325 FIXME("(%p) stub\n", pkey);
326 return E_NOTIMPL;