shlwapi/tests: Add some tests for memory stream.
[wine.git] / dlls / shdocvw / shdocvw_main.c
blob2657dfa5a581cddc517dd43e0e2419ce3156c3e7
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("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
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 DisableThreadLibraryCalls(hinst);
151 break;
152 case DLL_PROCESS_DETACH:
153 if (fImpLoad) break;
154 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
155 if (ieframe_instance) FreeLibrary(ieframe_instance);
156 break;
158 return TRUE;
161 /*************************************************************************
162 * DllCanUnloadNow (SHDOCVW.@)
164 HRESULT WINAPI DllCanUnloadNow(void)
166 return SHDOCVW_refCount ? S_FALSE : S_OK;
169 /***********************************************************************
170 * DllGetVersion (SHDOCVW.@)
172 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
174 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
176 /* this is what IE6 on Windows 98 reports */
177 info->dwMajorVersion = 6;
178 info->dwMinorVersion = 0;
179 info->dwBuildNumber = 2600;
180 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
182 return NOERROR;
185 /*************************************************************************
186 * DllInstall (SHDOCVW.@)
188 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
190 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
192 return S_OK;
195 /*************************************************************************
196 * SHDOCVW_LoadShell32
198 * makes sure the handle to shell32 is valid
200 static BOOL SHDOCVW_LoadShell32(void)
202 if (SHDOCVW_hshell32)
203 return TRUE;
204 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
207 /***********************************************************************
208 * @ (SHDOCVW.110)
210 * Called by Win98 explorer.exe main binary, definitely has 0
211 * parameters.
213 DWORD WINAPI WinList_Init(void)
215 FIXME("(), stub!\n");
216 return 0x0deadfeed;
219 /***********************************************************************
220 * @ (SHDOCVW.118)
222 * Called by Win98 explorer.exe main binary, definitely has only one
223 * parameter.
225 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
227 BOOL WINAPI ShellDDEInit(BOOL start)
229 TRACE("(%d)\n", start);
231 if (!pShellDDEInit)
233 if (!SHDOCVW_LoadShell32())
234 return FALSE;
235 pShellDDEInit = (void *)GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
238 if (pShellDDEInit)
239 return pShellDDEInit(start);
240 else
241 return FALSE;
244 /***********************************************************************
245 * @ (SHDOCVW.125)
247 * Called by Win98 explorer.exe main binary, definitely has 0
248 * parameters.
250 DWORD WINAPI RunInstallUninstallStubs(void)
252 FIXME("(), stub!\n");
253 return 0x0deadbee;
256 /***********************************************************************
257 * @ (SHDOCVW.130)
259 * Called by Emerge Desktop (alternative Windows Shell).
261 DWORD WINAPI RunInstallUninstallStubs2(int arg)
263 FIXME("(%d), stub!\n", arg);
264 return 0x0deadbee;
267 /***********************************************************************
268 * SetQueryNetSessionCount (SHDOCVW.@)
270 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
272 FIXME("(%u), stub!\n", arg);
273 return 0;
276 /**********************************************************************
277 * Some forwards (by ordinal) to SHLWAPI
280 static void* fetch_shlwapi_ordinal(UINT_PTR ord)
282 static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
283 static HANDLE h;
285 if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
286 return (void*)GetProcAddress(h, (const char*)ord);
289 /******************************************************************
290 * WhichPlatformFORWARD (SHDOCVW.@)
292 DWORD WINAPI WhichPlatformFORWARD(void)
294 static DWORD (WINAPI *p)(void);
296 if (p || (p = fetch_shlwapi_ordinal(276))) return p();
297 return 1; /* not integrated, see shlwapi.WhichPlatform */
300 /******************************************************************
301 * StopWatchModeFORWARD (SHDOCVW.@)
303 void WINAPI StopWatchModeFORWARD(void)
305 static void (WINAPI *p)(void);
307 if (p || (p = fetch_shlwapi_ordinal(241))) p();
310 /******************************************************************
311 * StopWatchFlushFORWARD (SHDOCVW.@)
313 void WINAPI StopWatchFlushFORWARD(void)
315 static void (WINAPI *p)(void);
317 if (p || (p = fetch_shlwapi_ordinal(242))) p();
320 /******************************************************************
321 * StopWatchAFORWARD (SHDOCVW.@)
323 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
324 DWORD dwMode, DWORD dwTimeStamp)
326 static DWORD (WINAPI *p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
328 if (p || (p = fetch_shlwapi_ordinal(243)))
329 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
330 return ERROR_CALL_NOT_IMPLEMENTED;
333 /******************************************************************
334 * StopWatchWFORWARD (SHDOCVW.@)
336 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
337 DWORD dwMode, DWORD dwTimeStamp)
339 static DWORD (WINAPI *p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
341 if (p || (p = fetch_shlwapi_ordinal(244)))
342 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
343 return ERROR_CALL_NOT_IMPLEMENTED;
346 /******************************************************************
347 * URLSubRegQueryA (SHDOCVW.151)
349 HRESULT WINAPI URLSubRegQueryA(LPCSTR regpath, LPCSTR name, DWORD type,
350 LPSTR out, DWORD outlen, DWORD unknown)
352 CHAR buffer[INTERNET_MAX_URL_LENGTH];
353 DWORD len;
354 LONG res;
356 TRACE("(%s, %s, %d, %p, %d, %d)\n", debugstr_a(regpath), debugstr_a(name),
357 type, out, outlen, unknown);
359 if (!out) return S_OK;
361 len = sizeof(buffer);
362 res = SHRegGetUSValueA(regpath, name, NULL, buffer, &len, FALSE, NULL, 0);
363 if (!res) {
364 lstrcpynA(out, buffer, outlen);
365 return S_OK;
368 return E_FAIL;
371 /******************************************************************
372 * ParseURLFromOutsideSourceW (SHDOCVW.170)
374 DWORD WINAPI ParseURLFromOutsideSourceW(LPCWSTR url, LPWSTR out, LPDWORD plen, LPDWORD unknown)
376 WCHAR buffer_in[INTERNET_MAX_URL_LENGTH];
377 WCHAR buffer_out[INTERNET_MAX_URL_LENGTH];
378 LPCWSTR ptr = url;
379 HRESULT hr;
380 DWORD needed;
381 DWORD len;
382 DWORD res = 0;
385 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_w(url), out, plen, unknown,
386 plen ? *plen : 0, unknown ? *unknown : 0);
388 if (!PathIsURLW(ptr)) {
389 len = ARRAY_SIZE(buffer_in);
390 buffer_in[0] = 0;
391 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT);
392 TRACE("got 0x%x with %s\n", hr, debugstr_w(buffer_in));
393 if (hr == S_OK) {
394 /* we parsed the url to buffer_in */
395 ptr = buffer_in;
397 else
399 FIXME("call search hook for %s\n", debugstr_w(ptr));
403 len = ARRAY_SIZE(buffer_out);
404 buffer_out[0] = '\0';
405 hr = UrlCanonicalizeW(ptr, buffer_out, &len, URL_ESCAPE_SPACES_ONLY);
406 needed = lstrlenW(buffer_out)+1;
407 TRACE("got 0x%x with %s (need %d)\n", hr, debugstr_w(buffer_out), needed);
409 if (*plen >= needed) {
410 if (out != NULL) {
411 lstrcpyW(out, buffer_out);
412 res++;
414 needed--;
417 *plen = needed;
419 TRACE("=> %d\n", res);
420 return res;
423 /******************************************************************
424 * ParseURLFromOutsideSourceA (SHDOCVW.169)
426 * See ParseURLFromOutsideSourceW
428 DWORD WINAPI ParseURLFromOutsideSourceA(LPCSTR url, LPSTR out, LPDWORD plen, LPDWORD unknown)
430 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
431 LPWSTR urlW = NULL;
432 DWORD needed;
433 DWORD res;
434 DWORD len;
436 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_a(url), out, plen, unknown,
437 plen ? *plen : 0, unknown ? *unknown : 0);
439 if (url) {
440 len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
441 urlW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
442 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
445 len = ARRAY_SIZE(buffer);
446 ParseURLFromOutsideSourceW(urlW, buffer, &len, unknown);
447 HeapFree(GetProcessHeap(), 0, urlW);
449 needed = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
451 res = 0;
452 if (*plen >= needed) {
453 if (out != NULL) {
454 WideCharToMultiByte(CP_ACP, 0, buffer, -1, out, *plen, NULL, NULL);
455 res = needed;
457 needed--;
460 *plen = needed;
462 TRACE("=> %d\n", res);
463 return res;
466 /******************************************************************
467 * IEParseDisplayNameWithBCW (SHDOCVW.218)
469 HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl)
471 /* Guessing at parameter 3 based on IShellFolder's ParseDisplayName */
472 FIXME("stub: 0x%x %s %p %p\n",codepage,debugstr_w(lpszDisplayName),pbc,ppidl);
473 return E_FAIL;
476 /******************************************************************
477 * SHRestricted2W (SHDOCVW.159)
479 DWORD WINAPI SHRestricted2W(DWORD res, LPCWSTR url, DWORD reserved)
481 FIXME("(%d %s %d) stub\n", res, debugstr_w(url), reserved);
482 return 0;
485 /******************************************************************
486 * SHRestricted2A (SHDOCVW.158)
488 * See SHRestricted2W
490 DWORD WINAPI SHRestricted2A(DWORD restriction, LPCSTR url, DWORD reserved)
492 LPWSTR urlW = NULL;
493 DWORD res;
495 TRACE("(%d, %s, %d)\n", restriction, debugstr_a(url), reserved);
496 if (url) {
497 DWORD len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
498 urlW = heap_alloc(len * sizeof(WCHAR));
499 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
501 res = SHRestricted2W(restriction, urlW, reserved);
502 heap_free(urlW);
503 return res;
506 /******************************************************************
507 * ImportPrivacySettings (SHDOCVW.@)
509 * Import global and/or per site privacy preferences from an xml file
511 * PARAMS
512 * filename [I] XML file to use
513 * pGlobalPrefs [IO] PTR to a usage flag for the global privacy preferences
514 * pPerSitePrefs [IO] PTR to a usage flag for the per site privacy preferences
516 * RETURNS
517 * Success: TRUE (the privacy preferences where updated)
518 * Failure: FALSE (the privacy preferences are unchanged)
520 * NOTES
521 * Set the flag to TRUE, when the related privacy preferences in the xml file
522 * should be used (parsed and overwrite the current settings).
523 * On return, the flag is TRUE, when the related privacy settings where used
526 BOOL WINAPI ImportPrivacySettings(LPCWSTR filename, BOOL *pGlobalPrefs, BOOL * pPerSitePrefs)
528 FIXME("(%s, %p->%d, %p->%d): stub\n", debugstr_w(filename),
529 pGlobalPrefs, pGlobalPrefs ? *pGlobalPrefs : 0,
530 pPerSitePrefs, pPerSitePrefs ? *pPerSitePrefs : 0);
532 if (pGlobalPrefs) *pGlobalPrefs = FALSE;
533 if (pPerSitePrefs) *pPerSitePrefs = FALSE;
535 return TRUE;
538 /******************************************************************
539 * ResetProfileSharing (SHDOCVW.164)
541 HRESULT WINAPI ResetProfileSharing(HWND hwnd)
543 FIXME("(%p) stub\n", hwnd);
544 return E_NOTIMPL;
547 /******************************************************************
548 * InstallReg_RunDLL (SHDOCVW.@)
550 void WINAPI InstallReg_RunDLL(HWND hwnd, HINSTANCE handle, LPCSTR cmdline, INT show)
552 FIXME("(%p %p %s %x)\n", hwnd, handle, debugstr_a(cmdline), show);
555 /******************************************************************
556 * DoFileDownload (SHDOCVW.@)
558 BOOL WINAPI DoFileDownload(LPWSTR filename)
560 FIXME("(%s) stub\n", debugstr_w(filename));
561 return FALSE;
564 /******************************************************************
565 * DoOrganizeFavDlgW (SHDOCVW.@)
567 BOOL WINAPI DoOrganizeFavDlgW(HWND hwnd, LPCWSTR initDir)
569 FIXME("(%p %s) stub\n", hwnd, debugstr_w(initDir));
570 return FALSE;
573 /******************************************************************
574 * DoOrganizeFavDlg (SHDOCVW.@)
576 BOOL WINAPI DoOrganizeFavDlg(HWND hwnd, LPCSTR initDir)
578 LPWSTR initDirW = NULL;
579 BOOL res;
581 TRACE("(%p %s)\n", hwnd, debugstr_a(initDir));
583 if (initDir) {
584 DWORD len = MultiByteToWideChar(CP_ACP, 0, initDir, -1, NULL, 0);
585 initDirW = heap_alloc(len * sizeof(WCHAR));
586 MultiByteToWideChar(CP_ACP, 0, initDir, -1, initDirW, len);
588 res = DoOrganizeFavDlgW(hwnd, initDirW);
589 heap_free(initDirW);
590 return res;