wuapi: Return success from automatic_updates_Resume.
[wine/multimedia.git] / dlls / shdocvw / shdocvw_main.c
blob5dfd2b99ddf0694b618c981a4dd1fbfcc41f98b1
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"
37 #include "initguid.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
41 LONG SHDOCVW_refCount = 0;
43 HINSTANCE shdocvw_hinstance = 0;
44 static HMODULE SHDOCVW_hshell32 = 0;
45 static ITypeInfo *wb_typeinfo = NULL;
47 HRESULT get_typeinfo(ITypeInfo **typeinfo)
49 ITypeLib *typelib;
50 HRESULT hres;
52 if(wb_typeinfo) {
53 *typeinfo = wb_typeinfo;
54 return S_OK;
57 hres = LoadRegTypeLib(&LIBID_SHDocVw, 1, 1, LOCALE_SYSTEM_DEFAULT, &typelib);
58 if(FAILED(hres)) {
59 ERR("LoadRegTypeLib failed: %08x\n", hres);
60 return hres;
63 hres = ITypeLib_GetTypeInfoOfGuid(typelib, &IID_IWebBrowser2, &wb_typeinfo);
64 ITypeLib_Release(typelib);
66 *typeinfo = wb_typeinfo;
67 return hres;
70 const char *debugstr_variant(const VARIANT *v)
72 if(!v)
73 return "(null)";
75 switch(V_VT(v)) {
76 case VT_EMPTY:
77 return "{VT_EMPTY}";
78 case VT_NULL:
79 return "{VT_NULL}";
80 case VT_I4:
81 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
82 case VT_R8:
83 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
84 case VT_BSTR:
85 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
86 case VT_DISPATCH:
87 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
88 case VT_BOOL:
89 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
90 default:
91 return wine_dbg_sprintf("{vt %d}", V_VT(v));
95 /*************************************************************************
96 * SHDOCVW DllMain
98 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
100 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
101 switch (fdwReason)
103 case DLL_PROCESS_ATTACH:
104 shdocvw_hinstance = hinst;
105 register_iewindow_class();
106 break;
107 case DLL_PROCESS_DETACH:
108 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
109 unregister_iewindow_class();
110 if(wb_typeinfo)
111 ITypeInfo_Release(wb_typeinfo);
112 break;
114 return TRUE;
117 /*************************************************************************
118 * DllCanUnloadNow (SHDOCVW.@)
120 HRESULT WINAPI DllCanUnloadNow(void)
122 return SHDOCVW_refCount ? S_FALSE : S_OK;
125 /***********************************************************************
126 * DllGetVersion (SHDOCVW.@)
128 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
130 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
132 /* this is what IE6 on Windows 98 reports */
133 info->dwMajorVersion = 6;
134 info->dwMinorVersion = 0;
135 info->dwBuildNumber = 2600;
136 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
138 return NOERROR;
141 /*************************************************************************
142 * DllInstall (SHDOCVW.@)
144 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
146 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
148 return S_OK;
151 /*************************************************************************
152 * SHDOCVW_LoadShell32
154 * makes sure the handle to shell32 is valid
156 static BOOL SHDOCVW_LoadShell32(void)
158 if (SHDOCVW_hshell32)
159 return TRUE;
160 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
163 /***********************************************************************
164 * @ (SHDOCVW.110)
166 * Called by Win98 explorer.exe main binary, definitely has 0
167 * parameters.
169 DWORD WINAPI WinList_Init(void)
171 FIXME("(), stub!\n");
172 return 0x0deadfeed;
175 /***********************************************************************
176 * @ (SHDOCVW.118)
178 * Called by Win98 explorer.exe main binary, definitely has only one
179 * parameter.
181 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
183 BOOL WINAPI ShellDDEInit(BOOL start)
185 TRACE("(%d)\n", start);
187 if (!pShellDDEInit)
189 if (!SHDOCVW_LoadShell32())
190 return FALSE;
191 pShellDDEInit = (void *)GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
194 if (pShellDDEInit)
195 return pShellDDEInit(start);
196 else
197 return FALSE;
200 /***********************************************************************
201 * @ (SHDOCVW.125)
203 * Called by Win98 explorer.exe main binary, definitely has 0
204 * parameters.
206 DWORD WINAPI RunInstallUninstallStubs(void)
208 FIXME("(), stub!\n");
209 return 0x0deadbee;
212 /***********************************************************************
213 * SetQueryNetSessionCount (SHDOCVW.@)
215 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
217 FIXME("(%u), stub!\n", arg);
218 return 0;
221 /**********************************************************************
222 * OpenURL (SHDOCVW.@)
224 void WINAPI OpenURL(HWND hWnd, HINSTANCE hInst, LPCSTR lpcstrUrl, int nShowCmd)
226 FIXME("%p %p %s %d\n", hWnd, hInst, debugstr_a(lpcstrUrl), nShowCmd);
229 /**********************************************************************
230 * Some forwards (by ordinal) to SHLWAPI
233 static void* fetch_shlwapi_ordinal(UINT_PTR ord)
235 static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
236 static HANDLE h;
238 if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
239 return (void*)GetProcAddress(h, (const char*)ord);
242 /******************************************************************
243 * WhichPlatformFORWARD (SHDOCVW.@)
245 DWORD WINAPI WhichPlatformFORWARD(void)
247 static DWORD (WINAPI *p)(void);
249 if (p || (p = fetch_shlwapi_ordinal(276))) return p();
250 return 1; /* not integrated, see shlwapi.WhichPlatform */
253 /******************************************************************
254 * StopWatchModeFORWARD (SHDOCVW.@)
256 void WINAPI StopWatchModeFORWARD(void)
258 static void (WINAPI *p)(void);
260 if (p || (p = fetch_shlwapi_ordinal(241))) p();
263 /******************************************************************
264 * StopWatchFlushFORWARD (SHDOCVW.@)
266 void WINAPI StopWatchFlushFORWARD(void)
268 static void (WINAPI *p)(void);
270 if (p || (p = fetch_shlwapi_ordinal(242))) p();
273 /******************************************************************
274 * StopWatchWFORWARD (SHDOCVW.@)
276 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
277 DWORD dwMode, DWORD dwTimeStamp)
279 static DWORD (WINAPI *p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
281 if (p || (p = fetch_shlwapi_ordinal(243)))
282 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
283 return ERROR_CALL_NOT_IMPLEMENTED;
286 /******************************************************************
287 * StopWatchAFORWARD (SHDOCVW.@)
289 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
290 DWORD dwMode, DWORD dwTimeStamp)
292 static DWORD (WINAPI *p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
294 if (p || (p = fetch_shlwapi_ordinal(244)))
295 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
296 return ERROR_CALL_NOT_IMPLEMENTED;
299 /******************************************************************
300 * URLSubRegQueryA (SHDOCVW.151)
302 HRESULT WINAPI URLSubRegQueryA(LPCSTR regpath, LPCSTR name, DWORD type,
303 LPSTR out, DWORD outlen, DWORD unknown)
305 CHAR buffer[INTERNET_MAX_URL_LENGTH];
306 DWORD len;
307 LONG res;
309 TRACE("(%s, %s, %d, %p, %d, %d)\n", debugstr_a(regpath), debugstr_a(name),
310 type, out, outlen, unknown);
312 if (!out) return S_OK;
314 len = sizeof(buffer);
315 res = SHRegGetUSValueA(regpath, name, NULL, buffer, &len, FALSE, NULL, 0);
316 if (!res) {
317 lstrcpynA(out, buffer, outlen);
318 return S_OK;
321 return E_FAIL;
324 /******************************************************************
325 * ParseURLFromOutsideSourceW (SHDOCVW.170)
327 DWORD WINAPI ParseURLFromOutsideSourceW(LPCWSTR url, LPWSTR out, LPDWORD plen, LPDWORD unknown)
329 WCHAR buffer_in[INTERNET_MAX_URL_LENGTH];
330 WCHAR buffer_out[INTERNET_MAX_URL_LENGTH];
331 LPCWSTR ptr = url;
332 HRESULT hr;
333 DWORD needed;
334 DWORD len;
335 DWORD res = 0;
338 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_w(url), out, plen, unknown,
339 plen ? *plen : 0, unknown ? *unknown : 0);
341 if (!PathIsURLW(ptr)) {
342 len = sizeof(buffer_in) / sizeof(buffer_in[0]);
343 buffer_in[0] = 0;
344 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_GUESSSCHEME);
345 TRACE("got 0x%x with %s\n", hr, debugstr_w(buffer_in));
346 if (hr != S_OK) {
347 /* when we can't guess the scheme, use the default scheme */
348 len = sizeof(buffer_in) / sizeof(buffer_in[0]);
349 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_DEFAULT);
352 if (hr == S_OK) {
353 /* we parsed the url to buffer_in */
354 ptr = buffer_in;
356 else
358 FIXME("call search hook for %s\n", debugstr_w(ptr));
362 len = sizeof(buffer_out) / sizeof(buffer_out[0]);
363 buffer_out[0] = '\0';
364 hr = UrlCanonicalizeW(ptr, buffer_out, &len, URL_ESCAPE_SPACES_ONLY);
365 needed = lstrlenW(buffer_out)+1;
366 TRACE("got 0x%x with %s (need %d)\n", hr, debugstr_w(buffer_out), needed);
368 if (*plen >= needed) {
369 if (out != NULL) {
370 lstrcpyW(out, buffer_out);
371 res++;
373 needed--;
376 *plen = needed;
378 TRACE("=> %d\n", res);
379 return res;
382 /******************************************************************
383 * ParseURLFromOutsideSourceA (SHDOCVW.169)
385 * See ParseURLFromOutsideSourceW
387 DWORD WINAPI ParseURLFromOutsideSourceA(LPCSTR url, LPSTR out, LPDWORD plen, LPDWORD unknown)
389 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
390 LPWSTR urlW = NULL;
391 DWORD needed;
392 DWORD res;
393 DWORD len;
395 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_a(url), out, plen, unknown,
396 plen ? *plen : 0, unknown ? *unknown : 0);
398 if (url) {
399 len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
400 urlW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
401 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
404 len = sizeof(buffer) / sizeof(buffer[0]);
405 res = ParseURLFromOutsideSourceW(urlW, buffer, &len, unknown);
406 HeapFree(GetProcessHeap(), 0, urlW);
408 needed = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
410 res = 0;
411 if (*plen >= needed) {
412 if (out != NULL) {
413 WideCharToMultiByte(CP_ACP, 0, buffer, -1, out, *plen, NULL, NULL);
414 res = needed;
416 needed--;
419 *plen = needed;
421 TRACE("=> %d\n", res);
422 return res;
425 /******************************************************************
426 * IEParseDisplayNameWithBCW (SHDOCVW.218)
428 HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl)
430 /* Guessing at parameter 3 based on IShellFolder's ParseDisplayName */
431 FIXME("stub: 0x%x %s %p %p\n",codepage,debugstr_w(lpszDisplayName),pbc,ppidl);
432 return E_FAIL;
435 /******************************************************************
436 * SHRestricted2W (SHDOCVW.159)
438 DWORD WINAPI SHRestricted2W(DWORD res, LPCWSTR url, DWORD reserved)
440 FIXME("(%d %s %d) stub\n", res, debugstr_w(url), reserved);
441 return 0;
444 /******************************************************************
445 * SHRestricted2A (SHDOCVW.158)
447 * See SHRestricted2W
449 DWORD WINAPI SHRestricted2A(DWORD restriction, LPCSTR url, DWORD reserved)
451 LPWSTR urlW = NULL;
452 DWORD res;
454 TRACE("(%d, %s, %d)\n", restriction, debugstr_a(url), reserved);
455 if (url) {
456 DWORD len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
457 urlW = heap_alloc(len * sizeof(WCHAR));
458 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
460 res = SHRestricted2W(restriction, urlW, reserved);
461 heap_free(urlW);
462 return res;