msvcrt/tests: Remove a space before a '\n'.
[wine/gsoc-2012-control.git] / dlls / shdocvw / shdocvw_main.c
blob110b713d883b5362fd0ab2bc609b03e259d3e89a
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 /*************************************************************************
71 * SHDOCVW DllMain
73 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
75 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
76 switch (fdwReason)
78 case DLL_PROCESS_ATTACH:
79 shdocvw_hinstance = hinst;
80 register_iewindow_class();
81 break;
82 case DLL_PROCESS_DETACH:
83 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
84 unregister_iewindow_class();
85 if(wb_typeinfo)
86 ITypeInfo_Release(wb_typeinfo);
87 break;
89 return TRUE;
92 /*************************************************************************
93 * DllCanUnloadNow (SHDOCVW.@)
95 HRESULT WINAPI DllCanUnloadNow(void)
97 return SHDOCVW_refCount ? S_FALSE : S_OK;
100 /***********************************************************************
101 * DllGetVersion (SHDOCVW.@)
103 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
105 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
107 /* this is what IE6 on Windows 98 reports */
108 info->dwMajorVersion = 6;
109 info->dwMinorVersion = 0;
110 info->dwBuildNumber = 2600;
111 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
113 return NOERROR;
116 /*************************************************************************
117 * DllInstall (SHDOCVW.@)
119 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
121 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
123 return S_OK;
126 /*************************************************************************
127 * SHDOCVW_LoadShell32
129 * makes sure the handle to shell32 is valid
131 static BOOL SHDOCVW_LoadShell32(void)
133 if (SHDOCVW_hshell32)
134 return TRUE;
135 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
138 /***********************************************************************
139 * @ (SHDOCVW.110)
141 * Called by Win98 explorer.exe main binary, definitely has 0
142 * parameters.
144 DWORD WINAPI WinList_Init(void)
146 FIXME("(), stub!\n");
147 return 0x0deadfeed;
150 /***********************************************************************
151 * @ (SHDOCVW.118)
153 * Called by Win98 explorer.exe main binary, definitely has only one
154 * parameter.
156 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
158 BOOL WINAPI ShellDDEInit(BOOL start)
160 TRACE("(%d)\n", start);
162 if (!pShellDDEInit)
164 if (!SHDOCVW_LoadShell32())
165 return FALSE;
166 pShellDDEInit = (void *)GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
169 if (pShellDDEInit)
170 return pShellDDEInit(start);
171 else
172 return FALSE;
175 /***********************************************************************
176 * @ (SHDOCVW.125)
178 * Called by Win98 explorer.exe main binary, definitely has 0
179 * parameters.
181 DWORD WINAPI RunInstallUninstallStubs(void)
183 FIXME("(), stub!\n");
184 return 0x0deadbee;
187 /***********************************************************************
188 * SetQueryNetSessionCount (SHDOCVW.@)
190 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
192 FIXME("(%u), stub!\n", arg);
193 return 0;
196 /**********************************************************************
197 * OpenURL (SHDOCVW.@)
199 void WINAPI OpenURL(HWND hWnd, HINSTANCE hInst, LPCSTR lpcstrUrl, int nShowCmd)
201 FIXME("%p %p %s %d\n", hWnd, hInst, debugstr_a(lpcstrUrl), nShowCmd);
204 /**********************************************************************
205 * Some forwards (by ordinal) to SHLWAPI
208 static void* fetch_shlwapi_ordinal(UINT_PTR ord)
210 static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
211 static HANDLE h;
213 if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
214 return (void*)GetProcAddress(h, (const char*)ord);
217 /******************************************************************
218 * WhichPlatformFORWARD (SHDOCVW.@)
220 DWORD WINAPI WhichPlatformFORWARD(void)
222 static DWORD (WINAPI *p)(void);
224 if (p || (p = fetch_shlwapi_ordinal(276))) return p();
225 return 1; /* not integrated, see shlwapi.WhichPlatform */
228 /******************************************************************
229 * StopWatchModeFORWARD (SHDOCVW.@)
231 void WINAPI StopWatchModeFORWARD(void)
233 static void (WINAPI *p)(void);
235 if (p || (p = fetch_shlwapi_ordinal(241))) p();
238 /******************************************************************
239 * StopWatchFlushFORWARD (SHDOCVW.@)
241 void WINAPI StopWatchFlushFORWARD(void)
243 static void (WINAPI *p)(void);
245 if (p || (p = fetch_shlwapi_ordinal(242))) p();
248 /******************************************************************
249 * StopWatchWFORWARD (SHDOCVW.@)
251 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
252 DWORD dwMode, DWORD dwTimeStamp)
254 static DWORD (WINAPI *p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
256 if (p || (p = fetch_shlwapi_ordinal(243)))
257 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
258 return ERROR_CALL_NOT_IMPLEMENTED;
261 /******************************************************************
262 * StopWatchAFORWARD (SHDOCVW.@)
264 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
265 DWORD dwMode, DWORD dwTimeStamp)
267 static DWORD (WINAPI *p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
269 if (p || (p = fetch_shlwapi_ordinal(244)))
270 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
271 return ERROR_CALL_NOT_IMPLEMENTED;
274 /******************************************************************
275 * URLSubRegQueryA (SHDOCVW.151)
277 HRESULT WINAPI URLSubRegQueryA(LPCSTR regpath, LPCSTR name, DWORD type,
278 LPSTR out, DWORD outlen, DWORD unknown)
280 CHAR buffer[INTERNET_MAX_URL_LENGTH];
281 DWORD len;
282 LONG res;
284 TRACE("(%s, %s, %d, %p, %d, %d)\n", debugstr_a(regpath), debugstr_a(name),
285 type, out, outlen, unknown);
287 if (!out) return S_OK;
289 len = sizeof(buffer);
290 res = SHRegGetUSValueA(regpath, name, NULL, buffer, &len, FALSE, NULL, 0);
291 if (!res) {
292 lstrcpynA(out, buffer, outlen);
293 return S_OK;
296 return E_FAIL;
299 /******************************************************************
300 * ParseURLFromOutsideSourceW (SHDOCVW.170)
302 DWORD WINAPI ParseURLFromOutsideSourceW(LPCWSTR url, LPWSTR out, LPDWORD plen, LPDWORD unknown)
304 WCHAR buffer_in[INTERNET_MAX_URL_LENGTH];
305 WCHAR buffer_out[INTERNET_MAX_URL_LENGTH];
306 LPCWSTR ptr = url;
307 HRESULT hr;
308 DWORD needed;
309 DWORD len;
310 DWORD res = 0;
313 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_w(url), out, plen, unknown,
314 plen ? *plen : 0, unknown ? *unknown : 0);
316 if (!PathIsURLW(ptr)) {
317 len = sizeof(buffer_in) / sizeof(buffer_in[0]);
318 buffer_in[0] = 0;
319 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_GUESSSCHEME);
320 TRACE("got 0x%x with %s\n", hr, debugstr_w(buffer_in));
321 if (hr != S_OK) {
322 /* when we can't guess the scheme, use the default scheme */
323 len = sizeof(buffer_in) / sizeof(buffer_in[0]);
324 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_DEFAULT);
327 if (hr == S_OK) {
328 /* we parsed the url to buffer_in */
329 ptr = buffer_in;
331 else
333 FIXME("call search hook for %s\n", debugstr_w(ptr));
337 len = sizeof(buffer_out) / sizeof(buffer_out[0]);
338 buffer_out[0] = '\0';
339 hr = UrlCanonicalizeW(ptr, buffer_out, &len, URL_ESCAPE_SPACES_ONLY);
340 needed = lstrlenW(buffer_out)+1;
341 TRACE("got 0x%x with %s (need %d)\n", hr, debugstr_w(buffer_out), needed);
343 if (*plen >= needed) {
344 if (out != NULL) {
345 lstrcpyW(out, buffer_out);
346 res++;
348 needed--;
351 *plen = needed;
353 TRACE("=> %d\n", res);
354 return res;
357 /******************************************************************
358 * ParseURLFromOutsideSourceA (SHDOCVW.169)
360 * See ParseURLFromOutsideSourceW
362 DWORD WINAPI ParseURLFromOutsideSourceA(LPCSTR url, LPSTR out, LPDWORD plen, LPDWORD unknown)
364 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
365 LPWSTR urlW = NULL;
366 DWORD needed;
367 DWORD res;
368 DWORD len;
370 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_a(url), out, plen, unknown,
371 plen ? *plen : 0, unknown ? *unknown : 0);
373 if (url) {
374 len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
375 urlW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
376 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
379 len = sizeof(buffer) / sizeof(buffer[0]);
380 res = ParseURLFromOutsideSourceW(urlW, buffer, &len, unknown);
381 HeapFree(GetProcessHeap(), 0, urlW);
383 needed = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
385 res = 0;
386 if (*plen >= needed) {
387 if (out != NULL) {
388 WideCharToMultiByte(CP_ACP, 0, buffer, -1, out, *plen, NULL, NULL);
389 res = needed;
391 needed--;
394 *plen = needed;
396 TRACE("=> %d\n", res);
397 return res;
400 /******************************************************************
401 * IEParseDisplayNameWithBCW (SHDOCVW.218)
403 HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl)
405 /* Guessing at parameter 3 based on IShellFolder's ParseDisplayName */
406 FIXME("stub: 0x%x %s %p %p\n",codepage,debugstr_w(lpszDisplayName),pbc,ppidl);
407 return E_FAIL;