appwiz.cpl: Added support for installing packages from MSI files.
[wine/multimedia.git] / dlls / msxml3 / factory.c
blob6fbf464e3dc4e69efe665b02e7ded1d8f0723c22
1 /*
2 * MSXML Class Factory
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
22 #define COBJMACROS
24 #include "config.h"
26 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "ole2.h"
31 #include "msxml.h"
32 #include "msxml2.h"
34 /* undef the #define in msxml2 so that we can access the v.2 version
35 independent CLSID as well as the v.3 one. */
36 #undef CLSID_DOMDocument
38 #include "wine/debug.h"
40 #include "msxml_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
44 typedef HRESULT (*ClassFactoryCreateInstanceFunc)(IUnknown *pUnkOuter, LPVOID *ppObj);
45 typedef HRESULT (*DOMFactoryCreateInstanceFunc)(const GUID *clsid, IUnknown *pUnkOuter, LPVOID *ppObj);
47 /******************************************************************************
48 * MSXML ClassFactory
50 typedef struct
52 const struct IClassFactoryVtbl *lpVtbl;
53 ClassFactoryCreateInstanceFunc pCreateInstance;
54 } ClassFactory;
56 typedef struct
58 const struct IClassFactoryVtbl *lpVtbl;
59 LONG ref;
60 DOMFactoryCreateInstanceFunc pCreateInstance;
61 GUID clsid;
62 } DOMFactory;
64 static HRESULT WINAPI ClassFactory_QueryInterface(
65 IClassFactory *iface,
66 REFIID riid,
67 void **ppobj )
69 if (IsEqualGUID(riid, &IID_IUnknown) ||
70 IsEqualGUID(riid, &IID_IClassFactory))
72 IClassFactory_AddRef( iface );
73 *ppobj = iface;
74 return S_OK;
77 FIXME("interface %s not implemented\n", debugstr_guid(riid));
78 return E_NOINTERFACE;
81 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface )
83 return 2;
86 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface )
88 return 1;
91 static HRESULT WINAPI ClassFactory_CreateInstance(
92 IClassFactory *iface,
93 IUnknown *pOuter,
94 REFIID riid,
95 void **ppobj )
97 ClassFactory *This = (ClassFactory*)iface;
98 IUnknown *punk;
99 HRESULT r;
101 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
103 *ppobj = NULL;
105 if (pOuter)
106 return CLASS_E_NOAGGREGATION;
108 r = This->pCreateInstance( pOuter, (void**) &punk );
109 if (FAILED(r))
110 return r;
112 r = IUnknown_QueryInterface( punk, riid, ppobj );
113 IUnknown_Release( punk );
114 return r;
117 static HRESULT WINAPI ClassFactory_LockServer(
118 IClassFactory *iface,
119 BOOL dolock)
121 FIXME("(%p)->(%d),stub!\n",iface,dolock);
122 return S_OK;
125 static ULONG WINAPI DOMClassFactory_AddRef(IClassFactory *iface )
127 DOMFactory *This = (DOMFactory*)iface;
128 ULONG ref = InterlockedIncrement(&This->ref);
129 TRACE("(%p) ref = %u\n", This, ref);
130 return ref;
133 static ULONG WINAPI DOMClassFactory_Release(IClassFactory *iface )
135 DOMFactory *This = (DOMFactory*)iface;
136 ULONG ref = InterlockedDecrement(&This->ref);
137 TRACE("(%p) ref = %u\n", This, ref);
138 if(!ref) {
139 heap_free(This);
141 return ref;
144 static HRESULT WINAPI DOMClassFactory_CreateInstance(
145 IClassFactory *iface,
146 IUnknown *pOuter,
147 REFIID riid,
148 void **ppobj )
150 DOMFactory *This = (DOMFactory*)iface;
151 IUnknown *punk;
152 HRESULT r;
154 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
156 *ppobj = NULL;
158 if (pOuter)
159 return CLASS_E_NOAGGREGATION;
161 r = This->pCreateInstance( &This->clsid, pOuter, (void**) &punk );
162 if (FAILED(r))
163 return r;
165 r = IUnknown_QueryInterface( punk, riid, ppobj );
166 IUnknown_Release( punk );
167 return r;
170 static const struct IClassFactoryVtbl ClassFactoryVtbl =
172 ClassFactory_QueryInterface,
173 ClassFactory_AddRef,
174 ClassFactory_Release,
175 ClassFactory_CreateInstance,
176 ClassFactory_LockServer
179 static const struct IClassFactoryVtbl DOMClassFactoryVtbl =
181 ClassFactory_QueryInterface,
182 DOMClassFactory_AddRef,
183 DOMClassFactory_Release,
184 DOMClassFactory_CreateInstance,
185 ClassFactory_LockServer
188 static HRESULT DOMClassFactory_Create(const GUID *clsid, REFIID riid, void **ppv, DOMFactoryCreateInstanceFunc fnCreateInstance)
190 DOMFactory *ret = heap_alloc(sizeof(DOMFactory));
191 HRESULT hres;
193 ret->lpVtbl = &DOMClassFactoryVtbl;
194 ret->ref = 0;
195 ret->clsid = *clsid;
196 ret->pCreateInstance = fnCreateInstance;
198 hres = IClassFactory_QueryInterface((IClassFactory*)ret, riid, ppv);
199 if(FAILED(hres)) {
200 heap_free(ret);
201 *ppv = NULL;
203 return hres;
206 static ClassFactory xmldoccf = { &ClassFactoryVtbl, XMLDocument_create };
207 static ClassFactory saxreadcf = { &ClassFactoryVtbl, SAXXMLReader_create };
208 static ClassFactory httpreqcf = { &ClassFactoryVtbl, XMLHTTPRequest_create };
210 /******************************************************************
211 * DllGetClassObject (MSXML3.@)
213 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, void **ppv )
215 IClassFactory *cf = NULL;
217 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv );
219 if( IsEqualCLSID( rclsid, &CLSID_DOMDocument ) || /* Version indep. v 2.x */
220 IsEqualCLSID( rclsid, &CLSID_DOMDocument2 ) || /* Version indep. v 3.0 */
221 IsEqualCLSID( rclsid, &CLSID_DOMDocument26 )|| /* Version dep. v 2.6 */
222 IsEqualCLSID( rclsid, &CLSID_DOMDocument30 )|| /* Version dep. v 3.0 */
223 IsEqualCLSID( rclsid, &CLSID_DOMDocument40 )|| /* Version dep. v 4.0 */
224 IsEqualCLSID( rclsid, &CLSID_DOMDocument60 )) /* Version dep. v 6.0 */
226 return DOMClassFactory_Create(rclsid, riid, ppv, DOMDocument_create);
228 else if( IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache ) ||
229 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache26 ) ||
230 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache30 ) ||
231 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache40 ) ||
232 IsEqualCLSID( rclsid, &CLSID_XMLSchemaCache60 ))
234 return DOMClassFactory_Create(rclsid, riid, ppv, SchemaCache_create);
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_FreeThreadedDOMDocument26 ) ||
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;
265 if ( !cf )
266 return CLASS_E_CLASSNOTAVAILABLE;
268 return IClassFactory_QueryInterface( cf, riid, ppv );