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
38 #include "mshtml_private.h"
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
47 DEFINE_GUID( CLSID_MozillaBrowser, 0x1339B54C,0x3453,0x11D2,0x93,0xB9,0x00,0x00,0x00,0x00,0x00,0x00);
49 typedef HRESULT (WINAPI *fnGetClassObject)(REFCLSID rclsid, REFIID iid, LPVOID *ppv);
50 typedef BOOL (WINAPI *fnCanUnloadNow)();
52 static HMODULE hMozCtl;
55 /* convert a guid to a wide character string */
56 static void MSHTML_guid2wstr( const GUID *guid, LPWSTR wstr )
60 sprintf(str, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
61 guid->Data1, guid->Data2, guid->Data3,
62 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
63 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
64 MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
67 static BOOL MSHTML_GetMozctlPath( LPWSTR szPath, DWORD sz )
72 static const WCHAR szPre[] = {
73 'S','o','f','t','w','a','r','e','\\',
74 'C','l','a','s','s','e','s','\\',
75 'C','L','S','I','D','\\',0 };
76 static const WCHAR szPost[] = {
77 '\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0 };
78 WCHAR szRegPath[(sizeof(szPre)+sizeof(szPost))/sizeof(WCHAR)+40];
80 strcpyW( szRegPath, szPre );
81 MSHTML_guid2wstr( &CLSID_MozillaBrowser, &szRegPath[strlenW(szRegPath)] );
82 strcatW( szRegPath, szPost );
84 TRACE("key = %s\n", debugstr_w( szRegPath ) );
86 r = RegOpenKeyW( HKEY_LOCAL_MACHINE, szRegPath, &hkey );
87 if( r != ERROR_SUCCESS )
90 r = RegQueryValueExW( hkey, NULL, NULL, &type, (LPBYTE)szPath, &sz );
91 ret = ( r == ERROR_SUCCESS ) && ( type == REG_SZ );
97 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
99 WCHAR szPath[MAX_PATH];
102 case DLL_PROCESS_ATTACH:
103 if(MSHTML_GetMozctlPath(szPath, sizeof szPath)) {
104 hMozCtl = LoadLibraryExW(szPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
106 ERR("Can't load the Mozilla ActiveX control\n");
108 MESSAGE("You need to install the Mozilla ActiveX control to\n");
109 MESSAGE("use Wine's builtin MSHTML dll.\n");
112 case DLL_PROCESS_DETACH:
114 FreeLibrary( hMozCtl );
120 /***********************************************************
121 * ClassFactory implementation
123 typedef HRESULT (*CreateInstanceFunc)(IUnknown*,REFIID,void**);
125 const IClassFactoryVtbl *lpVtbl;
127 CreateInstanceFunc fnCreateInstance;
130 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFGUID riid, void **ppvObject)
132 if(IsEqualGUID(&IID_IClassFactory, riid) || IsEqualGUID(&IID_IUnknown, riid)) {
133 IClassFactory_AddRef(iface);
138 WARN("not supported iid %s\n", debugstr_guid(riid));
140 return E_NOINTERFACE;
143 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
145 ClassFactory *This = (ClassFactory*)iface;
146 ULONG ref = InterlockedIncrement(&This->ref);
147 TRACE("(%p) ref = %lu\n", This, ref);
151 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
153 ClassFactory *This = (ClassFactory*)iface;
154 ULONG ref = InterlockedDecrement(&This->ref);
156 TRACE("(%p) ref = %lu\n", This, ref);
159 HeapFree(GetProcessHeap(), 0, This);
164 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
165 REFIID riid, void **ppvObject)
167 ClassFactory *This = (ClassFactory*)iface;
168 return This->fnCreateInstance(pUnkOuter, riid, ppvObject);
171 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
173 FIXME("(%p)->(%x) stub\n", iface, dolock);
177 static const IClassFactoryVtbl HTMLClassFactoryVtbl = {
178 ClassFactory_QueryInterface,
180 ClassFactory_Release,
181 ClassFactory_CreateInstance,
182 ClassFactory_LockServer
185 static HRESULT ClassFactory_Create(REFIID riid, void **ppv, CreateInstanceFunc fnCreateInstance)
187 ClassFactory *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ClassFactory));
190 ret->lpVtbl = &HTMLClassFactoryVtbl;
192 ret->fnCreateInstance = fnCreateInstance;
194 hres = IClassFactory_QueryInterface((IClassFactory*)ret, riid, ppv);
196 HeapFree(GetProcessHeap(), 0, ret);
202 HRESULT WINAPI MSHTML_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
205 fnGetClassObject pGetClassObject;
207 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv );
209 if(hMozCtl && IsEqualGUID(&CLSID_HTMLDocument, rclsid)) {
210 pGetClassObject = (fnGetClassObject) GetProcAddress(hMozCtl, "DllGetClassObject");
211 if(pGetClassObject) {
212 hres = pGetClassObject(&CLSID_MozillaBrowser, riid, ppv);
213 if(SUCCEEDED(hres)) {
214 TRACE("returning Mozilla ActiveX Control hres = %08lx *ppv = %p\n", hres, *ppv);
220 if(IsEqualGUID(&CLSID_HTMLDocument, rclsid)) {
221 hres = ClassFactory_Create(riid, ppv, HTMLDocument_Create);
222 TRACE("hres = %08lx\n", hres);
226 FIXME("Unknown class %s\n", debugstr_guid(rclsid));
227 return CLASS_E_CLASSNOTAVAILABLE;
230 HRESULT WINAPI MSHTML_DllCanUnloadNow(void)
232 fnCanUnloadNow pCanUnloadNow = NULL;
238 pCanUnloadNow = (fnCanUnloadNow) GetProcAddress(hMozCtl, "DllCanUnloadNow");
242 hres = pCanUnloadNow();
244 TRACE("hres = %08lx\n", hres);
249 /* appears to have the same prototype as WinMain */
250 INT WINAPI RunHTMLApplication( HINSTANCE hinst, HINSTANCE hPrevInst,
251 LPCSTR szCmdLine, INT nCmdShow )
253 FIXME("%p %p %s %d\n", hinst, hPrevInst, debugstr_a(szCmdLine), nCmdShow );
257 /***********************************************************************
258 * DllInstall (MSHTML.@)
260 HRESULT WINAPI MSHTML_DllInstall(BOOL bInstall, LPCWSTR cmdline)
262 FIXME("stub %d %s: returning S_OK\n", bInstall, debugstr_w(cmdline));
266 /***********************************************************************
267 * DllRegisterServer (MSHTML.@)
269 HRESULT WINAPI MSHTML_DllRegisterServer(void)
271 FIXME("stub: returning S_OK\n");