Don't mistake frames for bytes.
[wine/multimedia.git] / dlls / mshtml / main.c
blob3405ec29bfd2caa487ea0ba4c8b294996cda1a5e
1 /*
2 * MSHTML Class Factory
4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2003 Mike McCormack
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
24 #include <stdarg.h>
25 #include <stdio.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "winreg.h"
32 #include "ole2.h"
34 #include "mshtml.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 #include "initguid.h"
43 DEFINE_GUID( CLSID_MozillaBrowser, 0x1339B54C,0x3453,0x11D2,0x93,0xB9,0x00,0x00,0x00,0x00,0x00,0x00);
45 typedef HRESULT (WINAPI *fnGetClassObject)(REFCLSID rclsid, REFIID iid, LPVOID *ppv);
46 typedef BOOL (WINAPI *fnCanUnloadNow)();
48 HMODULE hMozCtl;
51 /* convert a guid to a wide character string */
52 static void MSHTML_guid2wstr( const GUID *guid, LPWSTR wstr )
54 char str[40];
56 sprintf(str, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
57 guid->Data1, guid->Data2, guid->Data3,
58 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
59 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
60 MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
63 static BOOL MSHTML_GetMozctlPath( LPWSTR szPath, DWORD sz )
65 DWORD r, type;
66 BOOL ret = FALSE;
67 HKEY hkey;
68 static const WCHAR szPre[] = {
69 'S','o','f','t','w','a','r','e','\\',
70 'C','l','a','s','s','e','s','\\',
71 'C','L','S','I','D','\\',0 };
72 static const WCHAR szPost[] = {
73 '\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0 };
74 WCHAR szRegPath[(sizeof(szPre)+sizeof(szPost))/sizeof(WCHAR)+40];
76 strcpyW( szRegPath, szPre );
77 MSHTML_guid2wstr( &CLSID_MozillaBrowser, &szRegPath[strlenW(szRegPath)] );
78 strcatW( szRegPath, szPost );
80 TRACE("key = %s\n", debugstr_w( szRegPath ) );
82 r = RegOpenKeyW( HKEY_LOCAL_MACHINE, szRegPath, &hkey );
83 if( r != ERROR_SUCCESS )
84 return FALSE;
86 r = RegQueryValueExW( hkey, NULL, NULL, &type, (LPBYTE)szPath, &sz );
87 ret = ( r == ERROR_SUCCESS ) && ( type == REG_SZ );
88 RegCloseKey( hkey );
90 return ret;
93 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
95 WCHAR szPath[MAX_PATH];
97 switch(fdwReason) {
98 case DLL_PROCESS_ATTACH:
99 if( !MSHTML_GetMozctlPath( szPath, sizeof szPath ) )
101 MESSAGE("You need to install the Mozilla ActiveX control to\n");
102 MESSAGE("use Wine's builtin MSHTML dll.\n");
103 return FALSE;
105 hMozCtl = LoadLibraryExW(szPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
106 if( !hMozCtl )
108 ERR("Can't load the Mozilla ActiveX control\n");
109 return FALSE;
111 break;
112 case DLL_PROCESS_DETACH:
113 FreeLibrary( hMozCtl );
114 break;
116 return TRUE;
119 HRESULT WINAPI MSHTML_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
121 HRESULT r;
122 fnGetClassObject pGetClassObject;
124 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv );
126 if( !IsEqualGUID( &CLSID_HTMLDocument, rclsid ) )
127 WARN("Unknown class %s\n", debugstr_guid(rclsid) );
129 pGetClassObject = (fnGetClassObject) GetProcAddress( hMozCtl, "DllGetClassObject" );
130 if( !pGetClassObject )
131 return CLASS_E_CLASSNOTAVAILABLE;
132 r = pGetClassObject( &CLSID_MozillaBrowser, iid, ppv );
134 TRACE("r = %08lx *ppv = %p\n", r, *ppv );
136 return S_OK;
139 BOOL WINAPI MSHTML_DllCanUnloadNow(void)
141 fnCanUnloadNow pCanUnloadNow;
142 BOOL r;
144 TRACE("\n");
146 pCanUnloadNow = (fnCanUnloadNow) GetProcAddress( hMozCtl, "DllCanUnloadNow" );
147 if( !pCanUnloadNow )
148 return FALSE;
149 r = pCanUnloadNow();
151 TRACE("r = %d\n", r);
153 return r;
156 /* appears to have the same prototype as WinMain */
157 INT WINAPI RunHTMLApplication( HINSTANCE hinst, HINSTANCE hPrevInst,
158 LPCSTR szCmdLine, INT nCmdShow )
160 FIXME("%p %p %s %d\n", hinst, hPrevInst, debugstr_a(szCmdLine), nCmdShow );
161 return 0;
164 /***********************************************************************
165 * DllInstall (MSHTML.@)
167 HRESULT WINAPI MSHTML_DllInstall(BOOL bInstall, LPCWSTR cmdline)
169 FIXME("stub %d %s: returning S_OK\n", bInstall, debugstr_w(cmdline));
170 return S_OK;
173 /***********************************************************************
174 * DllRegisterServer (MSHTML.@)
176 HRESULT WINAPI MSHTML_DllRegisterServer(void)
178 FIXME("stub: returning S_OK\n");
179 return S_OK;