user32: Make GetRegisteredRawInputDevices hotpatchable.
[wine/multimedia.git] / dlls / shdocvw / shdocvw_main.c
blob3ce5df1f1b457cac337a72770a4dbc3b5dd68a90
1 /*
2 * SHDOCVW - Internet Explorer Web Control
4 * Copyright 2001 John R. Sheets (for CodeWeavers)
5 * Copyright 2004 Mike McCormack (for CodeWeavers)
6 * Copyright 2008 Detlef Riekenberg
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
25 #include <stdarg.h>
26 #include <stdio.h>
28 #include "wine/unicode.h"
29 #include "wine/debug.h"
31 #include "shdocvw.h"
33 #include "winreg.h"
34 #include "shlwapi.h"
35 #include "wininet.h"
36 #include "isguids.h"
38 #include "initguid.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
42 LONG SHDOCVW_refCount = 0;
44 static HMODULE SHDOCVW_hshell32 = 0;
45 static HINSTANCE ieframe_instance;
47 static HINSTANCE get_ieframe_instance(void)
49 static const WCHAR ieframe_dllW[] = {'i','e','f','r','a','m','e','.','d','l','l',0};
51 if(!ieframe_instance)
52 ieframe_instance = LoadLibraryW(ieframe_dllW);
54 return ieframe_instance;
57 static HRESULT get_ieframe_object(REFCLSID rclsid, REFIID riid, void **ppv)
59 HINSTANCE ieframe_instance;
61 static HRESULT (WINAPI *ieframe_DllGetClassObject)(REFCLSID,REFIID,void**);
63 if(!ieframe_DllGetClassObject) {
64 ieframe_instance = get_ieframe_instance();
65 if(!ieframe_instance)
66 return CLASS_E_CLASSNOTAVAILABLE;
68 ieframe_DllGetClassObject = (void*)GetProcAddress(ieframe_instance, "DllGetClassObject");
69 if(!ieframe_DllGetClassObject)
70 return CLASS_E_CLASSNOTAVAILABLE;
73 return ieframe_DllGetClassObject(rclsid, riid, ppv);
76 /*************************************************************************
77 * DllGetClassObject (SHDOCVW.@)
79 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
81 TRACE("\n");
83 if(IsEqualGUID(&CLSID_WebBrowser, rclsid)
84 || IsEqualGUID(&CLSID_WebBrowser_V1, rclsid)
85 || IsEqualGUID(&CLSID_InternetShortcut, rclsid)
86 || IsEqualGUID(&CLSID_CUrlHistory, rclsid)
87 || IsEqualGUID(&CLSID_TaskbarList, rclsid))
88 return get_ieframe_object(rclsid, riid, ppv);
90 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
91 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
94 /***********************************************************************
95 * DllRegisterServer (shdocvw.@)
97 HRESULT WINAPI DllRegisterServer(void)
99 TRACE("\n");
100 return S_OK;
103 /***********************************************************************
104 * DllUnregisterServer (shdocvw.@)
106 HRESULT WINAPI DllUnregisterServer(void)
108 TRACE("\n");
109 return S_OK;
112 /******************************************************************
113 * IEWinMain (SHDOCVW.101)
115 * Only returns on error.
117 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
119 DWORD (WINAPI *pIEWinMain)(const WCHAR*,int);
120 WCHAR *cmdline;
121 DWORD ret, len;
123 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
125 pIEWinMain = (void*)GetProcAddress(get_ieframe_instance(), MAKEINTRESOURCEA(101));
126 if(!pIEWinMain)
127 ExitProcess(1);
129 len = MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, NULL, 0);
130 cmdline = heap_alloc(len*sizeof(WCHAR));
131 if(!cmdline)
132 ExitProcess(1);
133 MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, cmdline, len);
135 ret = pIEWinMain(cmdline, nShowWindow);
137 heap_free(cmdline);
138 return ret;
141 /*************************************************************************
142 * SHDOCVW DllMain
144 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
146 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
147 switch (fdwReason)
149 case DLL_PROCESS_ATTACH:
150 break;
151 case DLL_PROCESS_DETACH:
152 if (fImpLoad) break;
153 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
154 if (ieframe_instance) FreeLibrary(ieframe_instance);
155 break;
157 return TRUE;
160 /*************************************************************************
161 * DllCanUnloadNow (SHDOCVW.@)
163 HRESULT WINAPI DllCanUnloadNow(void)
165 return SHDOCVW_refCount ? S_FALSE : S_OK;
168 /***********************************************************************
169 * DllGetVersion (SHDOCVW.@)
171 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
173 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
175 /* this is what IE6 on Windows 98 reports */
176 info->dwMajorVersion = 6;
177 info->dwMinorVersion = 0;
178 info->dwBuildNumber = 2600;
179 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
181 return NOERROR;
184 /*************************************************************************
185 * DllInstall (SHDOCVW.@)
187 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
189 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
191 return S_OK;
194 /*************************************************************************
195 * SHDOCVW_LoadShell32
197 * makes sure the handle to shell32 is valid
199 static BOOL SHDOCVW_LoadShell32(void)
201 if (SHDOCVW_hshell32)
202 return TRUE;
203 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
206 /***********************************************************************
207 * @ (SHDOCVW.110)
209 * Called by Win98 explorer.exe main binary, definitely has 0
210 * parameters.
212 DWORD WINAPI WinList_Init(void)
214 FIXME("(), stub!\n");
215 return 0x0deadfeed;
218 /***********************************************************************
219 * @ (SHDOCVW.118)
221 * Called by Win98 explorer.exe main binary, definitely has only one
222 * parameter.
224 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
226 BOOL WINAPI ShellDDEInit(BOOL start)
228 TRACE("(%d)\n", start);
230 if (!pShellDDEInit)
232 if (!SHDOCVW_LoadShell32())
233 return FALSE;
234 pShellDDEInit = (void *)GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
237 if (pShellDDEInit)
238 return pShellDDEInit(start);
239 else
240 return FALSE;
243 /***********************************************************************
244 * @ (SHDOCVW.125)
246 * Called by Win98 explorer.exe main binary, definitely has 0
247 * parameters.
249 DWORD WINAPI RunInstallUninstallStubs(void)
251 FIXME("(), stub!\n");
252 return 0x0deadbee;
255 /***********************************************************************
256 * @ (SHDOCVW.130)
258 * Called by Emerge Desktop (alternative Windows Shell).
260 DWORD WINAPI RunInstallUninstallStubs2(void)
262 FIXME("(), stub!\n");
263 return 0x0deadbee;
266 /***********************************************************************
267 * SetQueryNetSessionCount (SHDOCVW.@)
269 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
271 FIXME("(%u), stub!\n", arg);
272 return 0;
275 /**********************************************************************
276 * Some forwards (by ordinal) to SHLWAPI
279 static void* fetch_shlwapi_ordinal(UINT_PTR ord)
281 static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
282 static HANDLE h;
284 if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
285 return (void*)GetProcAddress(h, (const char*)ord);
288 /******************************************************************
289 * WhichPlatformFORWARD (SHDOCVW.@)
291 DWORD WINAPI WhichPlatformFORWARD(void)
293 static DWORD (WINAPI *p)(void);
295 if (p || (p = fetch_shlwapi_ordinal(276))) return p();
296 return 1; /* not integrated, see shlwapi.WhichPlatform */
299 /******************************************************************
300 * StopWatchModeFORWARD (SHDOCVW.@)
302 void WINAPI StopWatchModeFORWARD(void)
304 static void (WINAPI *p)(void);
306 if (p || (p = fetch_shlwapi_ordinal(241))) p();
309 /******************************************************************
310 * StopWatchFlushFORWARD (SHDOCVW.@)
312 void WINAPI StopWatchFlushFORWARD(void)
314 static void (WINAPI *p)(void);
316 if (p || (p = fetch_shlwapi_ordinal(242))) p();
319 /******************************************************************
320 * StopWatchWFORWARD (SHDOCVW.@)
322 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
323 DWORD dwMode, DWORD dwTimeStamp)
325 static DWORD (WINAPI *p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
327 if (p || (p = fetch_shlwapi_ordinal(243)))
328 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
329 return ERROR_CALL_NOT_IMPLEMENTED;
332 /******************************************************************
333 * StopWatchAFORWARD (SHDOCVW.@)
335 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
336 DWORD dwMode, DWORD dwTimeStamp)
338 static DWORD (WINAPI *p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
340 if (p || (p = fetch_shlwapi_ordinal(244)))
341 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
342 return ERROR_CALL_NOT_IMPLEMENTED;
345 /******************************************************************
346 * URLSubRegQueryA (SHDOCVW.151)
348 HRESULT WINAPI URLSubRegQueryA(LPCSTR regpath, LPCSTR name, DWORD type,
349 LPSTR out, DWORD outlen, DWORD unknown)
351 CHAR buffer[INTERNET_MAX_URL_LENGTH];
352 DWORD len;
353 LONG res;
355 TRACE("(%s, %s, %d, %p, %d, %d)\n", debugstr_a(regpath), debugstr_a(name),
356 type, out, outlen, unknown);
358 if (!out) return S_OK;
360 len = sizeof(buffer);
361 res = SHRegGetUSValueA(regpath, name, NULL, buffer, &len, FALSE, NULL, 0);
362 if (!res) {
363 lstrcpynA(out, buffer, outlen);
364 return S_OK;
367 return E_FAIL;
370 /******************************************************************
371 * ParseURLFromOutsideSourceW (SHDOCVW.170)
373 DWORD WINAPI ParseURLFromOutsideSourceW(LPCWSTR url, LPWSTR out, LPDWORD plen, LPDWORD unknown)
375 WCHAR buffer_in[INTERNET_MAX_URL_LENGTH];
376 WCHAR buffer_out[INTERNET_MAX_URL_LENGTH];
377 LPCWSTR ptr = url;
378 HRESULT hr;
379 DWORD needed;
380 DWORD len;
381 DWORD res = 0;
384 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_w(url), out, plen, unknown,
385 plen ? *plen : 0, unknown ? *unknown : 0);
387 if (!PathIsURLW(ptr)) {
388 len = sizeof(buffer_in) / sizeof(buffer_in[0]);
389 buffer_in[0] = 0;
390 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT);
391 TRACE("got 0x%x with %s\n", hr, debugstr_w(buffer_in));
392 if (hr == S_OK) {
393 /* we parsed the url to buffer_in */
394 ptr = buffer_in;
396 else
398 FIXME("call search hook for %s\n", debugstr_w(ptr));
402 len = sizeof(buffer_out) / sizeof(buffer_out[0]);
403 buffer_out[0] = '\0';
404 hr = UrlCanonicalizeW(ptr, buffer_out, &len, URL_ESCAPE_SPACES_ONLY);
405 needed = lstrlenW(buffer_out)+1;
406 TRACE("got 0x%x with %s (need %d)\n", hr, debugstr_w(buffer_out), needed);
408 if (*plen >= needed) {
409 if (out != NULL) {
410 lstrcpyW(out, buffer_out);
411 res++;
413 needed--;
416 *plen = needed;
418 TRACE("=> %d\n", res);
419 return res;
422 /******************************************************************
423 * ParseURLFromOutsideSourceA (SHDOCVW.169)
425 * See ParseURLFromOutsideSourceW
427 DWORD WINAPI ParseURLFromOutsideSourceA(LPCSTR url, LPSTR out, LPDWORD plen, LPDWORD unknown)
429 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
430 LPWSTR urlW = NULL;
431 DWORD needed;
432 DWORD res;
433 DWORD len;
435 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_a(url), out, plen, unknown,
436 plen ? *plen : 0, unknown ? *unknown : 0);
438 if (url) {
439 len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
440 urlW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
441 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
444 len = sizeof(buffer) / sizeof(buffer[0]);
445 ParseURLFromOutsideSourceW(urlW, buffer, &len, unknown);
446 HeapFree(GetProcessHeap(), 0, urlW);
448 needed = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
450 res = 0;
451 if (*plen >= needed) {
452 if (out != NULL) {
453 WideCharToMultiByte(CP_ACP, 0, buffer, -1, out, *plen, NULL, NULL);
454 res = needed;
456 needed--;
459 *plen = needed;
461 TRACE("=> %d\n", res);
462 return res;
465 /******************************************************************
466 * IEParseDisplayNameWithBCW (SHDOCVW.218)
468 HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl)
470 /* Guessing at parameter 3 based on IShellFolder's ParseDisplayName */
471 FIXME("stub: 0x%x %s %p %p\n",codepage,debugstr_w(lpszDisplayName),pbc,ppidl);
472 return E_FAIL;
475 /******************************************************************
476 * SHRestricted2W (SHDOCVW.159)
478 DWORD WINAPI SHRestricted2W(DWORD res, LPCWSTR url, DWORD reserved)
480 FIXME("(%d %s %d) stub\n", res, debugstr_w(url), reserved);
481 return 0;
484 /******************************************************************
485 * SHRestricted2A (SHDOCVW.158)
487 * See SHRestricted2W
489 DWORD WINAPI SHRestricted2A(DWORD restriction, LPCSTR url, DWORD reserved)
491 LPWSTR urlW = NULL;
492 DWORD res;
494 TRACE("(%d, %s, %d)\n", restriction, debugstr_a(url), reserved);
495 if (url) {
496 DWORD len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
497 urlW = heap_alloc(len * sizeof(WCHAR));
498 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
500 res = SHRestricted2W(restriction, urlW, reserved);
501 heap_free(urlW);
502 return res;
505 /******************************************************************
506 * ImportPrivacySettings (SHDOCVW.@)
508 * Import global and/or per site privacy preferences from an xml file
510 * PARAMS
511 * filename [I] XML file to use
512 * pGlobalPrefs [IO] PTR to a usage flag for the global privacy preferences
513 * pPerSitePrefs [IO] PTR to a usage flag for the per site privacy preferences
515 * RETURNS
516 * Success: TRUE (the privacy preferences where updated)
517 * Failure: FALSE (the privacy preferences are unchanged)
519 * NOTES
520 * Set the flag to TRUE, when the related privacy preferences in the xml file
521 * should be used (parsed and overwrite the current settings).
522 * On return, the flag is TRUE, when the related privacy settings where used
525 BOOL WINAPI ImportPrivacySettings(LPCWSTR filename, BOOL *pGlobalPrefs, BOOL * pPerSitePrefs)
527 FIXME("(%s, %p->%d, %p->%d): stub\n", debugstr_w(filename),
528 pGlobalPrefs, pGlobalPrefs ? *pGlobalPrefs : 0,
529 pPerSitePrefs, pPerSitePrefs ? *pPerSitePrefs : 0);
531 if (pGlobalPrefs) *pGlobalPrefs = FALSE;
532 if (pPerSitePrefs) *pPerSitePrefs = FALSE;
534 return TRUE;
537 /******************************************************************
538 * ResetProfileSharing (SHDOCVW.164)
540 HRESULT WINAPI ResetProfileSharing(HWND hwnd)
542 FIXME("(%p) stub\n", hwnd);
543 return E_NOTIMPL;
546 /******************************************************************
547 * InstallReg_RunDLL (SHDOCVW.@)
549 void WINAPI InstallReg_RunDLL(HWND hwnd, HINSTANCE handle, LPCSTR cmdline, INT show)
551 FIXME("(%p %p %s %x)\n", hwnd, handle, debugstr_a(cmdline), show);