msxml3: Fix indexed access to schema collection namespace uris.
[wine] / dlls / qedit / main.c
1 /*              DirectShow Editing Services (qedit.dll)
2  *
3  * Copyright 2008 Google (Lei Zhang)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "qedit_private.h"
21 #include "rpcproxy.h"
22 #include "wine/debug.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(qedit);
25
26 static HINSTANCE instance;
27
28 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
29 {
30     switch(fdwReason) {
31         case DLL_PROCESS_ATTACH:
32             instance = hInstDLL;
33             DisableThreadLibraryCalls(hInstDLL);
34             break;
35         case DLL_PROCESS_DETACH:
36             break;
37     }
38     return TRUE;
39 }
40
41 /******************************************************************************
42  * DirectShow ClassFactory
43  */
44 typedef struct {
45     IClassFactory IClassFactory_iface;
46     LONG ref;
47     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
48 } IClassFactoryImpl;
49
50 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
51 {
52     return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
53 }
54
55 struct object_creation_info
56 {
57     const CLSID *clsid;
58     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
59 };
60
61 static const struct object_creation_info object_creation[] =
62 {
63     { &CLSID_MediaDet, MediaDet_create },
64     { &CLSID_SampleGrabber, SampleGrabber_create },
65 };
66
67 static HRESULT WINAPI DSCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
68 {
69     if (IsEqualGUID(riid, &IID_IUnknown)
70         || IsEqualGUID(riid, &IID_IClassFactory))
71     {
72         IClassFactory_AddRef(iface);
73         *ppobj = iface;
74         return S_OK;
75     }
76
77     *ppobj = NULL;
78     WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
79     return E_NOINTERFACE;
80 }
81
82 static ULONG WINAPI DSCF_AddRef(IClassFactory *iface)
83 {
84     IClassFactoryImpl *This = impl_from_IClassFactory(iface);
85     return InterlockedIncrement(&This->ref);
86 }
87
88 static ULONG WINAPI DSCF_Release(IClassFactory *iface)
89 {
90     IClassFactoryImpl *This = impl_from_IClassFactory(iface);
91     ULONG ref = InterlockedDecrement(&This->ref);
92
93     if (ref == 0)
94         CoTaskMemFree(This);
95
96     return ref;
97 }
98
99 static HRESULT WINAPI DSCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter, REFIID riid,
100         void **ppobj)
101 {
102     IClassFactoryImpl *This = impl_from_IClassFactory(iface);
103     HRESULT hres;
104     LPUNKNOWN punk;
105
106     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
107
108     *ppobj = NULL;
109     if (pOuter && !IsEqualGUID(&IID_IUnknown, riid))
110         return E_INVALIDARG;
111
112     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
113     if (SUCCEEDED(hres)) {
114         hres = IUnknown_QueryInterface(punk, riid, ppobj);
115         IUnknown_Release(punk);
116     }
117     return hres;
118 }
119
120 static HRESULT WINAPI DSCF_LockServer(IClassFactory *iface, BOOL dolock)
121 {
122     IClassFactoryImpl *This = impl_from_IClassFactory(iface);
123     FIXME("(%p)->(%d),stub!\n",This,dolock);
124     return S_OK;
125 }
126
127 static const IClassFactoryVtbl DSCF_Vtbl =
128 {
129     DSCF_QueryInterface,
130     DSCF_AddRef,
131     DSCF_Release,
132     DSCF_CreateInstance,
133     DSCF_LockServer
134 };
135
136
137 /***********************************************************************
138  *              DllCanUnloadNow (QEDIT.@)
139  */
140 HRESULT WINAPI DllCanUnloadNow(void)
141 {
142     return S_OK;
143 }
144
145 /*******************************************************************************
146  * DllGetClassObject [QEDIT.@]
147  * Retrieves class object from a DLL object
148  *
149  * PARAMS
150  *    rclsid [I] CLSID for the class object
151  *    riid   [I] Reference to identifier of interface for class object
152  *    ppv    [O] Address of variable to receive interface pointer for riid
153  *
154  * RETURNS
155  *    Success: S_OK
156  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
157  *             E_UNEXPECTED, E_NOINTERFACE
158  */
159
160 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
161 {
162     unsigned int i;
163     IClassFactoryImpl *factory;
164
165     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
166
167     if ( !IsEqualGUID( &IID_IClassFactory, riid )
168          && ! IsEqualGUID( &IID_IUnknown, riid) )
169         return E_NOINTERFACE;
170
171     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
172     {
173         if (IsEqualGUID(object_creation[i].clsid, rclsid))
174             break;
175     }
176
177     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
178     {
179         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
180         return CLASS_E_CLASSNOTAVAILABLE;
181     }
182
183     factory = CoTaskMemAlloc(sizeof(*factory));
184     if (factory == NULL) return E_OUTOFMEMORY;
185
186     factory->IClassFactory_iface.lpVtbl = &DSCF_Vtbl;
187     factory->ref = 1;
188
189     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
190
191     *ppv = &factory->IClassFactory_iface;
192     return S_OK;
193 }
194
195 /***********************************************************************
196  *              DllRegisterServer (QEDIT.@)
197  */
198 HRESULT WINAPI DllRegisterServer(void)
199 {
200     return __wine_register_resources( instance );
201 }
202
203 /***********************************************************************
204  *              DllUnregisterServer (QEDIT.@)
205  */
206 HRESULT WINAPI DllUnregisterServer(void)
207 {
208     return __wine_unregister_resources( instance );
209 }