2001-08-15 21:26:52 +02:00
|
|
|
/*
|
|
|
|
* An implementation of IUnknown.
|
|
|
|
*
|
|
|
|
* hidenori@a2.ctktv.ne.jp
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winerror.h"
|
2001-08-28 19:25:39 +02:00
|
|
|
#include "winbase.h"
|
2001-08-15 21:26:52 +02:00
|
|
|
#include "wine/obj_base.h"
|
|
|
|
|
|
|
|
#include "debugtools.h"
|
|
|
|
DEFAULT_DEBUG_CHANNEL(quartz);
|
|
|
|
|
|
|
|
#include "quartz_private.h"
|
|
|
|
#include "iunk.h"
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
IUnknown_fnQueryInterface(IUnknown* iface,REFIID riid,LPVOID *ppobj)
|
|
|
|
{
|
|
|
|
ICOM_THIS(QUARTZ_IUnkImpl,iface);
|
|
|
|
size_t ofs;
|
|
|
|
DWORD dwIndex;
|
2001-09-11 02:29:03 +02:00
|
|
|
QUARTZ_IFDelegation* pDelegation;
|
|
|
|
HRESULT hr;
|
2001-08-15 21:26:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
|
|
|
|
|
|
|
|
if ( ppobj == NULL )
|
|
|
|
return E_POINTER;
|
|
|
|
*ppobj = NULL;
|
|
|
|
|
|
|
|
ofs = 0;
|
2001-08-22 20:06:00 +02:00
|
|
|
|
|
|
|
if ( IsEqualGUID( &IID_IUnknown, riid ) )
|
2001-08-15 21:26:52 +02:00
|
|
|
{
|
2001-08-22 20:06:00 +02:00
|
|
|
TRACE("IID_IUnknown - returns inner object.\n");
|
2001-08-15 21:26:52 +02:00
|
|
|
}
|
2001-08-22 20:06:00 +02:00
|
|
|
else
|
2001-08-15 21:26:52 +02:00
|
|
|
{
|
2001-08-22 20:06:00 +02:00
|
|
|
for ( dwIndex = 0; dwIndex < This->dwEntries; dwIndex++ )
|
2001-08-15 21:26:52 +02:00
|
|
|
{
|
2001-08-22 20:06:00 +02:00
|
|
|
if ( IsEqualGUID( This->pEntries[dwIndex].piid, riid ) )
|
|
|
|
{
|
|
|
|
ofs = This->pEntries[dwIndex].ofsVTPtr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( dwIndex == This->dwEntries )
|
|
|
|
{
|
2001-09-11 02:29:03 +02:00
|
|
|
hr = E_NOINTERFACE;
|
|
|
|
|
|
|
|
/* delegation */
|
|
|
|
pDelegation = This->pDelegationFirst;
|
|
|
|
while ( pDelegation != NULL )
|
|
|
|
{
|
|
|
|
hr = (*pDelegation->pOnQueryInterface)( iface, riid, ppobj );
|
|
|
|
if ( hr != E_NOINTERFACE )
|
|
|
|
break;
|
|
|
|
pDelegation = pDelegation->pNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( hr == E_NOINTERFACE )
|
|
|
|
{
|
2001-09-26 00:37:04 +02:00
|
|
|
FIXME("(%p) unknown interface: %s\n",This,debugstr_guid(riid));
|
2001-09-11 02:29:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2001-08-15 21:26:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppobj = (LPVOID)(((char*)This) + ofs);
|
2001-08-22 20:06:00 +02:00
|
|
|
IUnknown_AddRef((IUnknown*)(*ppobj));
|
2001-08-15 21:26:52 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI
|
|
|
|
IUnknown_fnAddRef(IUnknown* iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS(QUARTZ_IUnkImpl,iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->()\n",This);
|
|
|
|
|
2001-08-28 19:25:39 +02:00
|
|
|
return InterlockedExchangeAdd(&(This->ref),1) + 1;
|
2001-08-15 21:26:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI
|
|
|
|
IUnknown_fnRelease(IUnknown* iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS(QUARTZ_IUnkImpl,iface);
|
2001-08-28 19:25:39 +02:00
|
|
|
LONG ref;
|
2001-08-15 21:26:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->()\n",This);
|
2001-08-28 19:25:39 +02:00
|
|
|
ref = InterlockedExchangeAdd(&(This->ref),-1) - 1;
|
|
|
|
if ( ref > 0 )
|
|
|
|
return (ULONG)ref;
|
|
|
|
|
|
|
|
if ( This->pOnFinalRelease != NULL )
|
|
|
|
(*(This->pOnFinalRelease))(iface);
|
2001-08-15 21:26:52 +02:00
|
|
|
|
|
|
|
QUARTZ_FreeObj(This);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ICOM_VTABLE(IUnknown) iunknown =
|
|
|
|
{
|
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|
|
|
/* IUnknown fields */
|
|
|
|
IUnknown_fnQueryInterface,
|
|
|
|
IUnknown_fnAddRef,
|
|
|
|
IUnknown_fnRelease,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-08-22 20:06:00 +02:00
|
|
|
void QUARTZ_IUnkInit( QUARTZ_IUnkImpl* pImpl, IUnknown* punkOuter )
|
2001-08-15 21:26:52 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n",pImpl);
|
|
|
|
|
|
|
|
ICOM_VTBL(pImpl) = &iunknown;
|
|
|
|
pImpl->pEntries = NULL;
|
|
|
|
pImpl->dwEntries = 0;
|
2001-09-11 02:29:03 +02:00
|
|
|
pImpl->pDelegationFirst = NULL;
|
2001-08-28 19:25:39 +02:00
|
|
|
pImpl->pOnFinalRelease = NULL;
|
2001-08-15 21:26:52 +02:00
|
|
|
pImpl->ref = 1;
|
2001-08-22 20:06:00 +02:00
|
|
|
pImpl->punkControl = (IUnknown*)pImpl;
|
|
|
|
|
2001-09-11 02:29:03 +02:00
|
|
|
/* for implementing aggregation. */
|
2001-08-22 20:06:00 +02:00
|
|
|
if ( punkOuter != NULL )
|
|
|
|
pImpl->punkControl = punkOuter;
|
2001-08-15 21:26:52 +02:00
|
|
|
}
|
2001-08-22 20:06:00 +02:00
|
|
|
|
2001-09-11 02:29:03 +02:00
|
|
|
void QUARTZ_IUnkAddDelegation(
|
|
|
|
QUARTZ_IUnkImpl* pImpl, QUARTZ_IFDelegation* pDelegation )
|
|
|
|
{
|
|
|
|
pDelegation->pNext = pImpl->pDelegationFirst;
|
|
|
|
pImpl->pDelegationFirst = pDelegation;
|
|
|
|
}
|
|
|
|
|