Make sure we include config.h before including twain_i.h.
[wine/hacks.git] / dlls / shdocvw / shdocvw_main.c
blob9dca61531c11ee2dec928df95cd3eff5227995d0
1 /*
2 * SHDOCVW - Internet Explorer Web Control
4 * Copyright 2001 John R. Sheets (for CodeWeavers)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #define COM_NO_WINDOWS_H
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winreg.h"
30 #include "winuser.h"
31 #include "winnls.h"
32 #include "ole2.h"
33 #include "shlwapi.h"
35 #include "shdocvw.h"
36 #include "uuids.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 #include "initguid.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
45 #define MOZILLA_ACTIVEX_MESSAGE "You need to install the Mozilla ActiveX control to\n" \
46 "use Wine's builtin CLSID_WebBrowser from SHDOCVW.DLL"
48 DEFINE_GUID( CLSID_MozillaBrowser, 0x1339B54C,0x3453,0x11D2,0x93,0xB9,0x00,0x00,0x00,0x00,0x00,0x00);
50 typedef HRESULT (WINAPI *fnGetClassObject)(REFCLSID rclsid, REFIID iid, LPVOID *ppv);
52 HINSTANCE shdocvw_hinstance = 0;
53 static HMODULE SHDOCVW_hshell32 = 0;
54 static HMODULE hMozCtl = (HMODULE)~0UL;
57 /* convert a guid to a wide character string */
58 static void SHDOCVW_guid2wstr( const GUID *guid, LPWSTR wstr )
60 char str[40];
62 sprintf(str, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
63 guid->Data1, guid->Data2, guid->Data3,
64 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
65 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
66 MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
69 static BOOL SHDOCVW_GetMozctlPath( LPWSTR szPath, DWORD sz )
71 DWORD r, type;
72 BOOL ret = FALSE;
73 HKEY hkey;
74 static const WCHAR szPre[] = {
75 'S','o','f','t','w','a','r','e','\\',
76 'C','l','a','s','s','e','s','\\',
77 'C','L','S','I','D','\\',0 };
78 static const WCHAR szPost[] = {
79 '\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0 };
80 WCHAR szRegPath[(sizeof(szPre)+sizeof(szPost))/sizeof(WCHAR)+40];
82 strcpyW( szRegPath, szPre );
83 SHDOCVW_guid2wstr( &CLSID_MozillaBrowser, &szRegPath[strlenW(szRegPath)] );
84 strcatW( szRegPath, szPost );
86 TRACE("key = %s\n", debugstr_w( szRegPath ) );
88 r = RegOpenKeyW( HKEY_LOCAL_MACHINE, szRegPath, &hkey );
89 if( r != ERROR_SUCCESS )
90 return FALSE;
92 r = RegQueryValueExW( hkey, NULL, NULL, &type, (LPBYTE)szPath, &sz );
93 ret = ( r == ERROR_SUCCESS ) && ( type == REG_SZ );
94 RegCloseKey( hkey );
96 return ret;
99 /*************************************************************************
100 * SHDOCVW DllMain
102 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
104 TRACE("%p 0x%lx %p\n", hinst, fdwReason, fImpLoad);
105 switch (fdwReason)
107 case DLL_PROCESS_ATTACH:
108 shdocvw_hinstance = hinst;
109 break;
110 case DLL_PROCESS_DETACH:
111 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
112 if (hMozCtl && hMozCtl != (HMODULE)~0UL) FreeLibrary(hMozCtl);
113 break;
115 return TRUE;
118 /*************************************************************************
119 * DllCanUnloadNow (SHDOCVW.@)
121 HRESULT WINAPI SHDOCVW_DllCanUnloadNow(void)
123 FIXME("(void): stub\n");
125 return S_FALSE;
129 static BOOL SHDOCVW_TryLoadMozillaControl()
131 WCHAR szPath[MAX_PATH];
133 if( hMozCtl != (HMODULE)~0UL )
134 return hMozCtl ? TRUE : FALSE;
136 if( !SHDOCVW_GetMozctlPath( szPath, sizeof szPath ) )
138 MESSAGE(MOZILLA_ACTIVEX_MESSAGE "\n");
139 MessageBoxA(NULL, MOZILLA_ACTIVEX_MESSAGE, "Wine", MB_OK | MB_ICONEXCLAMATION);
140 hMozCtl = 0;
141 return FALSE;
143 hMozCtl = LoadLibraryExW(szPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
144 if( !hMozCtl )
146 ERR("Can't load the Mozilla ActiveX control\n");
147 return FALSE;
149 return TRUE;
152 /*************************************************************************
153 * DllGetClassObject (SHDOCVW.@)
155 HRESULT WINAPI SHDOCVW_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
157 TRACE("\n");
159 if( IsEqualGUID( &CLSID_WebBrowser, rclsid ) &&
160 SHDOCVW_TryLoadMozillaControl() )
162 HRESULT r;
163 fnGetClassObject pGetClassObject;
165 TRACE("WebBrowser class %s\n", debugstr_guid(rclsid) );
167 pGetClassObject = (fnGetClassObject)
168 GetProcAddress( hMozCtl, "DllGetClassObject" );
170 if( !pGetClassObject )
171 return CLASS_E_CLASSNOTAVAILABLE;
172 r = pGetClassObject( &CLSID_MozillaBrowser, riid, ppv );
174 TRACE("r = %08lx *ppv = %p\n", r, *ppv );
176 return r;
179 if (IsEqualGUID(&IID_IClassFactory, riid))
181 /* Pass back our shdocvw class factory */
182 *ppv = (LPVOID)&SHDOCVW_ClassFactory;
183 IClassFactory_AddRef((IClassFactory*)&SHDOCVW_ClassFactory);
185 return S_OK;
188 return CLASS_E_CLASSNOTAVAILABLE;
191 /***********************************************************************
192 * DllGetVersion (SHDOCVW.@)
194 HRESULT WINAPI SHDOCVW_DllGetVersion (DLLVERSIONINFO *info)
196 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
198 /* this is what IE6 on Windows 98 reports */
199 info->dwMajorVersion = 6;
200 info->dwMinorVersion = 0;
201 info->dwBuildNumber = 2600;
202 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
204 return NOERROR;
207 /*************************************************************************
208 * DllInstall (SHDOCVW.@)
210 HRESULT WINAPI SHDOCVW_DllInstall(BOOL bInstall, LPCWSTR cmdline)
212 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
214 return S_OK;
217 /*************************************************************************
218 * SHDOCVW_LoadShell32
220 * makes sure the handle to shell32 is valid
222 BOOL SHDOCVW_LoadShell32(void)
224 if (SHDOCVW_hshell32)
225 return TRUE;
226 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
229 /***********************************************************************
230 * @ (SHDOCVW.110)
232 * Called by Win98 explorer.exe main binary, definitely has 0
233 * parameters.
235 DWORD WINAPI WinList_Init(void)
237 FIXME("(), stub!\n");
238 return 0x0deadfeed;
241 /***********************************************************************
242 * @ (SHDOCVW.118)
244 * Called by Win98 explorer.exe main binary, definitely has only one
245 * parameter.
247 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
249 BOOL WINAPI ShellDDEInit(BOOL start)
251 TRACE("(%d)\n", start);
253 if (!pShellDDEInit)
255 if (!SHDOCVW_LoadShell32())
256 return FALSE;
257 pShellDDEInit = GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
260 if (pShellDDEInit)
261 return pShellDDEInit(start);
262 else
263 return FALSE;
266 /***********************************************************************
267 * @ (SHDOCVW.125)
269 * Called by Win98 explorer.exe main binary, definitely has 0
270 * parameters.
272 DWORD WINAPI RunInstallUninstallStubs(void)
274 FIXME("(), stub!\n");
275 return 0x0deadbee;