wined3d: Properly compare integers in wined3d_bo_slab_vk_compare().
[wine.git] / dlls / shdocvw / shdocvw_main.c
bloba641bd92a73e03d4670aa415310a810ed088dc8c
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 <stdarg.h>
24 #include <stdio.h>
26 #include "wine/debug.h"
28 #include "shdocvw.h"
30 #include "winreg.h"
31 #include "shlwapi.h"
32 #include "wininet.h"
33 #include "isguids.h"
35 #include "initguid.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
39 LONG SHDOCVW_refCount = 0;
41 static HMODULE SHDOCVW_hshell32 = 0;
42 static HINSTANCE ieframe_instance;
44 static HINSTANCE get_ieframe_instance(void)
46 if(!ieframe_instance)
47 ieframe_instance = LoadLibraryW(L"ieframe.dll");
49 return ieframe_instance;
52 static HRESULT get_ieframe_object(REFCLSID rclsid, REFIID riid, void **ppv)
54 HINSTANCE ieframe_instance;
56 static HRESULT (WINAPI *ieframe_DllGetClassObject)(REFCLSID,REFIID,void**);
58 if(!ieframe_DllGetClassObject) {
59 ieframe_instance = get_ieframe_instance();
60 if(!ieframe_instance)
61 return CLASS_E_CLASSNOTAVAILABLE;
63 ieframe_DllGetClassObject = (void*)GetProcAddress(ieframe_instance, "DllGetClassObject");
64 if(!ieframe_DllGetClassObject)
65 return CLASS_E_CLASSNOTAVAILABLE;
68 return ieframe_DllGetClassObject(rclsid, riid, ppv);
71 /*************************************************************************
72 * DllGetClassObject (SHDOCVW.@)
74 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
76 TRACE("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
78 if(IsEqualGUID(&CLSID_WebBrowser, rclsid)
79 || IsEqualGUID(&CLSID_WebBrowser_V1, rclsid)
80 || IsEqualGUID(&CLSID_InternetShortcut, rclsid)
81 || IsEqualGUID(&CLSID_CUrlHistory, rclsid)
82 || IsEqualGUID(&CLSID_TaskbarList, rclsid))
83 return get_ieframe_object(rclsid, riid, ppv);
85 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
86 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
89 /******************************************************************
90 * IEWinMain (SHDOCVW.101)
92 * Only returns on error.
94 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
96 DWORD (WINAPI *pIEWinMain)(const WCHAR*,int);
97 WCHAR *cmdline;
98 DWORD ret, len;
100 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
102 pIEWinMain = (void*)GetProcAddress(get_ieframe_instance(), MAKEINTRESOURCEA(101));
103 if(!pIEWinMain)
104 ExitProcess(1);
106 len = MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, NULL, 0);
107 cmdline = heap_alloc(len*sizeof(WCHAR));
108 if(!cmdline)
109 ExitProcess(1);
110 MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, cmdline, len);
112 ret = pIEWinMain(cmdline, nShowWindow);
114 heap_free(cmdline);
115 return ret;
118 /*************************************************************************
119 * SHDOCVW DllMain
121 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
123 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
124 switch (fdwReason)
126 case DLL_PROCESS_ATTACH:
127 DisableThreadLibraryCalls(hinst);
128 break;
129 case DLL_PROCESS_DETACH:
130 if (fImpLoad) break;
131 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
132 if (ieframe_instance) FreeLibrary(ieframe_instance);
133 break;
135 return TRUE;
138 /*************************************************************************
139 * DllCanUnloadNow (SHDOCVW.@)
141 HRESULT WINAPI DllCanUnloadNow(void)
143 return SHDOCVW_refCount ? S_FALSE : S_OK;
146 /***********************************************************************
147 * DllGetVersion (SHDOCVW.@)
149 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
151 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
153 /* this is what IE6 on Windows 98 reports */
154 info->dwMajorVersion = 6;
155 info->dwMinorVersion = 0;
156 info->dwBuildNumber = 2600;
157 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
159 return NOERROR;
162 /*************************************************************************
163 * DllInstall (SHDOCVW.@)
165 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
167 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
169 return S_OK;
172 /*************************************************************************
173 * SHDOCVW_LoadShell32
175 * makes sure the handle to shell32 is valid
177 static BOOL SHDOCVW_LoadShell32(void)
179 if (SHDOCVW_hshell32)
180 return TRUE;
181 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
184 /***********************************************************************
185 * @ (SHDOCVW.110)
187 * Called by Win98 explorer.exe main binary, definitely has 0
188 * parameters.
190 DWORD WINAPI WinList_Init(void)
192 FIXME("(), stub!\n");
193 return 0x0deadfeed;
196 /***********************************************************************
197 * @ (SHDOCVW.118)
199 * Called by Win98 explorer.exe main binary, definitely has only one
200 * parameter.
202 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
204 BOOL WINAPI ShellDDEInit(BOOL start)
206 TRACE("(%d)\n", start);
208 if (!pShellDDEInit)
210 if (!SHDOCVW_LoadShell32())
211 return FALSE;
212 pShellDDEInit = (void *)GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
215 if (pShellDDEInit)
216 return pShellDDEInit(start);
217 else
218 return FALSE;
221 /***********************************************************************
222 * @ (SHDOCVW.125)
224 * Called by Win98 explorer.exe main binary, definitely has 0
225 * parameters.
227 DWORD WINAPI RunInstallUninstallStubs(void)
229 FIXME("(), stub!\n");
230 return 0x0deadbee;
233 /***********************************************************************
234 * @ (SHDOCVW.130)
236 * Called by Emerge Desktop (alternative Windows Shell).
238 DWORD WINAPI RunInstallUninstallStubs2(int arg)
240 FIXME("(%d), stub!\n", arg);
241 return 0x0deadbee;
244 /***********************************************************************
245 * SetQueryNetSessionCount (SHDOCVW.@)
247 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
249 FIXME("(%u), stub!\n", arg);
250 return 0;
253 /**********************************************************************
254 * Some forwards (by ordinal) to SHLWAPI
257 static void* fetch_shlwapi_ordinal(UINT_PTR ord)
259 static HANDLE h;
261 if (!h && !(h = GetModuleHandleW(L"shlwapi.dll"))) return NULL;
262 return (void*)GetProcAddress(h, (const char*)ord);
265 /******************************************************************
266 * StopWatchModeFORWARD (SHDOCVW.@)
268 void WINAPI StopWatchModeFORWARD(void)
270 static void (WINAPI *p)(void);
272 if (p || (p = fetch_shlwapi_ordinal(241))) p();
275 /******************************************************************
276 * StopWatchFlushFORWARD (SHDOCVW.@)
278 void WINAPI StopWatchFlushFORWARD(void)
280 static void (WINAPI *p)(void);
282 if (p || (p = fetch_shlwapi_ordinal(242))) p();
285 /******************************************************************
286 * StopWatchAFORWARD (SHDOCVW.@)
288 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
289 DWORD dwMode, DWORD dwTimeStamp)
291 static DWORD (WINAPI *p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
293 if (p || (p = fetch_shlwapi_ordinal(243)))
294 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
295 return ERROR_CALL_NOT_IMPLEMENTED;
298 /******************************************************************
299 * StopWatchWFORWARD (SHDOCVW.@)
301 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
302 DWORD dwMode, DWORD dwTimeStamp)
304 static DWORD (WINAPI *p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
306 if (p || (p = fetch_shlwapi_ordinal(244)))
307 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
308 return ERROR_CALL_NOT_IMPLEMENTED;
311 /******************************************************************
312 * URLSubRegQueryA (SHDOCVW.151)
314 HRESULT WINAPI URLSubRegQueryA(LPCSTR regpath, LPCSTR name, DWORD type,
315 LPSTR out, DWORD outlen, DWORD unknown)
317 CHAR buffer[INTERNET_MAX_URL_LENGTH];
318 DWORD len;
319 LONG res;
321 TRACE("(%s, %s, %d, %p, %d, %d)\n", debugstr_a(regpath), debugstr_a(name),
322 type, out, outlen, unknown);
324 if (!out) return S_OK;
326 len = sizeof(buffer);
327 res = SHRegGetUSValueA(regpath, name, NULL, buffer, &len, FALSE, NULL, 0);
328 if (!res) {
329 lstrcpynA(out, buffer, outlen);
330 return S_OK;
333 return E_FAIL;
336 /******************************************************************
337 * ParseURLFromOutsideSourceW (SHDOCVW.170)
339 DWORD WINAPI ParseURLFromOutsideSourceW(LPCWSTR url, LPWSTR out, LPDWORD plen, LPDWORD unknown)
341 WCHAR buffer_in[INTERNET_MAX_URL_LENGTH];
342 WCHAR buffer_out[INTERNET_MAX_URL_LENGTH];
343 LPCWSTR ptr = url;
344 HRESULT hr;
345 DWORD needed;
346 DWORD len;
347 DWORD res = 0;
350 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_w(url), out, plen, unknown,
351 plen ? *plen : 0, unknown ? *unknown : 0);
353 if (!PathIsURLW(ptr)) {
354 len = ARRAY_SIZE(buffer_in);
355 buffer_in[0] = 0;
356 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT);
357 TRACE("got 0x%x with %s\n", hr, debugstr_w(buffer_in));
358 if (hr == S_OK) {
359 /* we parsed the url to buffer_in */
360 ptr = buffer_in;
362 else
364 FIXME("call search hook for %s\n", debugstr_w(ptr));
368 len = ARRAY_SIZE(buffer_out);
369 buffer_out[0] = '\0';
370 hr = UrlCanonicalizeW(ptr, buffer_out, &len, URL_ESCAPE_SPACES_ONLY);
371 needed = lstrlenW(buffer_out)+1;
372 TRACE("got 0x%x with %s (need %d)\n", hr, debugstr_w(buffer_out), needed);
374 if (*plen >= needed) {
375 if (out != NULL) {
376 lstrcpyW(out, buffer_out);
377 res++;
379 needed--;
382 *plen = needed;
384 TRACE("=> %d\n", res);
385 return res;
388 /******************************************************************
389 * ParseURLFromOutsideSourceA (SHDOCVW.169)
391 * See ParseURLFromOutsideSourceW
393 DWORD WINAPI ParseURLFromOutsideSourceA(LPCSTR url, LPSTR out, LPDWORD plen, LPDWORD unknown)
395 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
396 LPWSTR urlW = NULL;
397 DWORD needed;
398 DWORD res;
399 DWORD len;
401 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_a(url), out, plen, unknown,
402 plen ? *plen : 0, unknown ? *unknown : 0);
404 if (url) {
405 len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
406 urlW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
407 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
410 len = ARRAY_SIZE(buffer);
411 ParseURLFromOutsideSourceW(urlW, buffer, &len, unknown);
412 HeapFree(GetProcessHeap(), 0, urlW);
414 needed = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
416 res = 0;
417 if (*plen >= needed) {
418 if (out != NULL) {
419 WideCharToMultiByte(CP_ACP, 0, buffer, -1, out, *plen, NULL, NULL);
420 res = needed;
422 needed--;
425 *plen = needed;
427 TRACE("=> %d\n", res);
428 return res;
431 /******************************************************************
432 * IEParseDisplayNameWithBCW (SHDOCVW.218)
434 HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl)
436 /* Guessing at parameter 3 based on IShellFolder's ParseDisplayName */
437 FIXME("stub: 0x%x %s %p %p\n",codepage,debugstr_w(lpszDisplayName),pbc,ppidl);
438 return E_FAIL;
441 /******************************************************************
442 * SHRestricted2W (SHDOCVW.159)
444 DWORD WINAPI SHRestricted2W(DWORD res, LPCWSTR url, DWORD reserved)
446 FIXME("(%d %s %d) stub\n", res, debugstr_w(url), reserved);
447 return 0;
450 /******************************************************************
451 * SHRestricted2A (SHDOCVW.158)
453 * See SHRestricted2W
455 DWORD WINAPI SHRestricted2A(DWORD restriction, LPCSTR url, DWORD reserved)
457 LPWSTR urlW = NULL;
458 DWORD res;
460 TRACE("(%d, %s, %d)\n", restriction, debugstr_a(url), reserved);
461 if (url) {
462 DWORD len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
463 urlW = heap_alloc(len * sizeof(WCHAR));
464 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
466 res = SHRestricted2W(restriction, urlW, reserved);
467 heap_free(urlW);
468 return res;
471 /******************************************************************
472 * ImportPrivacySettings (SHDOCVW.@)
474 * Import global and/or per site privacy preferences from an xml file
476 * PARAMS
477 * filename [I] XML file to use
478 * pGlobalPrefs [IO] PTR to a usage flag for the global privacy preferences
479 * pPerSitePrefs [IO] PTR to a usage flag for the per site privacy preferences
481 * RETURNS
482 * Success: TRUE (the privacy preferences where updated)
483 * Failure: FALSE (the privacy preferences are unchanged)
485 * NOTES
486 * Set the flag to TRUE, when the related privacy preferences in the xml file
487 * should be used (parsed and overwrite the current settings).
488 * On return, the flag is TRUE, when the related privacy settings where used
491 BOOL WINAPI ImportPrivacySettings(LPCWSTR filename, BOOL *pGlobalPrefs, BOOL * pPerSitePrefs)
493 FIXME("(%s, %p->%d, %p->%d): stub\n", debugstr_w(filename),
494 pGlobalPrefs, pGlobalPrefs ? *pGlobalPrefs : 0,
495 pPerSitePrefs, pPerSitePrefs ? *pPerSitePrefs : 0);
497 if (pGlobalPrefs) *pGlobalPrefs = FALSE;
498 if (pPerSitePrefs) *pPerSitePrefs = FALSE;
500 return TRUE;
503 /******************************************************************
504 * ResetProfileSharing (SHDOCVW.164)
506 HRESULT WINAPI ResetProfileSharing(HWND hwnd)
508 FIXME("(%p) stub\n", hwnd);
509 return E_NOTIMPL;
512 /******************************************************************
513 * InstallReg_RunDLL (SHDOCVW.@)
515 void WINAPI InstallReg_RunDLL(HWND hwnd, HINSTANCE handle, LPCSTR cmdline, INT show)
517 FIXME("(%p %p %s %x)\n", hwnd, handle, debugstr_a(cmdline), show);
520 /******************************************************************
521 * DoFileDownload (SHDOCVW.@)
523 BOOL WINAPI DoFileDownload(LPWSTR filename)
525 FIXME("(%s) stub\n", debugstr_w(filename));
526 return FALSE;
529 /******************************************************************
530 * DoOrganizeFavDlgW (SHDOCVW.@)
532 BOOL WINAPI DoOrganizeFavDlgW(HWND hwnd, LPCWSTR initDir)
534 FIXME("(%p %s) stub\n", hwnd, debugstr_w(initDir));
535 return FALSE;
538 /******************************************************************
539 * DoOrganizeFavDlg (SHDOCVW.@)
541 BOOL WINAPI DoOrganizeFavDlg(HWND hwnd, LPCSTR initDir)
543 LPWSTR initDirW = NULL;
544 BOOL res;
546 TRACE("(%p %s)\n", hwnd, debugstr_a(initDir));
548 if (initDir) {
549 DWORD len = MultiByteToWideChar(CP_ACP, 0, initDir, -1, NULL, 0);
550 initDirW = heap_alloc(len * sizeof(WCHAR));
551 MultiByteToWideChar(CP_ACP, 0, initDir, -1, initDirW, len);
553 res = DoOrganizeFavDlgW(hwnd, initDirW);
554 heap_free(initDirW);
555 return res;