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