cabinet: Add initial tests for FDI.
[wine] / dlls / shdocvw / shdocvw_main.c
1 /*
2  * SHDOCVW - Internet Explorer Web Control
3  *
4  * Copyright 2001 John R. Sheets (for CodeWeavers)
5  * Copyright 2004 Mike McCormack (for CodeWeavers)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #include "wine/unicode.h"
28 #include "wine/debug.h"
29
30 #include "shdocvw.h"
31
32 #include "winreg.h"
33 #include "shlwapi.h"
34
35 #include "initguid.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
38
39 LONG SHDOCVW_refCount = 0;
40
41 HINSTANCE shdocvw_hinstance = 0;
42 static HMODULE SHDOCVW_hshell32 = 0;
43 static ITypeInfo *wb_typeinfo = NULL;
44
45 HRESULT get_typeinfo(ITypeInfo **typeinfo)
46 {
47     ITypeLib *typelib;
48     HRESULT hres;
49
50     if(wb_typeinfo) {
51         *typeinfo = wb_typeinfo;
52         return S_OK;
53     }
54
55     hres = LoadRegTypeLib(&LIBID_SHDocVw, 1, 1, LOCALE_SYSTEM_DEFAULT, &typelib);
56     if(FAILED(hres)) {
57         ERR("LoadRegTypeLib failed: %08x\n", hres);
58         return hres;
59     }
60
61     hres = ITypeLib_GetTypeInfoOfGuid(typelib, &IID_IWebBrowser2, &wb_typeinfo);
62     ITypeLib_Release(typelib);
63
64     *typeinfo = wb_typeinfo;
65     return hres;
66 }
67
68 /*************************************************************************
69  * SHDOCVW DllMain
70  */
71 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
72 {
73     TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
74     switch (fdwReason)
75     {
76         case DLL_PROCESS_ATTACH:
77         shdocvw_hinstance = hinst;
78         register_iewindow_class();
79         break;
80     case DLL_PROCESS_DETACH:
81         if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
82         unregister_iewindow_class();
83         if(wb_typeinfo)
84             ITypeInfo_Release(wb_typeinfo);
85         break;
86     }
87     return TRUE;
88 }
89
90 /*************************************************************************
91  *              DllCanUnloadNow (SHDOCVW.@)
92  */
93 HRESULT WINAPI DllCanUnloadNow(void)
94 {
95     return SHDOCVW_refCount ? S_FALSE : S_OK;
96 }
97
98 /***********************************************************************
99  *              DllGetVersion (SHDOCVW.@)
100  */
101 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
102 {
103     if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
104
105     /* this is what IE6 on Windows 98 reports */
106     info->dwMajorVersion = 6;
107     info->dwMinorVersion = 0;
108     info->dwBuildNumber = 2600;
109     info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
110
111     return NOERROR;
112 }
113
114 /*************************************************************************
115  *              DllInstall (SHDOCVW.@)
116  */
117 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
118 {
119    FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
120
121    return S_OK;
122 }
123
124 /*************************************************************************
125  * SHDOCVW_LoadShell32
126  *
127  * makes sure the handle to shell32 is valid
128  */
129 static BOOL SHDOCVW_LoadShell32(void)
130 {
131      if (SHDOCVW_hshell32)
132        return TRUE;
133      return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
134 }
135
136 /***********************************************************************
137  *              @ (SHDOCVW.110)
138  *
139  * Called by Win98 explorer.exe main binary, definitely has 0
140  * parameters.
141  */
142 DWORD WINAPI WinList_Init(void)
143 {
144     FIXME("(), stub!\n");
145     return 0x0deadfeed;
146 }
147
148 /***********************************************************************
149  *              @ (SHDOCVW.118)
150  *
151  * Called by Win98 explorer.exe main binary, definitely has only one
152  * parameter.
153  */
154 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
155
156 BOOL WINAPI ShellDDEInit(BOOL start)
157 {
158     TRACE("(%d)\n", start);
159
160     if (!pShellDDEInit)
161     {
162       if (!SHDOCVW_LoadShell32())
163         return FALSE;
164       pShellDDEInit = (void *)GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
165     }
166
167     if (pShellDDEInit)
168       return pShellDDEInit(start);
169     else
170       return FALSE;
171 }
172
173 /***********************************************************************
174  *              @ (SHDOCVW.125)
175  *
176  * Called by Win98 explorer.exe main binary, definitely has 0
177  * parameters.
178  */
179 DWORD WINAPI RunInstallUninstallStubs(void)
180 {
181     FIXME("(), stub!\n");
182     return 0x0deadbee;
183 }
184
185 /***********************************************************************
186  *              SetQueryNetSessionCount (SHDOCVW.@)
187  */
188 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
189 {
190     FIXME("(%u), stub!\n", arg);
191     return 0;
192 }
193
194 /**********************************************************************
195  * OpenURL  (SHDOCVW.@)
196  */
197 void WINAPI OpenURL(HWND hWnd, HINSTANCE hInst, LPCSTR lpcstrUrl, int nShowCmd)
198 {
199     FIXME("%p %p %s %d\n", hWnd, hInst, debugstr_a(lpcstrUrl), nShowCmd);
200 }
201
202 /**********************************************************************
203  * Some forwards (by ordinal) to SHLWAPI
204  */
205
206 static void* fetch_shlwapi_ordinal(unsigned ord)
207 {
208     static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
209     static HANDLE h;
210
211     if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
212     return (void*)GetProcAddress(h, (const char*)ord);
213 }
214
215 /******************************************************************
216  *              WhichPlatformFORWARD            (SHDOCVW.@)
217  */
218 DWORD WINAPI WhichPlatformFORWARD(void)
219 {
220     static DWORD (*WINAPI p)(void);
221
222     if (p || (p = fetch_shlwapi_ordinal(276))) return p();
223     return 1; /* not integrated, see shlwapi.WhichPlatform */
224 }
225
226 /******************************************************************
227  *              StopWatchModeFORWARD            (SHDOCVW.@)
228  */
229 void WINAPI StopWatchModeFORWARD(void)
230 {
231     static void (*WINAPI p)(void);
232
233     if (p || (p = fetch_shlwapi_ordinal(241))) p();
234 }
235
236 /******************************************************************
237  *              StopWatchFlushFORWARD            (SHDOCVW.@)
238  */
239 void WINAPI StopWatchFlushFORWARD(void)
240 {
241     static void (*WINAPI p)(void);
242
243     if (p || (p = fetch_shlwapi_ordinal(242))) p();
244 }
245
246 /******************************************************************
247  *              StopWatchWFORWARD            (SHDOCVW.@)
248  */
249 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
250                                DWORD dwMode, DWORD dwTimeStamp)
251 {
252     static DWORD (*WINAPI p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
253
254     if (p || (p = fetch_shlwapi_ordinal(243)))
255         return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
256     return ERROR_CALL_NOT_IMPLEMENTED;
257 }
258
259 /******************************************************************
260  *              StopWatchAFORWARD            (SHDOCVW.@)
261  */
262 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
263                                DWORD dwMode, DWORD dwTimeStamp)
264 {
265     static DWORD (*WINAPI p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
266
267     if (p || (p = fetch_shlwapi_ordinal(244)))
268         return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
269     return ERROR_CALL_NOT_IMPLEMENTED;
270 }