6753d5b66425d5bf08fc1de0b221efba49d07741
[reactos.git] / reactos / dll / directx / wine / 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
23 static HINSTANCE instance;
24
25 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
26 {
27 switch(fdwReason) {
28 case DLL_PROCESS_ATTACH:
29 instance = hInstDLL;
30 DisableThreadLibraryCalls(hInstDLL);
31 break;
32 }
33 return TRUE;
34 }
35
36 /******************************************************************************
37 * DirectShow ClassFactory
38 */
39 typedef struct {
40 IClassFactory IClassFactory_iface;
41 LONG ref;
42 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
43 } IClassFactoryImpl;
44
45 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
46 {
47 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
48 }
49
50 struct object_creation_info
51 {
52 const CLSID *clsid;
53 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
54 };
55
56 static const struct object_creation_info object_creation[] =
57 {
58 { &CLSID_MediaDet, MediaDet_create },
59 { &CLSID_SampleGrabber, SampleGrabber_create },
60 };
61
62 static HRESULT WINAPI DSCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
63 {
64 if (IsEqualGUID(riid, &IID_IUnknown)
65 || IsEqualGUID(riid, &IID_IClassFactory))
66 {
67 IClassFactory_AddRef(iface);
68 *ppobj = iface;
69 return S_OK;
70 }
71
72 *ppobj = NULL;
73 WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
74 return E_NOINTERFACE;
75 }
76
77 static ULONG WINAPI DSCF_AddRef(IClassFactory *iface)
78 {
79 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
80 return InterlockedIncrement(&This->ref);
81 }
82
83 static ULONG WINAPI DSCF_Release(IClassFactory *iface)
84 {
85 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
86 ULONG ref = InterlockedDecrement(&This->ref);
87
88 if (ref == 0)
89 CoTaskMemFree(This);
90
91 return ref;
92 }
93
94 static HRESULT WINAPI DSCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter, REFIID riid,
95 void **ppobj)
96 {
97 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
98 HRESULT hres;
99 LPUNKNOWN punk;
100
101 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
102
103 *ppobj = NULL;
104 if (pOuter && !IsEqualGUID(&IID_IUnknown, riid))
105 return E_INVALIDARG;
106
107 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
108 if (SUCCEEDED(hres)) {
109 hres = IUnknown_QueryInterface(punk, riid, ppobj);
110 IUnknown_Release(punk);
111 }
112 return hres;
113 }
114
115 static HRESULT WINAPI DSCF_LockServer(IClassFactory *iface, BOOL dolock)
116 {
117 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
118 FIXME("(%p)->(%d),stub!\n",This,dolock);
119 return S_OK;
120 }
121
122 static const IClassFactoryVtbl DSCF_Vtbl =
123 {
124 DSCF_QueryInterface,
125 DSCF_AddRef,
126 DSCF_Release,
127 DSCF_CreateInstance,
128 DSCF_LockServer
129 };
130
131
132 /***********************************************************************
133 * DllCanUnloadNow (QEDIT.@)
134 */
135 HRESULT WINAPI DllCanUnloadNow(void)
136 {
137 return S_FALSE;
138 }
139
140 /*******************************************************************************
141 * DllGetClassObject [QEDIT.@]
142 * Retrieves class object from a DLL object
143 *
144 * PARAMS
145 * rclsid [I] CLSID for the class object
146 * riid [I] Reference to identifier of interface for class object
147 * ppv [O] Address of variable to receive interface pointer for riid
148 *
149 * RETURNS
150 * Success: S_OK
151 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
152 * E_UNEXPECTED, E_NOINTERFACE
153 */
154
155 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
156 {
157 unsigned int i;
158 IClassFactoryImpl *factory;
159
160 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
161
162 if ( !IsEqualGUID( &IID_IClassFactory, riid )
163 && ! IsEqualGUID( &IID_IUnknown, riid) )
164 return E_NOINTERFACE;
165
166 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
167 {
168 if (IsEqualGUID(object_creation[i].clsid, rclsid))
169 break;
170 }
171
172 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
173 {
174 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
175 return CLASS_E_CLASSNOTAVAILABLE;
176 }
177
178 factory = CoTaskMemAlloc(sizeof(*factory));
179 if (factory == NULL) return E_OUTOFMEMORY;
180
181 factory->IClassFactory_iface.lpVtbl = &DSCF_Vtbl;
182 factory->ref = 1;
183
184 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
185
186 *ppv = &factory->IClassFactory_iface;
187 return S_OK;
188 }
189
190 /***********************************************************************
191 * DllRegisterServer (QEDIT.@)
192 */
193 HRESULT WINAPI DllRegisterServer(void)
194 {
195 return __wine_register_resources( instance );
196 }
197
198 /***********************************************************************
199 * DllUnregisterServer (QEDIT.@)
200 */
201 HRESULT WINAPI DllUnregisterServer(void)
202 {
203 return __wine_unregister_resources( instance );
204 }