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
36 /* undef the #define in msxml2 so that we can access the v.2 version
37 independent CLSID as well as the v.3 one. */
38 #undef CLSID_DOMDocument
40 #include "wine/debug.h"
42 #include "msxml_private.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
46 typedef HRESULT (*ClassFactoryCreateInstanceFunc)(IUnknown *pUnkOuter, LPVOID *ppObj);
47 typedef HRESULT (*DOMFactoryCreateInstanceFunc)(const GUID *clsid, IUnknown *pUnkOuter, LPVOID *ppObj);
49 /******************************************************************************
54 const struct IClassFactoryVtbl *lpVtbl;
55 ClassFactoryCreateInstanceFunc pCreateInstance;
60 const struct IClassFactoryVtbl *lpVtbl;
62 DOMFactoryCreateInstanceFunc pCreateInstance;
66 static HRESULT WINAPI ClassFactory_QueryInterface(
71 if (IsEqualGUID(riid, &IID_IUnknown) ||
72 IsEqualGUID(riid, &IID_IClassFactory))
74 IClassFactory_AddRef( iface );
79 FIXME("interface %s not implemented\n", debugstr_guid(riid));
83 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface )
88 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface )
93 static HRESULT WINAPI ClassFactory_CreateInstance(
99 ClassFactory *This = (ClassFactory*)iface;
103 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
108 return CLASS_E_NOAGGREGATION;
110 r = This->pCreateInstance( pOuter, (void**) &punk );
114 r = IUnknown_QueryInterface( punk, riid, ppobj );
115 IUnknown_Release( punk );
119 static HRESULT WINAPI ClassFactory_LockServer(
120 IClassFactory *iface,
123 FIXME("(%p)->(%d),stub!\n",iface,dolock);
127 static ULONG WINAPI DOMClassFactory_AddRef(IClassFactory *iface )
129 DOMFactory *This = (DOMFactory*)iface;
130 ULONG ref = InterlockedIncrement(&This->ref);
131 TRACE("(%p) ref = %u\n", This, ref);
135 static ULONG WINAPI DOMClassFactory_Release(IClassFactory *iface )
137 DOMFactory *This = (DOMFactory*)iface;
138 ULONG ref = InterlockedDecrement(&This->ref);
139 TRACE("(%p) ref = %u\n", This, ref);
146 static HRESULT WINAPI DOMClassFactory_CreateInstance(
147 IClassFactory *iface,
152 DOMFactory *This = (DOMFactory*)iface;
156 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
161 return CLASS_E_NOAGGREGATION;
163 r = This->pCreateInstance( &This->clsid, pOuter, (void**) &punk );
167 r = IUnknown_QueryInterface( punk, riid, ppobj );
168 IUnknown_Release( punk );
172 static const struct IClassFactoryVtbl ClassFactoryVtbl =
174 ClassFactory_QueryInterface,
176 ClassFactory_Release,
177 ClassFactory_CreateInstance,
178 ClassFactory_LockServer
181 static const struct IClassFactoryVtbl DOMClassFactoryVtbl =
183 ClassFactory_QueryInterface,
184 DOMClassFactory_AddRef,
185 DOMClassFactory_Release,
186 DOMClassFactory_CreateInstance,
187 ClassFactory_LockServer
190 static HRESULT DOMClassFactory_Create(const GUID *clsid, REFIID riid, void **ppv, DOMFactoryCreateInstanceFunc fnCreateInstance)
192 DOMFactory *ret = heap_alloc(sizeof(DOMFactory));
195 ret->lpVtbl = &DOMClassFactoryVtbl;
198 ret->pCreateInstance = fnCreateInstance;
200 hres = IClassFactory_QueryInterface((IClassFactory*)ret, riid, ppv);
208 static ClassFactory schemacf = { &ClassFactoryVtbl, SchemaCache_create };
209 static ClassFactory xmldoccf = { &ClassFactoryVtbl, XMLDocument_create };
210 static ClassFactory saxreadcf = { &ClassFactoryVtbl, SAXXMLReader_create };
211 static ClassFactory httpreqcf = { &ClassFactoryVtbl, XMLHTTPRequest_create };
213 /******************************************************************
214 * DllGetClassObject (MSXML3.@)
216 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, void **ppv )
218 IClassFactory *cf = NULL;
220 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv );
222 if( IsEqualCLSID( rclsid, &CLSID_DOMDocument ) || /* Version indep. v 2.x */
223 IsEqualCLSID( rclsid, &CLSID_DOMDocument2 ) || /* Version indep. v 3.0 */
224 IsEqualCLSID( rclsid, &CLSID_DOMDocument30 )|| /* Version dep. v 3.0 */
225 IsEqualCLSID( rclsid, &CLSID_DOMDocument40 )|| /* Version dep. v 4.0 */
226 IsEqualCLSID( rclsid, &CLSID_DOMDocument60 )) /* Version dep. v 6.0 */
228 return DOMClassFactory_Create(rclsid, riid, ppv, DOMDocument_create);
230 else if( IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache ) ||
231 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache30 ) ||
232 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache40 ) ||
233 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache60 ))
235 cf = (IClassFactory*) &schemacf.lpVtbl;
237 else if( IsEqualCLSID( rclsid, &CLSID_XMLDocument ) )
239 cf = (IClassFactory*) &xmldoccf.lpVtbl;
241 else if( IsEqualCLSID( rclsid, &CLSID_DOMFreeThreadedDocument ) || /* Version indep. v 2.x */
242 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument ) ||
243 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument30 ) ||
244 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument40 ) ||
245 IsEqualCLSID( rclsid, &CLSID_FreeThreadedDOMDocument60 ))
247 return DOMClassFactory_Create(rclsid, riid, ppv, DOMDocument_create);
249 else if( IsEqualCLSID( rclsid, &CLSID_SAXXMLReader) ||
250 IsEqualCLSID( rclsid, &CLSID_SAXXMLReader30 ) ||
251 IsEqualCLSID( rclsid, &CLSID_SAXXMLReader40 ) ||
252 IsEqualCLSID( rclsid, &CLSID_SAXXMLReader60 ))
254 cf = (IClassFactory*) &saxreadcf.lpVtbl;
256 else if( IsEqualCLSID( rclsid, &CLSID_XMLHTTPRequest ) ||
257 IsEqualCLSID( rclsid, &CLSID_XMLHTTP26 ) ||
258 IsEqualCLSID( rclsid, &CLSID_XMLHTTP30 ) ||
259 IsEqualCLSID( rclsid, &CLSID_XMLHTTP40 ) ||
260 IsEqualCLSID( rclsid, &CLSID_XMLHTTP60 ))
262 cf = (IClassFactory*) &httpreqcf.lpVtbl;
266 return CLASS_E_CLASSNOTAVAILABLE;
268 return IClassFactory_QueryInterface( cf, riid, ppv );