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