| 1 | /*
|
|---|
| 2 | * An implementation of IUnknown.
|
|---|
| 3 | *
|
|---|
| 4 | * hidenori@a2.ctktv.ne.jp
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #include "config.h"
|
|---|
| 8 |
|
|---|
| 9 | #include "windef.h"
|
|---|
| 10 | #include "winerror.h"
|
|---|
| 11 | #include "wine/obj_base.h"
|
|---|
| 12 |
|
|---|
| 13 | #include "debugtools.h"
|
|---|
| 14 | DEFAULT_DEBUG_CHANNEL(quartz);
|
|---|
| 15 |
|
|---|
| 16 | #include "quartz_private.h"
|
|---|
| 17 | #include "iunk.h"
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | static HRESULT WINAPI
|
|---|
| 21 | IUnknown_fnQueryInterface(IUnknown* iface,REFIID riid,LPVOID *ppobj)
|
|---|
| 22 | {
|
|---|
| 23 | ICOM_THIS(QUARTZ_IUnkImpl,iface);
|
|---|
| 24 | size_t ofs;
|
|---|
| 25 | DWORD dwIndex;
|
|---|
| 26 |
|
|---|
| 27 | TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
|
|---|
| 28 |
|
|---|
| 29 | if ( ppobj == NULL )
|
|---|
| 30 | return E_POINTER;
|
|---|
| 31 | *ppobj = NULL;
|
|---|
| 32 |
|
|---|
| 33 | ofs = 0;
|
|---|
| 34 |
|
|---|
| 35 | if ( IsEqualGUID( &IID_IUnknown, riid ) )
|
|---|
| 36 | {
|
|---|
| 37 | TRACE("IID_IUnknown - returns inner object.\n");
|
|---|
| 38 | }
|
|---|
| 39 | else
|
|---|
| 40 | {
|
|---|
| 41 | for ( dwIndex = 0; dwIndex < This->dwEntries; dwIndex++ )
|
|---|
| 42 | {
|
|---|
| 43 | if ( IsEqualGUID( This->pEntries[dwIndex].piid, riid ) )
|
|---|
| 44 | {
|
|---|
| 45 | ofs = This->pEntries[dwIndex].ofsVTPtr;
|
|---|
| 46 | break;
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 | if ( dwIndex == This->dwEntries )
|
|---|
| 50 | {
|
|---|
| 51 | FIXME("unknown interface: %s\n",debugstr_guid(riid));
|
|---|
| 52 | return E_NOINTERFACE;
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | *ppobj = (LPVOID)(((char*)This) + ofs);
|
|---|
| 57 | IUnknown_AddRef((IUnknown*)(*ppobj));
|
|---|
| 58 |
|
|---|
| 59 | return S_OK;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | static ULONG WINAPI
|
|---|
| 63 | IUnknown_fnAddRef(IUnknown* iface)
|
|---|
| 64 | {
|
|---|
| 65 | ICOM_THIS(QUARTZ_IUnkImpl,iface);
|
|---|
| 66 |
|
|---|
| 67 | TRACE("(%p)->()\n",This);
|
|---|
| 68 |
|
|---|
| 69 | return ++(This->ref);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | static ULONG WINAPI
|
|---|
| 73 | IUnknown_fnRelease(IUnknown* iface)
|
|---|
| 74 | {
|
|---|
| 75 | ICOM_THIS(QUARTZ_IUnkImpl,iface);
|
|---|
| 76 |
|
|---|
| 77 | TRACE("(%p)->()\n",This);
|
|---|
| 78 | if ( (--(This->ref)) > 0 )
|
|---|
| 79 | return This->ref;
|
|---|
| 80 |
|
|---|
| 81 | QUARTZ_FreeObj(This);
|
|---|
| 82 |
|
|---|
| 83 | return 0;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | static ICOM_VTABLE(IUnknown) iunknown =
|
|---|
| 87 | {
|
|---|
| 88 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|---|
| 89 | /* IUnknown fields */
|
|---|
| 90 | IUnknown_fnQueryInterface,
|
|---|
| 91 | IUnknown_fnAddRef,
|
|---|
| 92 | IUnknown_fnRelease,
|
|---|
| 93 | };
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 | void QUARTZ_IUnkInit( QUARTZ_IUnkImpl* pImpl, IUnknown* punkOuter )
|
|---|
| 97 | {
|
|---|
| 98 | TRACE("(%p)\n",pImpl);
|
|---|
| 99 |
|
|---|
| 100 | ICOM_VTBL(pImpl) = &iunknown;
|
|---|
| 101 | pImpl->pEntries = NULL;
|
|---|
| 102 | pImpl->dwEntries = 0;
|
|---|
| 103 | pImpl->ref = 1;
|
|---|
| 104 | pImpl->punkControl = (IUnknown*)pImpl;
|
|---|
| 105 |
|
|---|
| 106 | /* for delegation. */
|
|---|
| 107 | if ( punkOuter != NULL )
|
|---|
| 108 | pImpl->punkControl = punkOuter;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|