Changeset 6710 for trunk/src/quartz/iunk.c
- Timestamp:
- Sep 15, 2001, 11:28:23 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/quartz/iunk.c
r6649 r6710 1 /* $Id: iunk.c,v 1.3 2001-09-05 13:36:37 bird Exp $ */2 1 /* 3 2 * An implementation of IUnknown. … … 10 9 #include "windef.h" 11 10 #include "winerror.h" 11 #include "winbase.h" 12 12 #include "wine/obj_base.h" 13 13 … … 22 22 IUnknown_fnQueryInterface(IUnknown* iface,REFIID riid,LPVOID *ppobj) 23 23 { 24 ICOM_THIS(QUARTZ_IUnkImpl,iface); 25 size_t ofs; 26 DWORD dwIndex; 24 ICOM_THIS(QUARTZ_IUnkImpl,iface); 25 size_t ofs; 26 DWORD dwIndex; 27 QUARTZ_IFDelegation* pDelegation; 28 HRESULT hr; 27 29 28 30 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj); 29 31 30 31 32 32 if ( ppobj == NULL ) 33 return E_POINTER; 34 *ppobj = NULL; 33 35 34 36 ofs = 0; 35 37 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 } 38 if ( IsEqualGUID( &IID_IUnknown, riid ) ) 39 { 40 TRACE("IID_IUnknown - returns inner object.\n"); 41 } 42 else 43 { 44 for ( dwIndex = 0; dwIndex < This->dwEntries; dwIndex++ ) 45 { 46 if ( IsEqualGUID( This->pEntries[dwIndex].piid, riid ) ) 47 { 48 ofs = This->pEntries[dwIndex].ofsVTPtr; 49 break; 50 } 51 } 52 if ( dwIndex == This->dwEntries ) 53 { 54 hr = E_NOINTERFACE; 56 55 57 *ppobj = (LPVOID)(((char*)This) + ofs); 58 IUnknown_AddRef((IUnknown*)(*ppobj)); 56 /* delegation */ 57 pDelegation = This->pDelegationFirst; 58 while ( pDelegation != NULL ) 59 { 60 hr = (*pDelegation->pOnQueryInterface)( iface, riid, ppobj ); 61 if ( hr != E_NOINTERFACE ) 62 break; 63 pDelegation = pDelegation->pNext; 64 } 59 65 60 return S_OK; 66 if ( hr == E_NOINTERFACE ) 67 { 68 FIXME("unknown interface: %s\n",debugstr_guid(riid)); 69 } 70 71 return hr; 72 } 73 } 74 75 *ppobj = (LPVOID)(((char*)This) + ofs); 76 IUnknown_AddRef((IUnknown*)(*ppobj)); 77 78 return S_OK; 61 79 } 62 80 … … 64 82 IUnknown_fnAddRef(IUnknown* iface) 65 83 { 66 84 ICOM_THIS(QUARTZ_IUnkImpl,iface); 67 85 68 86 TRACE("(%p)->()\n",This); 69 87 70 return ++(This->ref);88 return InterlockedExchangeAdd(&(This->ref),1) + 1; 71 89 } 72 90 … … 74 92 IUnknown_fnRelease(IUnknown* iface) 75 93 { 76 ICOM_THIS(QUARTZ_IUnkImpl,iface); 94 ICOM_THIS(QUARTZ_IUnkImpl,iface); 95 LONG ref; 77 96 78 TRACE("(%p)->()\n",This); 79 if ( (--(This->ref)) > 0 ) 80 return This->ref; 97 TRACE("(%p)->()\n",This); 98 ref = InterlockedExchangeAdd(&(This->ref),-1) - 1; 99 if ( ref > 0 ) 100 return (ULONG)ref; 81 101 82 QUARTZ_FreeObj(This); 102 if ( This->pOnFinalRelease != NULL ) 103 (*(This->pOnFinalRelease))(iface); 83 104 84 return 0; 105 QUARTZ_FreeObj(This); 106 107 return 0; 85 108 } 86 109 87 110 static ICOM_VTABLE(IUnknown) iunknown = 88 111 { 89 90 91 92 93 112 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE 113 /* IUnknown fields */ 114 IUnknown_fnQueryInterface, 115 IUnknown_fnAddRef, 116 IUnknown_fnRelease, 94 117 }; 95 118 … … 97 120 void QUARTZ_IUnkInit( QUARTZ_IUnkImpl* pImpl, IUnknown* punkOuter ) 98 121 { 99 122 TRACE("(%p)\n",pImpl); 100 123 101 ICOM_VTBL(pImpl) = &iunknown; 102 pImpl->pEntries = NULL; 103 pImpl->dwEntries = 0; 104 pImpl->ref = 1; 105 pImpl->punkControl = (IUnknown*)pImpl; 124 ICOM_VTBL(pImpl) = &iunknown; 125 pImpl->pEntries = NULL; 126 pImpl->dwEntries = 0; 127 pImpl->pDelegationFirst = NULL; 128 pImpl->pOnFinalRelease = NULL; 129 pImpl->ref = 1; 130 pImpl->punkControl = (IUnknown*)pImpl; 106 131 107 /* for delegation. */108 109 132 /* for implementing aggregation. */ 133 if ( punkOuter != NULL ) 134 pImpl->punkControl = punkOuter; 110 135 } 111 136 137 void QUARTZ_IUnkAddDelegation( 138 QUARTZ_IUnkImpl* pImpl, QUARTZ_IFDelegation* pDelegation ) 139 { 140 pDelegation->pNext = pImpl->pDelegationFirst; 141 pImpl->pDelegationFirst = pDelegation; 142 } 143
Note:
See TracChangeset
for help on using the changeset viewer.