source: trunk/src/quartz/iunk.c@ 6563

Last change on this file since 6563 was 6563, checked in by sandervl, 24 years ago

created

File size: 1.7 KB
Line 
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"
14DEFAULT_DEBUG_CHANNEL(quartz);
15
16#include "quartz_private.h"
17#include "iunk.h"
18
19
20static HRESULT WINAPI
21IUnknown_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 for ( dwIndex = 0; dwIndex < This->dwEntries; dwIndex++ )
35 {
36 if ( IsEqualGUID( This->pEntries[dwIndex].piid, riid ) )
37 {
38 ofs = This->pEntries[dwIndex].ofsVTPtr;
39 break;
40 }
41 }
42
43 if ( dwIndex == This->dwEntries )
44 {
45 if ( !IsEqualGUID( &IID_IUnknown, riid ) )
46 {
47 TRACE("unknown interface: %s\n",debugstr_guid(riid));
48 return E_NOINTERFACE;
49 }
50 }
51
52 *ppobj = (LPVOID)(((char*)This) + ofs);
53 IUnknown_AddRef(iface);
54
55 return S_OK;
56}
57
58static ULONG WINAPI
59IUnknown_fnAddRef(IUnknown* iface)
60{
61 ICOM_THIS(QUARTZ_IUnkImpl,iface);
62
63 TRACE("(%p)->()\n",This);
64
65 return ++(This->ref);
66}
67
68static ULONG WINAPI
69IUnknown_fnRelease(IUnknown* iface)
70{
71 ICOM_THIS(QUARTZ_IUnkImpl,iface);
72
73 TRACE("(%p)->()\n",This);
74 if ( (--(This->ref)) > 0 )
75 return This->ref;
76
77 QUARTZ_FreeObj(This);
78
79 return 0;
80}
81
82static ICOM_VTABLE(IUnknown) iunknown =
83{
84 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
85 /* IUnknown fields */
86 IUnknown_fnQueryInterface,
87 IUnknown_fnAddRef,
88 IUnknown_fnRelease,
89};
90
91
92void QUARTZ_IUnkInit( QUARTZ_IUnkImpl* pImpl )
93{
94 TRACE("(%p)\n",pImpl);
95
96 ICOM_VTBL(pImpl) = &iunknown;
97 pImpl->pEntries = NULL;
98 pImpl->dwEntries = 0;
99 pImpl->ref = 1;
100}
Note: See TracBrowser for help on using the repository browser.