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