4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2005 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 /* undef the #define in msxml2 so that we can access the v.2 version
36 independent CLSID as well as the v.3 one. */
37 #undef CLSID_DOMDocument
39 #include "wine/debug.h"
41 #include "msxml_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
45 typedef HRESULT (*ClassFactoryCreateInstanceFunc)(IUnknown *pUnkOuter, LPVOID *ppObj);
46 typedef HRESULT (*DOMFactoryCreateInstanceFunc)(const GUID *clsid, IUnknown *pUnkOuter, LPVOID *ppObj);
48 /******************************************************************************
53 const struct IClassFactoryVtbl *lpVtbl;
54 ClassFactoryCreateInstanceFunc pCreateInstance;
59 const struct IClassFactoryVtbl *lpVtbl;
61 DOMFactoryCreateInstanceFunc pCreateInstance;
65 static HRESULT WINAPI ClassFactory_QueryInterface(
70 if (IsEqualGUID(riid, &IID_IUnknown) ||
71 IsEqualGUID(riid, &IID_IClassFactory))
73 IClassFactory_AddRef( iface );
78 FIXME("interface %s not implemented\n", debugstr_guid(riid));
82 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface )
87 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface )
92 static HRESULT WINAPI ClassFactory_CreateInstance(
98 ClassFactory *This = (ClassFactory*)iface;
102 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
107 return CLASS_E_NOAGGREGATION;
109 r = This->pCreateInstance( pOuter, (void**) &punk );
113 r = IUnknown_QueryInterface( punk, riid, ppobj );
114 IUnknown_Release( punk );
118 static HRESULT WINAPI ClassFactory_LockServer(
119 IClassFactory *iface,
122 FIXME("(%p)->(%d),stub!\n",iface,dolock);
126 static ULONG WINAPI DOMClassFactory_AddRef(IClassFactory *iface )
128 DOMFactory *This = (DOMFactory*)iface;
129 ULONG ref = InterlockedIncrement(&This->ref);
130 TRACE("(%p) ref = %u\n", This, ref);
134 static ULONG WINAPI DOMClassFactory_Release(IClassFactory *iface )
136 DOMFactory *This = (DOMFactory*)iface;
137 ULONG ref = InterlockedDecrement(&This->ref);
138 TRACE("(%p) ref = %u\n", This, ref);
145 static HRESULT WINAPI DOMClassFactory_CreateInstance(
146 IClassFactory *iface,
151 DOMFactory *This = (DOMFactory*)iface;
155 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
160 return CLASS_E_NOAGGREGATION;
162 r = This->pCreateInstance( &This->clsid, pOuter, (void**) &punk );
166 r = IUnknown_QueryInterface( punk, riid, ppobj );
167 IUnknown_Release( punk );
171 static const struct IClassFactoryVtbl ClassFactoryVtbl =
173 ClassFactory_QueryInterface,
175 ClassFactory_Release,
176 ClassFactory_CreateInstance,
177 ClassFactory_LockServer
180 static const struct IClassFactoryVtbl DOMClassFactoryVtbl =
182 ClassFactory_QueryInterface,
183 DOMClassFactory_AddRef,
184 DOMClassFactory_Release,
185 DOMClassFactory_CreateInstance,
186 ClassFactory_LockServer
189 static HRESULT DOMClassFactory_Create(const GUID *clsid, REFIID riid, void **ppv, DOMFactoryCreateInstanceFunc fnCreateInstance)
191 DOMFactory *ret = heap_alloc(sizeof(DOMFactory));
194 ret->lpVtbl = &DOMClassFactoryVtbl;
197 ret->pCreateInstance = fnCreateInstance;
199 hres = IClassFactory_QueryInterface((IClassFactory*)ret, riid, ppv);
207 static ClassFactory schemacf = { &ClassFactoryVtbl, SchemaCache_create };
208 static ClassFactory xmldoccf = { &ClassFactoryVtbl, XMLDocument_create };
209 static ClassFactory saxreadcf = { &ClassFactoryVtbl, SAXXMLReader_create };
210 static ClassFactory httpreqcf = { &ClassFactoryVtbl, XMLHTTPRequest_create };
212 /******************************************************************
213 * DllGetClassObject (MSXML3.@)
215 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, void **ppv )
217 IClassFactory *cf = NULL;
219 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv );
221 if( IsEqualCLSID( rclsid, &CLSID_DOMDocument ) || /* Version indep. v 2.x */
222 IsEqualCLSID( rclsid, &CLSID_DOMDocument2 ) || /* Version indep. v 3.0 */
223 IsEqualCLSID( rclsid, &CLSID_DOMDocument30 )|| /* Version dep. v 3.0 */
224 IsEqualCLSID( rclsid, &CLSID_DOMDocument40 )|| /* Version dep. v 4.0 */
225 IsEqualCLSID( rclsid, &CLSID_DOMDocument60 )) /* Version dep. v 6.0 */
227 return DOMClassFactory_Create(rclsid, riid, ppv, DOMDocument_create);
229 else if( IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache ) ||
230 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache30 ) ||
231 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache40 ) ||
232 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache60 ))
234 cf = (IClassFactory*) &schemacf.lpVtbl;
236 else if( IsEqualCLSID( rclsid, &CLSID_XMLDocument ) )
238 cf = (IClassFactory*) &xmldoccf.lpVtbl;
240 else if( IsEqualCLSID( rclsid, &CLSID_DOMFreeThreadedDocument ) || /* Version indep. v 2.x */
241 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument ) ||
242 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument30 ) ||
243 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument40 ) ||
244 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument60 ))
246 return DOMClassFactory_Create(rclsid, riid, ppv, DOMDocument_create);
248 else if( IsEqualCLSID( rclsid, &CLSID_SAXXMLReader) ||
249 IsEqualCLSID( rclsid, &CLSID_SAXXMLReader30 ) ||
250 IsEqualCLSID( rclsid, &CLSID_SAXXMLReader40 ) ||
251 IsEqualCLSID( rclsid, &CLSID_SAXXMLReader60 ))
253 cf = (IClassFactory*) &saxreadcf.lpVtbl;
255 else if( IsEqualCLSID( rclsid, &CLSID_XMLHTTPRequest ) ||
256 IsEqualCLSID( rclsid, &CLSID_XMLHTTP26 ) ||
257 IsEqualCLSID( rclsid, &CLSID_XMLHTTP30 ) ||
258 IsEqualCLSID( rclsid, &CLSID_XMLHTTP40 ) ||
259 IsEqualCLSID( rclsid, &CLSID_XMLHTTP60 ))
261 cf = (IClassFactory*) &httpreqcf.lpVtbl;
265 return CLASS_E_CLASSNOTAVAILABLE;
267 return IClassFactory_QueryInterface( cf, riid, ppv );