Fix the case of product and company names.
[wine] / dlls / mshtml / main.c
1 /*
2  *    MSHTML Class Factory
3  *
4  * Copyright 2002 Lionel Ulmer
5  * Copyright 2003 Mike McCormack
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29
30 #include "uuids.h"
31
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35
36 extern HRESULT HTMLDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj);
37
38 /* For the moment, do nothing here. */
39 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
40 {
41     switch(fdwReason) {
42         case DLL_PROCESS_ATTACH:
43             DisableThreadLibraryCalls(hInstDLL);
44             break;
45         case DLL_PROCESS_DETACH:
46             break;
47     }
48     return TRUE;
49 }
50
51 /******************************************************************************
52  * MSHTML ClassFactory
53  */
54 typedef struct {
55     IClassFactory ITF_IClassFactory;
56
57     DWORD ref;
58     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
59 } IClassFactoryImpl;
60
61 struct object_creation_info
62 {
63     const CLSID *clsid;
64     LPCSTR szClassName;
65     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
66 };
67
68 static const struct object_creation_info object_creation[] =
69 {
70     { &CLSID_HTMLDocument, "HTMLDocument", HTMLDocument_create },
71 };
72
73 static HRESULT WINAPI
74 HTMLCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
75 {
76     ICOM_THIS(IClassFactoryImpl,iface);
77
78     if (IsEqualGUID(riid, &IID_IUnknown)
79         || IsEqualGUID(riid, &IID_IClassFactory))
80     {
81         IClassFactory_AddRef(iface);
82         *ppobj = This;
83         return S_OK;
84     }
85
86     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
87     return E_NOINTERFACE;
88 }
89
90 static ULONG WINAPI HTMLCF_AddRef(LPCLASSFACTORY iface) {
91     ICOM_THIS(IClassFactoryImpl,iface);
92     return ++(This->ref);
93 }
94
95 static ULONG WINAPI HTMLCF_Release(LPCLASSFACTORY iface) {
96     ICOM_THIS(IClassFactoryImpl,iface);
97
98     ULONG ref = --This->ref;
99
100     if (ref == 0)
101         HeapFree(GetProcessHeap(), 0, This);
102
103     return ref;
104 }
105
106
107 static HRESULT WINAPI HTMLCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
108                                           REFIID riid, LPVOID *ppobj) {
109     ICOM_THIS(IClassFactoryImpl,iface);
110     HRESULT hres;
111     LPUNKNOWN punk;
112     
113     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
114
115     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
116     if (FAILED(hres)) {
117         *ppobj = NULL;
118         return hres;
119     }
120     hres = IUnknown_QueryInterface(punk, riid, ppobj);
121     if (FAILED(hres)) {
122         *ppobj = NULL;
123         return hres;
124     }
125     IUnknown_Release(punk);
126     return hres;
127 }
128
129 static HRESULT WINAPI HTMLCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
130     ICOM_THIS(IClassFactoryImpl,iface);
131     FIXME("(%p)->(%d),stub!\n",This,dolock);
132     return S_OK;
133 }
134
135 static ICOM_VTABLE(IClassFactory) HTMLCF_Vtbl =
136 {
137     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
138     HTMLCF_QueryInterface,
139     HTMLCF_AddRef,
140     HTMLCF_Release,
141     HTMLCF_CreateInstance,
142     HTMLCF_LockServer
143 };
144
145
146 HRESULT WINAPI MSHTML_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
147 {
148     int i;
149     IClassFactoryImpl *factory;
150
151     TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
152     
153     if ( !IsEqualGUID( &IID_IClassFactory, iid )
154          && ! IsEqualGUID( &IID_IUnknown, iid) )
155         return E_NOINTERFACE;
156
157     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
158     {
159         if (IsEqualGUID(object_creation[i].clsid, rclsid))
160             break;
161     }
162
163     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
164     {
165         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
166         return CLASS_E_CLASSNOTAVAILABLE;
167     }
168
169     TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
170
171     factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
172     if (factory == NULL) return E_OUTOFMEMORY;
173
174     factory->ITF_IClassFactory.lpVtbl = &HTMLCF_Vtbl;
175     factory->ref = 1;
176
177     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
178
179     *ppv = &(factory->ITF_IClassFactory);
180
181     TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
182
183     return S_OK;
184 }
185
186 HRESULT WINAPI MSHTML_DllCanUnloadNow(void)
187 {
188     FIXME("\n");
189     return S_FALSE;
190 }
191
192 /* appears to have the same prototype as WinMain */
193 INT WINAPI RunHTMLApplication( HINSTANCE hinst, HINSTANCE hPrevInst,
194                                LPCSTR szCmdLine, INT nCmdShow )
195 {
196     FIXME("%p %p %s %d\n", hinst, hPrevInst, debugstr_a(szCmdLine), nCmdShow );
197     return 0;
198 }