include: Windows SDK C headers have snprintf.
[wine.git] / dlls / shdocvw / shdocvw_main.c
blob98d0d2cde215327463925801f4e968714e9dea93
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 static const WCHAR ieframe_dllW[] = {'i','e','f','r','a','m','e','.','d','l','l',0};
48 if(!ieframe_instance)
49 ieframe_instance = LoadLibraryW(ieframe_dllW);
51 return ieframe_instance;
54 static HRESULT get_ieframe_object(REFCLSID rclsid, REFIID riid, void **ppv)
56 HINSTANCE ieframe_instance;
58 static HRESULT (WINAPI *ieframe_DllGetClassObject)(REFCLSID,REFIID,void**);
60 if(!ieframe_DllGetClassObject) {
61 ieframe_instance = get_ieframe_instance();
62 if(!ieframe_instance)
63 return CLASS_E_CLASSNOTAVAILABLE;
65 ieframe_DllGetClassObject = (void*)GetProcAddress(ieframe_instance, "DllGetClassObject");
66 if(!ieframe_DllGetClassObject)
67 return CLASS_E_CLASSNOTAVAILABLE;
70 return ieframe_DllGetClassObject(rclsid, riid, ppv);
73 /*************************************************************************
74 * DllGetClassObject (SHDOCVW.@)
76 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
78 TRACE("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
80 if(IsEqualGUID(&CLSID_WebBrowser, rclsid)
81 || IsEqualGUID(&CLSID_WebBrowser_V1, rclsid)
82 || IsEqualGUID(&CLSID_InternetShortcut, rclsid)
83 || IsEqualGUID(&CLSID_CUrlHistory, rclsid)
84 || IsEqualGUID(&CLSID_TaskbarList, rclsid))
85 return get_ieframe_object(rclsid, riid, ppv);
87 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
88 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
91 /***********************************************************************
92 * DllRegisterServer (shdocvw.@)
94 HRESULT WINAPI DllRegisterServer(void)
96 TRACE("\n");
97 return S_OK;
100 /***********************************************************************
101 * DllUnregisterServer (shdocvw.@)
103 HRESULT WINAPI DllUnregisterServer(void)
105 TRACE("\n");
106 return S_OK;
109 /******************************************************************
110 * IEWinMain (SHDOCVW.101)
112 * Only returns on error.
114 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
116 DWORD (WINAPI *pIEWinMain)(const WCHAR*,int);
117 WCHAR *cmdline;
118 DWORD ret, len;
120 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
122 pIEWinMain = (void*)GetProcAddress(get_ieframe_instance(), MAKEINTRESOURCEA(101));
123 if(!pIEWinMain)
124 ExitProcess(1);
126 len = MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, NULL, 0);
127 cmdline = heap_alloc(len*sizeof(WCHAR));
128 if(!cmdline)
129 ExitProcess(1);
130 MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, cmdline, len);
132 ret = pIEWinMain(cmdline, nShowWindow);
134 heap_free(cmdline);
135 return ret;
138 /*************************************************************************
139 * SHDOCVW DllMain
141 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
143 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
144 switch (fdwReason)
146 case DLL_PROCESS_ATTACH:
147 DisableThreadLibraryCalls(hinst);
148 break;
149 case DLL_PROCESS_DETACH:
150 if (fImpLoad) break;
151 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
152 if (ieframe_instance) FreeLibrary(ieframe_instance);
153 break;
155 return TRUE;
158 /*************************************************************************
159 * DllCanUnloadNow (SHDOCVW.@)
161 HRESULT WINAPI DllCanUnloadNow(void)
163 return SHDOCVW_refCount ? S_FALSE : S_OK;
166 /***********************************************************************
167 * DllGetVersion (SHDOCVW.@)
169 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
171 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
173 /* this is what IE6 on Windows 98 reports */
174 info->dwMajorVersion = 6;
175 info->dwMinorVersion = 0;
176 info->dwBuildNumber = 2600;
177 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
179 return NOERROR;
182 /*************************************************************************
183 * DllInstall (SHDOCVW.@)
185 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
187 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
189 return S_OK;
192 /*************************************************************************
193 * SHDOCVW_LoadShell32
195 * makes sure the handle to shell32 is valid
197 static BOOL SHDOCVW_LoadShell32(void)
199 if (SHDOCVW_hshell32)
200 return TRUE;
201 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
204 /***********************************************************************
205 * @ (SHDOCVW.110)
207 * Called by Win98 explorer.exe main binary, definitely has 0
208 * parameters.
210 DWORD WINAPI WinList_Init(void)
212 FIXME("(), stub!\n");
213 return 0x0deadfeed;
216 /***********************************************************************
217 * @ (SHDOCVW.118)
219 * Called by Win98 explorer.exe main binary, definitely has only one
220 * parameter.
222 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
224 BOOL WINAPI ShellDDEInit(BOOL start)
226 TRACE("(%d)\n", start);
228 if (!pShellDDEInit)
230 if (!SHDOCVW_LoadShell32())
231 return FALSE;
232 pShellDDEInit = (void *)GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
235 if (pShellDDEInit)
236 return pShellDDEInit(start);
237 else
238 return FALSE;
241 /***********************************************************************
242 * @ (SHDOCVW.125)
244 * Called by Win98 explorer.exe main binary, definitely has 0
245 * parameters.
247 DWORD WINAPI RunInstallUninstallStubs(void)
249 FIXME("(), stub!\n");
250 return 0x0deadbee;
253 /***********************************************************************
254 * @ (SHDOCVW.130)
256 * Called by Emerge Desktop (alternative Windows Shell).
258 DWORD WINAPI RunInstallUninstallStubs2(int arg)
260 FIXME("(%d), stub!\n", arg);
261 return 0x0deadbee;
264 /***********************************************************************
265 * SetQueryNetSessionCount (SHDOCVW.@)
267 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
269 FIXME("(%u), stub!\n", arg);
270 return 0;
273 /**********************************************************************
274 * Some forwards (by ordinal) to SHLWAPI
277 static void* fetch_shlwapi_ordinal(UINT_PTR ord)
279 static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
280 static HANDLE h;
282 if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
283 return (void*)GetProcAddress(h, (const char*)ord);
286 /******************************************************************
287 * WhichPlatformFORWARD (SHDOCVW.@)
289 DWORD WINAPI WhichPlatformFORWARD(void)
291 static DWORD (WINAPI *p)(void);
293 if (p || (p = fetch_shlwapi_ordinal(276))) return p();
294 return 1; /* not integrated, see shlwapi.WhichPlatform */
297 /******************************************************************
298 * StopWatchModeFORWARD (SHDOCVW.@)
300 void WINAPI StopWatchModeFORWARD(void)
302 static void (WINAPI *p)(void);
304 if (p || (p = fetch_shlwapi_ordinal(241))) p();
307 /******************************************************************
308 * StopWatchFlushFORWARD (SHDOCVW.@)
310 void WINAPI StopWatchFlushFORWARD(void)
312 static void (WINAPI *p)(void);
314 if (p || (p = fetch_shlwapi_ordinal(242))) p();
317 /******************************************************************
318 * StopWatchAFORWARD (SHDOCVW.@)
320 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
321 DWORD dwMode, DWORD dwTimeStamp)
323 static DWORD (WINAPI *p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
325 if (p || (p = fetch_shlwapi_ordinal(243)))
326 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
327 return ERROR_CALL_NOT_IMPLEMENTED;
330 /******************************************************************
331 * StopWatchWFORWARD (SHDOCVW.@)
333 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
334 DWORD dwMode, DWORD dwTimeStamp)
336 static DWORD (WINAPI *p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
338 if (p || (p = fetch_shlwapi_ordinal(244)))
339 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
340 return ERROR_CALL_NOT_IMPLEMENTED;
343 /******************************************************************
344 * URLSubRegQueryA (SHDOCVW.151)
346 HRESULT WINAPI URLSubRegQueryA(LPCSTR regpath, LPCSTR name, DWORD type,
347 LPSTR out, DWORD outlen, DWORD unknown)
349 CHAR buffer[INTERNET_MAX_URL_LENGTH];
350 DWORD len;
351 LONG res;
353 TRACE("(%s, %s, %d, %p, %d, %d)\n", debugstr_a(regpath), debugstr_a(name),
354 type, out, outlen, unknown);
356 if (!out) return S_OK;
358 len = sizeof(buffer);
359 res = SHRegGetUSValueA(regpath, name, NULL, buffer, &len, FALSE, NULL, 0);
360 if (!res) {
361 lstrcpynA(out, buffer, outlen);
362 return S_OK;
365 return E_FAIL;
368 /******************************************************************
369 * ParseURLFromOutsideSourceW (SHDOCVW.170)
371 DWORD WINAPI ParseURLFromOutsideSourceW(LPCWSTR url, LPWSTR out, LPDWORD plen, LPDWORD unknown)
373 WCHAR buffer_in[INTERNET_MAX_URL_LENGTH];
374 WCHAR buffer_out[INTERNET_MAX_URL_LENGTH];
375 LPCWSTR ptr = url;
376 HRESULT hr;
377 DWORD needed;
378 DWORD len;
379 DWORD res = 0;
382 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_w(url), out, plen, unknown,
383 plen ? *plen : 0, unknown ? *unknown : 0);
385 if (!PathIsURLW(ptr)) {
386 len = ARRAY_SIZE(buffer_in);
387 buffer_in[0] = 0;
388 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT);
389 TRACE("got 0x%x with %s\n", hr, debugstr_w(buffer_in));
390 if (hr == S_OK) {
391 /* we parsed the url to buffer_in */
392 ptr = buffer_in;
394 else
396 FIXME("call search hook for %s\n", debugstr_w(ptr));
400 len = ARRAY_SIZE(buffer_out);
401 buffer_out[0] = '\0';
402 hr = UrlCanonicalizeW(ptr, buffer_out, &len, URL_ESCAPE_SPACES_ONLY);
403 needed = lstrlenW(buffer_out)+1;
404 TRACE("got 0x%x with %s (need %d)\n", hr, debugstr_w(buffer_out), needed);
406 if (*plen >= needed) {
407 if (out != NULL) {
408 lstrcpyW(out, buffer_out);
409 res++;
411 needed--;
414 *plen = needed;
416 TRACE("=> %d\n", res);
417 return res;
420 /******************************************************************
421 * ParseURLFromOutsideSourceA (SHDOCVW.169)
423 * See ParseURLFromOutsideSourceW
425 DWORD WINAPI ParseURLFromOutsideSourceA(LPCSTR url, LPSTR out, LPDWORD plen, LPDWORD unknown)
427 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
428 LPWSTR urlW = NULL;
429 DWORD needed;
430 DWORD res;
431 DWORD len;
433 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_a(url), out, plen, unknown,
434 plen ? *plen : 0, unknown ? *unknown : 0);
436 if (url) {
437 len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
438 urlW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
439 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
442 len = ARRAY_SIZE(buffer);
443 ParseURLFromOutsideSourceW(urlW, buffer, &len, unknown);
444 HeapFree(GetProcessHeap(), 0, urlW);
446 needed = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
448 res = 0;
449 if (*plen >= needed) {
450 if (out != NULL) {
451 WideCharToMultiByte(CP_ACP, 0, buffer, -1, out, *plen, NULL, NULL);
452 res = needed;
454 needed--;
457 *plen = needed;
459 TRACE("=> %d\n", res);
460 return res;
463 /******************************************************************
464 * IEParseDisplayNameWithBCW (SHDOCVW.218)
466 HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl)
468 /* Guessing at parameter 3 based on IShellFolder's ParseDisplayName */
469 FIXME("stub: 0x%x %s %p %p\n",codepage,debugstr_w(lpszDisplayName),pbc,ppidl);
470 return E_FAIL;
473 /******************************************************************
474 * SHRestricted2W (SHDOCVW.159)
476 DWORD WINAPI SHRestricted2W(DWORD res, LPCWSTR url, DWORD reserved)
478 FIXME("(%d %s %d) stub\n", res, debugstr_w(url), reserved);
479 return 0;
482 /******************************************************************
483 * SHRestricted2A (SHDOCVW.158)
485 * See SHRestricted2W
487 DWORD WINAPI SHRestricted2A(DWORD restriction, LPCSTR url, DWORD reserved)
489 LPWSTR urlW = NULL;
490 DWORD res;
492 TRACE("(%d, %s, %d)\n", restriction, debugstr_a(url), reserved);
493 if (url) {
494 DWORD len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
495 urlW = heap_alloc(len * sizeof(WCHAR));
496 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
498 res = SHRestricted2W(restriction, urlW, reserved);
499 heap_free(urlW);
500 return res;
503 /******************************************************************
504 * ImportPrivacySettings (SHDOCVW.@)
506 * Import global and/or per site privacy preferences from an xml file
508 * PARAMS
509 * filename [I] XML file to use
510 * pGlobalPrefs [IO] PTR to a usage flag for the global privacy preferences
511 * pPerSitePrefs [IO] PTR to a usage flag for the per site privacy preferences
513 * RETURNS
514 * Success: TRUE (the privacy preferences where updated)
515 * Failure: FALSE (the privacy preferences are unchanged)
517 * NOTES
518 * Set the flag to TRUE, when the related privacy preferences in the xml file
519 * should be used (parsed and overwrite the current settings).
520 * On return, the flag is TRUE, when the related privacy settings where used
523 BOOL WINAPI ImportPrivacySettings(LPCWSTR filename, BOOL *pGlobalPrefs, BOOL * pPerSitePrefs)
525 FIXME("(%s, %p->%d, %p->%d): stub\n", debugstr_w(filename),
526 pGlobalPrefs, pGlobalPrefs ? *pGlobalPrefs : 0,
527 pPerSitePrefs, pPerSitePrefs ? *pPerSitePrefs : 0);
529 if (pGlobalPrefs) *pGlobalPrefs = FALSE;
530 if (pPerSitePrefs) *pPerSitePrefs = FALSE;
532 return TRUE;
535 /******************************************************************
536 * ResetProfileSharing (SHDOCVW.164)
538 HRESULT WINAPI ResetProfileSharing(HWND hwnd)
540 FIXME("(%p) stub\n", hwnd);
541 return E_NOTIMPL;
544 /******************************************************************
545 * InstallReg_RunDLL (SHDOCVW.@)
547 void WINAPI InstallReg_RunDLL(HWND hwnd, HINSTANCE handle, LPCSTR cmdline, INT show)
549 FIXME("(%p %p %s %x)\n", hwnd, handle, debugstr_a(cmdline), show);
552 /******************************************************************
553 * DoFileDownload (SHDOCVW.@)
555 BOOL WINAPI DoFileDownload(LPWSTR filename)
557 FIXME("(%s) stub\n", debugstr_w(filename));
558 return FALSE;
561 /******************************************************************
562 * DoOrganizeFavDlgW (SHDOCVW.@)
564 BOOL WINAPI DoOrganizeFavDlgW(HWND hwnd, LPCWSTR initDir)
566 FIXME("(%p %s) stub\n", hwnd, debugstr_w(initDir));
567 return FALSE;
570 /******************************************************************
571 * DoOrganizeFavDlg (SHDOCVW.@)
573 BOOL WINAPI DoOrganizeFavDlg(HWND hwnd, LPCSTR initDir)
575 LPWSTR initDirW = NULL;
576 BOOL res;
578 TRACE("(%p %s)\n", hwnd, debugstr_a(initDir));
580 if (initDir) {
581 DWORD len = MultiByteToWideChar(CP_ACP, 0, initDir, -1, NULL, 0);
582 initDirW = heap_alloc(len * sizeof(WCHAR));
583 MultiByteToWideChar(CP_ACP, 0, initDir, -1, initDirW, len);
585 res = DoOrganizeFavDlgW(hwnd, initDirW);
586 heap_free(initDirW);
587 return res;