4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2003 Mike McCormack
6 * Copyright 2005 Jacek Caban
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 #include "mshtml_private.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
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);
51 typedef BOOL (WINAPI *fnCanUnloadNow)();
53 static HMODULE hMozCtl;
57 /* convert a guid to a wide character string */
58 static void MSHTML_guid2wstr( const GUID *guid, LPWSTR wstr )
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 MSHTML_GetMozctlPath( LPWSTR szPath, DWORD sz )
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 MSHTML_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 )
92 r = RegQueryValueExW( hkey, NULL, NULL, &type, (LPBYTE)szPath, &sz );
93 ret = ( r == ERROR_SUCCESS ) && ( type == REG_SZ );
99 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
101 WCHAR szPath[MAX_PATH];
104 case DLL_PROCESS_ATTACH:
105 if(MSHTML_GetMozctlPath(szPath, sizeof szPath)) {
106 hMozCtl = LoadLibraryExW(szPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
108 ERR("Can't load the Mozilla ActiveX control\n");
110 MESSAGE("You need to install the Mozilla ActiveX control to\n");
111 MESSAGE("use Wine's builtin MSHTML dll.\n");
115 case DLL_PROCESS_DETACH:
117 FreeLibrary( hMozCtl );
123 /***********************************************************
124 * ClassFactory implementation
126 typedef HRESULT (*CreateInstanceFunc)(IUnknown*,REFIID,void**);
128 const IClassFactoryVtbl *lpVtbl;
130 CreateInstanceFunc fnCreateInstance;
133 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFGUID riid, void **ppvObject)
135 if(IsEqualGUID(&IID_IClassFactory, riid) || IsEqualGUID(&IID_IUnknown, riid)) {
136 IClassFactory_AddRef(iface);
141 WARN("not supported iid %s\n", debugstr_guid(riid));
143 return E_NOINTERFACE;
146 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
148 ClassFactory *This = (ClassFactory*)iface;
149 ULONG ref = InterlockedIncrement(&This->ref);
150 TRACE("(%p) ref = %lu\n", This, ref);
154 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
156 ClassFactory *This = (ClassFactory*)iface;
157 ULONG ref = InterlockedDecrement(&This->ref);
159 TRACE("(%p) ref = %lu\n", This, ref);
162 HeapFree(GetProcessHeap(), 0, This);
167 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
168 REFIID riid, void **ppvObject)
170 ClassFactory *This = (ClassFactory*)iface;
171 return This->fnCreateInstance(pUnkOuter, riid, ppvObject);
174 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
176 FIXME("(%p)->(%x) stub\n", iface, dolock);
180 static const IClassFactoryVtbl HTMLClassFactoryVtbl = {
181 ClassFactory_QueryInterface,
183 ClassFactory_Release,
184 ClassFactory_CreateInstance,
185 ClassFactory_LockServer
188 static HRESULT ClassFactory_Create(REFIID riid, void **ppv, CreateInstanceFunc fnCreateInstance)
190 ClassFactory *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ClassFactory));
193 ret->lpVtbl = &HTMLClassFactoryVtbl;
195 ret->fnCreateInstance = fnCreateInstance;
197 hres = IClassFactory_QueryInterface((IClassFactory*)ret, riid, ppv);
199 HeapFree(GetProcessHeap(), 0, ret);
205 HRESULT WINAPI MSHTML_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
208 fnGetClassObject pGetClassObject;
210 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv );
212 if(hMozCtl && IsEqualGUID(&CLSID_HTMLDocument, rclsid)) {
213 pGetClassObject = (fnGetClassObject) GetProcAddress(hMozCtl, "DllGetClassObject");
214 if(pGetClassObject) {
215 hres = pGetClassObject(&CLSID_MozillaBrowser, riid, ppv);
216 if(SUCCEEDED(hres)) {
217 TRACE("returning Mozilla ActiveX Control hres = %08lx *ppv = %p\n", hres, *ppv);
223 if(IsEqualGUID(&CLSID_HTMLDocument, rclsid)) {
224 hres = ClassFactory_Create(riid, ppv, HTMLDocument_Create);
225 TRACE("hres = %08lx\n", hres);
229 FIXME("Unknown class %s\n", debugstr_guid(rclsid));
230 return CLASS_E_CLASSNOTAVAILABLE;
233 HRESULT WINAPI MSHTML_DllCanUnloadNow(void)
235 fnCanUnloadNow pCanUnloadNow = NULL;
241 pCanUnloadNow = (fnCanUnloadNow) GetProcAddress(hMozCtl, "DllCanUnloadNow");
245 hres = pCanUnloadNow();
247 TRACE("hres = %08lx\n", hres);
252 /***********************************************************************
253 * RunHTMLApplication (MSHTML.@)
255 * Appears to have the same prototype as WinMain.
257 INT WINAPI RunHTMLApplication( HINSTANCE hinst, HINSTANCE hPrevInst,
258 LPCSTR szCmdLine, INT nCmdShow )
260 FIXME("%p %p %s %d\n", hinst, hPrevInst, debugstr_a(szCmdLine), nCmdShow );
264 /***********************************************************************
265 * DllInstall (MSHTML.@)
267 HRESULT WINAPI MSHTML_DllInstall(BOOL bInstall, LPCWSTR cmdline)
269 FIXME("stub %d %s: returning S_OK\n", bInstall, debugstr_w(cmdline));
273 /***********************************************************************
274 * DllRegisterServer (MSHTML.@)
276 HRESULT WINAPI MSHTML_DllRegisterServer(void)
278 FIXME("stub: returning S_OK\n");