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

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

wine updates

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