Implement NtAccessCheck.
[wine/gsoc-2012-control.git] / dlls / mshtml / main.c
blobf9b5905f307dcfdd906f2f09ab49339aabdb61a8
1 /*
2 * MSHTML Class Factory
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
23 #include "config.h"
25 #include <stdarg.h>
26 #include <stdio.h>
28 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "winreg.h"
35 #include "ole2.h"
36 #include "docobj.h"
38 #include "mshtml.h"
39 #include "mshtml_private.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
46 #include "initguid.h"
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;
55 HINSTANCE hInst;
57 /* convert a guid to a wide character string */
58 static void MSHTML_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 MSHTML_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 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 )
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 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
101 WCHAR szPath[MAX_PATH];
103 switch(fdwReason) {
104 case DLL_PROCESS_ATTACH:
105 if(MSHTML_GetMozctlPath(szPath, sizeof szPath)) {
106 hMozCtl = LoadLibraryExW(szPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
107 if(!hMozCtl)
108 ERR("Can't load the Mozilla ActiveX control\n");
109 }else {
110 MESSAGE("You need to install the Mozilla ActiveX control to\n");
111 MESSAGE("use Wine's builtin MSHTML dll.\n");
113 hInst = hInstDLL;
114 break;
115 case DLL_PROCESS_DETACH:
116 if(hMozCtl)
117 FreeLibrary( hMozCtl );
118 break;
120 return TRUE;
123 /***********************************************************
124 * ClassFactory implementation
126 typedef HRESULT (*CreateInstanceFunc)(IUnknown*,REFIID,void**);
127 typedef struct {
128 const IClassFactoryVtbl *lpVtbl;
129 ULONG ref;
130 CreateInstanceFunc fnCreateInstance;
131 } ClassFactory;
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);
137 *ppvObject = iface;
138 return S_OK;
141 WARN("not supported iid %s\n", debugstr_guid(riid));
142 *ppvObject = NULL;
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);
151 return 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);
161 if(!ref)
162 HeapFree(GetProcessHeap(), 0, This);
164 return ref;
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);
177 return S_OK;
180 static const IClassFactoryVtbl HTMLClassFactoryVtbl = {
181 ClassFactory_QueryInterface,
182 ClassFactory_AddRef,
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));
191 HRESULT hres;
193 ret->lpVtbl = &HTMLClassFactoryVtbl;
194 ret->ref = 0;
195 ret->fnCreateInstance = fnCreateInstance;
197 hres = IClassFactory_QueryInterface((IClassFactory*)ret, riid, ppv);
198 if(FAILED(hres)) {
199 HeapFree(GetProcessHeap(), 0, ret);
200 *ppv = NULL;
202 return hres;
205 HRESULT WINAPI MSHTML_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
207 HRESULT hres;
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);
218 return hres;
223 if(IsEqualGUID(&CLSID_HTMLDocument, rclsid)) {
224 hres = ClassFactory_Create(riid, ppv, HTMLDocument_Create);
225 TRACE("hres = %08lx\n", hres);
226 return 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;
236 HRESULT hres;
238 TRACE("()\n");
240 if(hMozCtl)
241 pCanUnloadNow = (fnCanUnloadNow) GetProcAddress(hMozCtl, "DllCanUnloadNow");
242 if(!pCanUnloadNow)
243 return S_FALSE;
245 hres = pCanUnloadNow();
247 TRACE("hres = %08lx\n", hres);
249 return 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 );
261 return 0;
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));
270 return S_OK;
273 /***********************************************************************
274 * DllRegisterServer (MSHTML.@)
276 HRESULT WINAPI MSHTML_DllRegisterServer(void)
278 FIXME("stub: returning S_OK\n");
279 return S_OK;