2001-07-02 18:57:22 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winerror.h"
|
2001-08-15 19:26:52 +00:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
2001-07-02 18:57:22 +00:00
|
|
|
#include "ole2.h"
|
2001-08-15 19:26:52 +00:00
|
|
|
#include "strmif.h"
|
|
|
|
#include "uuids.h"
|
2001-07-02 18:57:22 +00:00
|
|
|
|
|
|
|
#include "debugtools.h"
|
|
|
|
DEFAULT_DEBUG_CHANNEL(quartz);
|
|
|
|
|
2001-08-15 19:26:52 +00:00
|
|
|
#include "quartz_private.h"
|
|
|
|
#include "fgraph.h"
|
|
|
|
#include "sysclock.h"
|
|
|
|
#include "memalloc.h"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct QUARTZ_CLASSENTRY
|
|
|
|
{
|
|
|
|
const CLSID* pclsid;
|
|
|
|
QUARTZ_pCreateIUnknown pCreateIUnk;
|
|
|
|
} QUARTZ_CLASSENTRY;
|
|
|
|
|
|
|
|
|
2001-07-02 18:57:22 +00:00
|
|
|
static HRESULT WINAPI
|
|
|
|
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
|
|
|
|
static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
|
|
|
|
static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
|
|
|
|
static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
|
|
|
|
static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
|
|
|
|
|
|
|
|
static ICOM_VTABLE(IClassFactory) iclassfact =
|
|
|
|
{
|
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|
|
|
IClassFactory_fnQueryInterface,
|
|
|
|
IClassFactory_fnAddRef,
|
|
|
|
IClassFactory_fnRelease,
|
|
|
|
IClassFactory_fnCreateInstance,
|
|
|
|
IClassFactory_fnLockServer
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
|
|
|
ICOM_VFIELD(IClassFactory);
|
|
|
|
DWORD ref;
|
2001-08-15 19:26:52 +00:00
|
|
|
/* IClassFactory fields */
|
|
|
|
const QUARTZ_CLASSENTRY* pEntry;
|
2001-07-02 18:57:22 +00:00
|
|
|
} IClassFactoryImpl;
|
|
|
|
|
2001-08-15 19:26:52 +00:00
|
|
|
static const QUARTZ_CLASSENTRY QUARTZ_ClassList[] =
|
|
|
|
{
|
|
|
|
{ &CLSID_FilterGraph, &QUARTZ_CreateFilterGraph },
|
|
|
|
{ &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
|
|
|
|
{ &CLSID_MemoryAllocator, &QUARTZ_CreateMemoryAllocator },
|
|
|
|
{ NULL, NULL },
|
|
|
|
};
|
2001-07-02 18:57:22 +00:00
|
|
|
|
2001-08-15 19:26:52 +00:00
|
|
|
/* per-process variables */
|
|
|
|
static CRITICAL_SECTION csHeap;
|
2001-07-02 18:57:22 +00:00
|
|
|
static DWORD dwClassObjRef;
|
2001-08-15 19:26:52 +00:00
|
|
|
static HANDLE hDLLHeap;
|
|
|
|
|
|
|
|
void* QUARTZ_AllocObj( DWORD dwSize )
|
|
|
|
{
|
|
|
|
void* pv;
|
2001-07-02 18:57:22 +00:00
|
|
|
|
2001-08-15 19:26:52 +00:00
|
|
|
EnterCriticalSection( &csHeap );
|
|
|
|
dwClassObjRef ++;
|
|
|
|
pv = HeapAlloc( hDLLHeap, 0, dwSize );
|
|
|
|
if ( pv == NULL )
|
|
|
|
dwClassObjRef --;
|
|
|
|
LeaveCriticalSection( &csHeap );
|
|
|
|
|
|
|
|
return pv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QUARTZ_FreeObj( void* pobj )
|
|
|
|
{
|
|
|
|
EnterCriticalSection( &csHeap );
|
|
|
|
HeapFree( hDLLHeap, 0, pobj );
|
|
|
|
dwClassObjRef --;
|
|
|
|
LeaveCriticalSection( &csHeap );
|
|
|
|
}
|
|
|
|
|
|
|
|
void* QUARTZ_AllocMem( DWORD dwSize )
|
|
|
|
{
|
|
|
|
return HeapAlloc( hDLLHeap, 0, dwSize );
|
|
|
|
}
|
|
|
|
|
|
|
|
void QUARTZ_FreeMem( void* pMem )
|
|
|
|
{
|
|
|
|
HeapFree( hDLLHeap, 0, pMem );
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
2001-07-02 18:57:22 +00:00
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
|
|
|
|
{
|
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p,%p)\n",This,riid,ppobj);
|
|
|
|
if ( ( IsEqualGUID( &IID_IUnknown, riid ) ) ||
|
|
|
|
( IsEqualGUID( &IID_IClassFactory, riid ) ) )
|
|
|
|
{
|
|
|
|
*ppobj = iface;
|
|
|
|
IClassFactory_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->()\n",This);
|
|
|
|
|
|
|
|
return ++(This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->()\n",This);
|
|
|
|
if ( (--(This->ref)) > 0 )
|
|
|
|
return This->ref;
|
|
|
|
|
2001-08-15 19:26:52 +00:00
|
|
|
QUARTZ_FreeObj(This);
|
2001-07-02 18:57:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj)
|
|
|
|
{
|
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
2001-08-15 19:26:52 +00:00
|
|
|
HRESULT hr;
|
|
|
|
IUnknown* punk;
|
2001-07-02 18:57:22 +00:00
|
|
|
|
2001-08-15 19:26:52 +00:00
|
|
|
TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
|
|
|
|
|
|
|
|
if ( ppobj == NULL )
|
|
|
|
return E_POINTER;
|
2001-07-02 18:57:22 +00:00
|
|
|
|
|
|
|
*ppobj = NULL;
|
|
|
|
|
2001-08-15 19:26:52 +00:00
|
|
|
hr = (*This->pEntry->pCreateIUnk)(pOuter,(void**)&punk);
|
|
|
|
if ( hr != S_OK )
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(punk,riid,ppobj);
|
|
|
|
IUnknown_Release(punk);
|
|
|
|
|
|
|
|
return hr;
|
2001-07-02 18:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
|
|
|
|
{
|
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
FIXME("(%p)->(%d),stub!\n",This,dolock);
|
|
|
|
if (dolock)
|
|
|
|
hr = IClassFactory_AddRef(iface);
|
|
|
|
else
|
|
|
|
hr = IClassFactory_Release(iface);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-08-15 19:26:52 +00:00
|
|
|
static HRESULT IClassFactory_Alloc( const CLSID* pclsid, void** ppobj )
|
|
|
|
{
|
|
|
|
const QUARTZ_CLASSENTRY* pEntry;
|
|
|
|
IClassFactoryImpl* pImpl;
|
|
|
|
|
|
|
|
TRACE( "(%s,%p)\n", debugstr_guid(pclsid), ppobj );
|
|
|
|
|
|
|
|
pEntry = QUARTZ_ClassList;
|
|
|
|
while ( pEntry->pclsid != NULL )
|
|
|
|
{
|
|
|
|
if ( IsEqualGUID( pclsid, pEntry->pclsid ) )
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
found:
|
|
|
|
pImpl = (IClassFactoryImpl*)QUARTZ_AllocObj( sizeof(IClassFactoryImpl) );
|
|
|
|
if ( pImpl == NULL )
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
ICOM_VTBL(pImpl) = &iclassfact;
|
|
|
|
pImpl->ref = 1;
|
|
|
|
pImpl->pEntry = pEntry;
|
|
|
|
|
|
|
|
*ppobj = (void*)pImpl;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2001-07-02 18:57:22 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* QUARTZ_InitProcess (internal)
|
|
|
|
*/
|
|
|
|
static BOOL QUARTZ_InitProcess( void )
|
|
|
|
{
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
dwClassObjRef = 0;
|
2001-08-15 19:26:52 +00:00
|
|
|
hDLLHeap = (HANDLE)NULL;
|
|
|
|
InitializeCriticalSection( &csHeap );
|
|
|
|
|
|
|
|
hDLLHeap = HeapCreate( 0, 0x10000, 0 );
|
|
|
|
if ( hDLLHeap == (HANDLE)NULL )
|
|
|
|
return FALSE;
|
2001-07-02 18:57:22 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* QUARTZ_UninitProcess (internal)
|
|
|
|
*/
|
|
|
|
static void QUARTZ_UninitProcess( void )
|
|
|
|
{
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
if ( dwClassObjRef != 0 )
|
|
|
|
ERR( "you must release some objects allocated from quartz.\n" );
|
2001-08-15 19:26:52 +00:00
|
|
|
if ( hDLLHeap != (HANDLE)NULL )
|
|
|
|
{
|
|
|
|
HeapDestroy( hDLLHeap );
|
|
|
|
hDLLHeap = (HANDLE)NULL;
|
|
|
|
}
|
|
|
|
DeleteCriticalSection( &csHeap );
|
2001-07-02 18:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* QUARTZ_DllMain
|
|
|
|
*/
|
|
|
|
BOOL WINAPI QUARTZ_DllMain(
|
|
|
|
HINSTANCE hInstDLL,
|
|
|
|
DWORD fdwReason,
|
|
|
|
LPVOID lpvReserved )
|
|
|
|
{
|
|
|
|
switch ( fdwReason )
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
if ( !QUARTZ_InitProcess() )
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
QUARTZ_UninitProcess();
|
|
|
|
break;
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
break;
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllCanUnloadNow (QUARTZ.@)
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: S_FALSE
|
|
|
|
*/
|
2001-08-15 19:26:52 +00:00
|
|
|
HRESULT WINAPI QUARTZ_DllCanUnloadNow(void)
|
2001-07-02 18:57:22 +00:00
|
|
|
{
|
2001-08-15 19:26:52 +00:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
EnterCriticalSection( &csHeap );
|
|
|
|
hr = ( dwClassObjRef == 0 ) ? S_OK : S_FALSE;
|
|
|
|
LeaveCriticalSection( &csHeap );
|
|
|
|
|
|
|
|
return hr;
|
2001-07-02 18:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllGetClassObject (QUARTZ.@)
|
|
|
|
*/
|
2001-08-15 19:26:52 +00:00
|
|
|
HRESULT WINAPI QUARTZ_DllGetClassObject(
|
2001-07-02 18:57:22 +00:00
|
|
|
const CLSID* pclsid,const IID* piid,void** ppv)
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
2001-08-15 19:26:52 +00:00
|
|
|
if ( IsEqualCLSID( &IID_IUnknown, piid ) ||
|
|
|
|
IsEqualCLSID( &IID_IClassFactory, piid ) )
|
2001-07-02 18:57:22 +00:00
|
|
|
{
|
2001-08-15 19:26:52 +00:00
|
|
|
return IClassFactory_Alloc( pclsid, ppv );
|
2001-07-02 18:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllRegisterServer (QUARTZ.@)
|
|
|
|
*/
|
|
|
|
|
|
|
|
HRESULT WINAPI QUARTZ_DllRegisterServer( void )
|
|
|
|
{
|
|
|
|
FIXME( "(): stub\n" );
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllUnregisterServer (QUARTZ.@)
|
|
|
|
*/
|
|
|
|
|
|
|
|
HRESULT WINAPI QUARTZ_DllUnregisterServer( void )
|
|
|
|
{
|
|
|
|
FIXME( "(): stub\n" );
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|