source: trunk/src/quartz/main.c@ 6710

Last change on this file since 6710 was 6710, checked in by sandervl, 24 years ago

wine update

File size: 7.2 KB
Line 
1#include "config.h"
2
3#include "windef.h"
4#include "winerror.h"
5#include "winbase.h"
6#include "wingdi.h"
7#include "ole2.h"
8#include "wine/obj_oleaut.h"
9#include "strmif.h"
10#include "control.h"
11#include "uuids.h"
12
13#include "debugtools.h"
14DEFAULT_DEBUG_CHANNEL(quartz);
15
16#include "quartz_private.h"
17#include "fgraph.h"
18#include "sysclock.h"
19#include "memalloc.h"
20#include "devenum.h"
21#include "fmap.h"
22#include "fmap2.h"
23#include "seekpass.h"
24
25
26typedef struct QUARTZ_CLASSENTRY
27{
28 const CLSID* pclsid;
29 QUARTZ_pCreateIUnknown pCreateIUnk;
30} QUARTZ_CLASSENTRY;
31
32
33static HRESULT WINAPI
34IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
35static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
36static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
37static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
38static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
39
40static ICOM_VTABLE(IClassFactory) iclassfact =
41{
42 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
43 IClassFactory_fnQueryInterface,
44 IClassFactory_fnAddRef,
45 IClassFactory_fnRelease,
46 IClassFactory_fnCreateInstance,
47 IClassFactory_fnLockServer
48};
49
50typedef struct
51{
52 /* IUnknown fields */
53 ICOM_VFIELD(IClassFactory);
54 LONG ref;
55 /* IClassFactory fields */
56 const QUARTZ_CLASSENTRY* pEntry;
57} IClassFactoryImpl;
58
59static const QUARTZ_CLASSENTRY QUARTZ_ClassList[] =
60{
61 { &CLSID_FilterGraph, &QUARTZ_CreateFilterGraph },
62 { &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
63 { &CLSID_MemoryAllocator, &QUARTZ_CreateMemoryAllocator },
64 { &CLSID_SystemDeviceEnum, &QUARTZ_CreateSystemDeviceEnum },
65 { &CLSID_FilterMapper, &QUARTZ_CreateFilterMapper },
66 { &CLSID_FilterMapper2, &QUARTZ_CreateFilterMapper2 },
67 { &CLSID_SeekingPassThru, &QUARTZ_CreateSeekingPassThru },
68 { NULL, NULL },
69};
70
71/* per-process variables */
72static CRITICAL_SECTION csHeap;
73static DWORD dwClassObjRef;
74static HANDLE hDLLHeap;
75
76void* QUARTZ_AllocObj( DWORD dwSize )
77{
78 void* pv;
79
80 EnterCriticalSection( &csHeap );
81 dwClassObjRef ++;
82 pv = HeapAlloc( hDLLHeap, 0, dwSize );
83 if ( pv == NULL )
84 dwClassObjRef --;
85 LeaveCriticalSection( &csHeap );
86
87 return pv;
88}
89
90void QUARTZ_FreeObj( void* pobj )
91{
92 EnterCriticalSection( &csHeap );
93 HeapFree( hDLLHeap, 0, pobj );
94 dwClassObjRef --;
95 LeaveCriticalSection( &csHeap );
96}
97
98void* QUARTZ_AllocMem( DWORD dwSize )
99{
100 return HeapAlloc( hDLLHeap, 0, dwSize );
101}
102
103void QUARTZ_FreeMem( void* pMem )
104{
105 HeapFree( hDLLHeap, 0, pMem );
106}
107
108/************************************************************************/
109
110static HRESULT WINAPI
111IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
112{
113 ICOM_THIS(IClassFactoryImpl,iface);
114
115 TRACE("(%p)->(%p,%p)\n",This,riid,ppobj);
116 if ( ( IsEqualGUID( &IID_IUnknown, riid ) ) ||
117 ( IsEqualGUID( &IID_IClassFactory, riid ) ) )
118 {
119 *ppobj = iface;
120 IClassFactory_AddRef(iface);
121 return S_OK;
122 }
123
124 return E_NOINTERFACE;
125}
126
127static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
128{
129 ICOM_THIS(IClassFactoryImpl,iface);
130
131 TRACE("(%p)->()\n",This);
132
133 return InterlockedExchangeAdd(&(This->ref),1) + 1;
134}
135
136static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
137{
138 ICOM_THIS(IClassFactoryImpl,iface);
139 LONG ref;
140
141 TRACE("(%p)->()\n",This);
142 ref = InterlockedExchangeAdd(&(This->ref),-1) - 1;
143 if ( ref > 0 )
144 return (ULONG)ref;
145
146 QUARTZ_FreeObj(This);
147 return 0;
148}
149
150static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj)
151{
152 ICOM_THIS(IClassFactoryImpl,iface);
153 HRESULT hr;
154 IUnknown* punk;
155
156 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
157
158 if ( ppobj == NULL )
159 return E_POINTER;
160 if ( pOuter != NULL && !IsEqualGUID( riid, &IID_IUnknown ) )
161 return CLASS_E_NOAGGREGATION;
162
163 *ppobj = NULL;
164
165 hr = (*This->pEntry->pCreateIUnk)(pOuter,(void**)&punk);
166 if ( hr != S_OK )
167 return hr;
168
169 hr = IUnknown_QueryInterface(punk,riid,ppobj);
170 IUnknown_Release(punk);
171
172 return hr;
173}
174
175static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
176{
177 ICOM_THIS(IClassFactoryImpl,iface);
178 HRESULT hr;
179
180 TRACE("(%p)->(%d)\n",This,dolock);
181 if (dolock)
182 hr = IClassFactory_AddRef(iface);
183 else
184 hr = IClassFactory_Release(iface);
185
186 return hr;
187}
188
189
190
191static HRESULT IClassFactory_Alloc( const CLSID* pclsid, void** ppobj )
192{
193 const QUARTZ_CLASSENTRY* pEntry;
194 IClassFactoryImpl* pImpl;
195
196 TRACE( "(%s,%p)\n", debugstr_guid(pclsid), ppobj );
197
198 pEntry = QUARTZ_ClassList;
199 while ( pEntry->pclsid != NULL )
200 {
201 if ( IsEqualGUID( pclsid, pEntry->pclsid ) )
202 goto found;
203 pEntry ++;
204 }
205
206 return CLASS_E_CLASSNOTAVAILABLE;
207found:
208 pImpl = (IClassFactoryImpl*)QUARTZ_AllocObj( sizeof(IClassFactoryImpl) );
209 if ( pImpl == NULL )
210 return E_OUTOFMEMORY;
211
212 TRACE( "allocated successfully.\n" );
213
214 ICOM_VTBL(pImpl) = &iclassfact;
215 pImpl->ref = 1;
216 pImpl->pEntry = pEntry;
217
218 *ppobj = (void*)pImpl;
219 return S_OK;
220}
221
222
223/***********************************************************************
224 * QUARTZ_InitProcess (internal)
225 */
226static BOOL QUARTZ_InitProcess( void )
227{
228 TRACE("()\n");
229
230 dwClassObjRef = 0;
231 hDLLHeap = (HANDLE)NULL;
232 InitializeCriticalSection( &csHeap );
233
234 hDLLHeap = HeapCreate( 0, 0x10000, 0 );
235 if ( hDLLHeap == (HANDLE)NULL )
236 return FALSE;
237
238 return TRUE;
239}
240
241/***********************************************************************
242 * QUARTZ_UninitProcess (internal)
243 */
244static void QUARTZ_UninitProcess( void )
245{
246 TRACE("()\n");
247
248 if ( dwClassObjRef != 0 )
249 ERR( "you must release some objects allocated from quartz.\n" );
250 if ( hDLLHeap != (HANDLE)NULL )
251 {
252 HeapDestroy( hDLLHeap );
253 hDLLHeap = (HANDLE)NULL;
254 }
255 DeleteCriticalSection( &csHeap );
256}
257
258/***********************************************************************
259 * QUARTZ_DllMain
260 */
261BOOL WINAPI QUARTZ_DllMain(
262 HINSTANCE hInstDLL,
263 DWORD fdwReason,
264 LPVOID lpvReserved )
265{
266 switch ( fdwReason )
267 {
268 case DLL_PROCESS_ATTACH:
269 if ( !QUARTZ_InitProcess() )
270 return FALSE;
271 break;
272 case DLL_PROCESS_DETACH:
273 QUARTZ_UninitProcess();
274 break;
275 case DLL_THREAD_ATTACH:
276 break;
277 case DLL_THREAD_DETACH:
278 break;
279 }
280
281 return TRUE;
282}
283
284
285/***********************************************************************
286 * DllCanUnloadNow (QUARTZ.@)
287 *
288 * RETURNS
289 * Success: S_OK
290 * Failure: S_FALSE
291 */
292HRESULT WINAPI QUARTZ_DllCanUnloadNow(void)
293{
294 HRESULT hr;
295
296 EnterCriticalSection( &csHeap );
297 hr = ( dwClassObjRef == 0 ) ? S_OK : S_FALSE;
298 LeaveCriticalSection( &csHeap );
299
300 return hr;
301}
302
303/***********************************************************************
304 * DllGetClassObject (QUARTZ.@)
305 */
306HRESULT WINAPI QUARTZ_DllGetClassObject(
307 const CLSID* pclsid,const IID* piid,void** ppv)
308{
309 *ppv = NULL;
310 if ( IsEqualCLSID( &IID_IUnknown, piid ) ||
311 IsEqualCLSID( &IID_IClassFactory, piid ) )
312 {
313 return IClassFactory_Alloc( pclsid, ppv );
314 }
315
316 return CLASS_E_CLASSNOTAVAILABLE;
317}
318
319/***********************************************************************
320 * DllRegisterServer (QUARTZ.@)
321 */
322
323HRESULT WINAPI QUARTZ_DllRegisterServer( void )
324{
325 FIXME( "(): stub\n" );
326 return E_FAIL;
327}
328
329/***********************************************************************
330 * DllUnregisterServer (QUARTZ.@)
331 */
332
333HRESULT WINAPI QUARTZ_DllUnregisterServer( void )
334{
335 FIXME( "(): stub\n" );
336 return E_FAIL;
337}
338
339
340
Note: See TracBrowser for help on using the repository browser.