4 * Copyright 2009 Andrew Hill <ash77@reactos.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 template <class Base
, const IID
*piid
, class T
, class Copy
, class ThreadModel
= CComObjectThreadModel
>
30 #define DECLARE_CLASSFACTORY_EX(cf) typedef ATL::CComCreator<ATL::CComObjectCached<cf> > _ClassFactoryCreatorClass;
31 #define DECLARE_CLASSFACTORY() DECLARE_CLASSFACTORY_EX(ATL::CComClassFactory)
33 class CComObjectRootBase
51 HRESULT
_AtlFinalConstruct()
56 HRESULT
FinalConstruct()
61 void InternalFinalConstructAddRef()
65 void InternalFinalConstructRelease()
73 static void WINAPI
ObjectMain(bool)
77 static const struct _ATL_CATMAP_ENTRY
*GetCategoryMap()
82 static HRESULT WINAPI
InternalQueryInterface(void *pThis
, const _ATL_INTMAP_ENTRY
*pEntries
, REFIID iid
, void **ppvObject
)
84 return AtlInternalQueryInterface(pThis
, pEntries
, iid
, ppvObject
);
89 template <class ThreadModel
>
90 class CComObjectRootEx
: public CComObjectRootBase
93 typename
ThreadModel::AutoDeleteCriticalSection m_critsec
;
99 ULONG
InternalAddRef()
101 ATLASSERT(m_dwRef
>= 0);
102 return ThreadModel::Increment(reinterpret_cast<int *>(&m_dwRef
));
105 ULONG
InternalRelease()
107 ATLASSERT(m_dwRef
> 0);
108 return ThreadModel::Decrement(reinterpret_cast<int *>(&m_dwRef
));
121 HRESULT
_AtlInitialConstruct()
123 return m_critsec
.Init();
127 template <class Base
>
128 class CComObject
: public Base
131 CComObject(void * = NULL
)
136 virtual ~CComObject()
138 CComObject
<Base
> *pThis
;
140 pThis
= reinterpret_cast<CComObject
<Base
> *>(this);
141 pThis
->FinalRelease();
142 _pAtlModule
->Unlock();
145 STDMETHOD_(ULONG
, AddRef
)()
147 CComObject
<Base
> *pThis
;
149 pThis
= reinterpret_cast<CComObject
<Base
> *>(this);
150 return pThis
->InternalAddRef();
153 STDMETHOD_(ULONG
, Release
)()
155 CComObject
<Base
> *pThis
;
158 pThis
= reinterpret_cast<CComObject
<Base
> *>(this);
159 l
= pThis
->InternalRelease();
165 STDMETHOD(QueryInterface
)(REFIID iid
, void **ppvObject
)
167 CComObject
<Base
> *pThis
;
169 pThis
= reinterpret_cast<CComObject
<Base
> *>(this);
170 return pThis
->_InternalQueryInterface(iid
, ppvObject
);
173 static HRESULT WINAPI
CreateInstance(CComObject
<Base
> **pp
)
175 CComObject
<Base
> *newInstance
;
178 ATLASSERT(pp
!= NULL
);
182 hResult
= E_OUTOFMEMORY
;
184 ATLTRY(newInstance
= new CComObject
<Base
>())
185 if (newInstance
!= NULL
)
187 newInstance
->SetVoid(NULL
);
188 newInstance
->InternalFinalConstructAddRef();
189 hResult
= newInstance
->_AtlInitialConstruct();
190 if (SUCCEEDED(hResult
))
191 hResult
= newInstance
->FinalConstruct();
192 if (SUCCEEDED(hResult
))
193 hResult
= newInstance
->_AtlFinalConstruct();
194 newInstance
->InternalFinalConstructRelease();
208 template <HRESULT hResult
>
209 class CComFailCreator
212 static HRESULT WINAPI
CreateInstance(void *, REFIID
, LPVOID
*ppv
)
214 ATLASSERT(ppv
!= NULL
);
227 static HRESULT WINAPI
CreateInstance(void *pv
, REFIID riid
, LPVOID
*ppv
)
232 ATLASSERT(ppv
!= NULL
);
237 hResult
= E_OUTOFMEMORY
;
239 ATLTRY(newInstance
= new T1())
240 if (newInstance
!= NULL
)
242 newInstance
->SetVoid(pv
);
243 newInstance
->InternalFinalConstructAddRef();
244 hResult
= newInstance
->_AtlInitialConstruct();
245 if (SUCCEEDED(hResult
))
246 hResult
= newInstance
->FinalConstruct();
247 if (SUCCEEDED(hResult
))
248 hResult
= newInstance
->_AtlFinalConstruct();
249 newInstance
->InternalFinalConstructRelease();
250 if (SUCCEEDED(hResult
))
251 hResult
= newInstance
->QueryInterface(riid
, ppv
);
262 template <class T1
, class T2
>
266 static HRESULT WINAPI
CreateInstance(void *pv
, REFIID riid
, LPVOID
*ppv
)
268 ATLASSERT(ppv
!= NULL
&& ppv
!= NULL
);
271 return T1::CreateInstance(NULL
, riid
, ppv
);
273 return T2::CreateInstance(pv
, riid
, ppv
);
277 template <class Base
>
278 class CComObjectCached
: public Base
281 CComObjectCached(void * = NULL
)
285 STDMETHOD_(ULONG
, AddRef
)()
287 CComObjectCached
<Base
> *pThis
;
290 pThis
= reinterpret_cast<CComObjectCached
<Base
>*>(this);
291 newRefCount
= pThis
->InternalAddRef();
292 if (newRefCount
== 2)
297 STDMETHOD_(ULONG
, Release
)()
299 CComObjectCached
<Base
> *pThis
;
302 pThis
= reinterpret_cast<CComObjectCached
<Base
>*>(this);
303 newRefCount
= pThis
->InternalRelease();
304 if (newRefCount
== 0)
306 else if (newRefCount
== 1)
307 _pAtlModule
->Unlock();
311 STDMETHOD(QueryInterface
)(REFIID iid
, void **ppvObject
)
313 CComObjectCached
<Base
> *pThis
;
315 pThis
= reinterpret_cast<CComObjectCached
<Base
>*>(this);
316 return pThis
->_InternalQueryInterface(iid
, ppvObject
);
320 #define BEGIN_COM_MAP(x) \
322 typedef x _ComMapClass; \
323 HRESULT _InternalQueryInterface(REFIID iid, void **ppvObject) \
325 return InternalQueryInterface(this, _GetEntries(), iid, ppvObject); \
327 const static ATL::_ATL_INTMAP_ENTRY *WINAPI _GetEntries() \
329 static const ATL::_ATL_INTMAP_ENTRY _entries[] = {
331 #define END_COM_MAP() \
336 virtual ULONG STDMETHODCALLTYPE AddRef() = 0; \
337 virtual ULONG STDMETHODCALLTYPE Release() = 0; \
338 STDMETHOD(QueryInterface)(REFIID, void **) = 0;
340 #define COM_INTERFACE_ENTRY_IID(iid, x) \
341 {&iid, offsetofclass(x, _ComMapClass), _ATL_SIMPLEMAPENTRY},
343 #define COM_INTERFACE_ENTRY2_IID(iid, x, x2) \
345 reinterpret_cast<DWORD_PTR>(static_cast<x *>(static_cast<x2 *>(reinterpret_cast<_ComMapClass *>(_ATL_PACKING)))) - _ATL_PACKING, \
346 _ATL_SIMPLEMAPENTRY},
348 #define COM_INTERFACE_ENTRY_BREAK(x) \
351 _Break}, // Break is a function that issues int 3.
353 #define COM_INTERFACE_ENTRY_NOINTERFACE(x) \
356 _NoInterface}, // NoInterface returns E_NOINTERFACE.
358 #define COM_INTERFACE_ENTRY_FUNC(iid, dw, func) \
363 #define COM_INTERFACE_ENTRY_FUNC_BLIND(dw, func) \
368 #define COM_INTERFACE_ENTRY_CHAIN(classname) \
370 reinterpret_cast<DWORD>(&_CComChainData<classname, _ComMapClass>::data), \
373 #define DECLARE_REGISTRY_RESOURCEID(x)\
374 static HRESULT WINAPI UpdateRegistry(BOOL bRegister)\
376 return ATL::_pAtlModule->UpdateRegistryFromResource(x, bRegister); \
379 #define DECLARE_NOT_AGGREGATABLE(x) \
381 typedef ATL::CComCreator2<ATL::CComCreator<ATL::CComObject<x> >, ATL::CComFailCreator<CLASS_E_NOAGGREGATION> > _CreatorClass;
383 #define DECLARE_AGGREGATABLE(x) \
385 typedef CComCreator2<CComCreator<CComObject<x> >, CComCreator<CComAggObject<x> > > _CreatorClass;
387 #define DECLARE_ONLY_AGGREGATABLE(x) \
389 typedef CComCreator2<CComFailCreator<E_FAIL>, CComCreator<CComAggObject<x> > > _CreatorClass;
391 #define DECLARE_POLY_AGGREGATABLE(x) \
393 typedef CComCreator<CComPolyObject<x> > _CreatorClass;
395 #define DECLARE_GET_CONTROLLING_UNKNOWN() \
397 virtual IUnknown *GetControllingUnknown() \
399 return GetUnknown(); \
402 #define DECLARE_PROTECT_FINAL_CONSTRUCT() \
403 void InternalFinalConstructAddRef() \
407 void InternalFinalConstructRelease() \
412 #define BEGIN_OBJECT_MAP(x) static ATL::_ATL_OBJMAP_ENTRY x[] = {
414 #define END_OBJECT_MAP() {NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL}};
416 #define OBJECT_ENTRY(clsid, class) \
419 class::UpdateRegistry, \
420 class::_ClassFactoryCreatorClass::CreateInstance, \
421 class::_CreatorClass::CreateInstance, \
424 class::GetObjectDescription, \
425 class::GetCategoryMap, \
428 class CComClassFactory
:
429 public IClassFactory
,
430 public CComObjectRootEx
<CComGlobalsThreadModel
>
433 _ATL_CREATORFUNC
*m_pfnCreateInstance
;
435 STDMETHOD(CreateInstance
)(LPUNKNOWN pUnkOuter
, REFIID riid
, void **ppvObj
)
439 ATLASSERT(m_pfnCreateInstance
!= NULL
);
445 if (pUnkOuter
!= NULL
&& InlineIsEqualUnknown(riid
) == FALSE
)
446 hResult
= CLASS_E_NOAGGREGATION
;
448 hResult
= m_pfnCreateInstance(pUnkOuter
, riid
, ppvObj
);
452 STDMETHOD(LockServer
)(BOOL fLock
)
457 _pAtlModule
->Unlock();
461 void SetVoid(void *pv
)
463 m_pfnCreateInstance
= (_ATL_CREATORFUNC
*)pv
;
466 BEGIN_COM_MAP(CComClassFactory
)
467 COM_INTERFACE_ENTRY_IID(IID_IClassFactory
, IClassFactory
)
471 template <class T
, const CLSID
*pclsid
= &CLSID_NULL
>
475 DECLARE_CLASSFACTORY()
477 static LPCTSTR WINAPI
GetObjectDescription()
487 static HRESULT
copy(T
*pTo
, const T
*pFrom
)
489 memcpy(pTo
, pFrom
, sizeof(T
));
493 static void init(T
*)
497 static void destroy(T
*)
503 class _Copy
<CONNECTDATA
>
506 static HRESULT
copy(CONNECTDATA
*pTo
, const CONNECTDATA
*pFrom
)
514 static void init(CONNECTDATA
*)
518 static void destroy(CONNECTDATA
*p
)
529 static HRESULT
copy(T
**pTo
, T
**pFrom
)
537 static void init(T
**)
541 static void destroy(T
**p
)
551 AtlFlagTakeOwnership
= 2, // BitOwn
552 AtlFlagCopy
= 3 // BitOwn | BitCopy
555 template <class Base
, const IID
*piid
, class T
, class Copy
>
556 class CComEnumImpl
: public Base
559 typedef CComObject
<CComEnum
<Base
, piid
, T
, Copy
> > enumeratorClass
;
561 CComPtr
<IUnknown
> m_spUnk
;
575 virtual ~CComEnumImpl()
579 if ((m_dwFlags
& BitOwn
) != 0)
581 for (x
= m_begin
; x
!= m_end
; x
++)
587 HRESULT
Init(T
*begin
, T
*end
, IUnknown
*pUnk
, CComEnumFlags flags
= AtlFlagNoCopy
)
595 if (flags
== AtlFlagCopy
)
597 ATLTRY(newBuffer
= new T
[end
- begin
])
598 if (newBuffer
== NULL
)
599 return E_OUTOFMEMORY
;
601 for (sourcePtr
= begin
; sourcePtr
!= end
; sourcePtr
++)
604 hResult
= Copy::copy(destPtr
, sourcePtr
);
607 cleanupPtr
= m_begin
;
608 while (cleanupPtr
< destPtr
)
609 Copy::destroy(cleanupPtr
++);
616 m_end
= m_begin
+ (end
- begin
);
629 STDMETHOD(Next
)(ULONG celt
, T
*rgelt
, ULONG
*pceltFetched
)
636 if (pceltFetched
!= NULL
)
640 if (rgelt
== NULL
|| (celt
!= 1 && pceltFetched
== NULL
))
642 if (m_begin
== NULL
|| m_end
== NULL
|| m_iter
== NULL
)
645 numAvailable
= static_cast<ULONG
>(m_end
- m_iter
);
646 if (celt
< numAvailable
)
649 numToFetch
= numAvailable
;
650 if (pceltFetched
!= NULL
)
651 *pceltFetched
= numToFetch
;
653 while (numToFetch
!= 0)
655 hResult
= Copy::copy(rgeltTemp
, m_iter
);
658 while (rgelt
< rgeltTemp
)
659 Copy::destroy(rgelt
++);
660 if (pceltFetched
!= NULL
)
668 if (numAvailable
< celt
)
673 STDMETHOD(Skip
)(ULONG celt
)
681 numAvailable
= static_cast<ULONG
>(m_end
- m_iter
);
682 if (celt
< numAvailable
)
685 numToSkip
= numAvailable
;
687 if (numAvailable
< celt
)
698 STDMETHOD(Clone
)(Base
**ppEnum
)
700 enumeratorClass
*newInstance
;
707 hResult
= enumeratorClass::CreateInstance(&newInstance
);
708 if (SUCCEEDED(hResult
))
710 hResult
= newInstance
->Init(m_begin
, m_end
, (m_dwFlags
& BitOwn
) ? this : m_spUnk
);
711 if (SUCCEEDED(hResult
))
713 newInstance
->m_iter
= m_iter
;
714 hResult
= newInstance
->_InternalQueryInterface(*piid
, (void **)ppEnum
);
731 template <class Base
, const IID
*piid
, class T
, class Copy
, class ThreadModel
>
733 public CComEnumImpl
<Base
, piid
, T
, Copy
>,
734 public CComObjectRootEx
<ThreadModel
>
737 typedef CComEnum
<Base
, piid
, T
, Copy
> _CComEnum
;
738 typedef CComEnumImpl
<Base
, piid
, T
, Copy
> _CComEnumBase
;
740 BEGIN_COM_MAP(_CComEnum
)
741 COM_INTERFACE_ENTRY_IID(*piid
, _CComEnumBase
)
745 #ifndef _DEFAULT_VECTORLENGTH
746 #define _DEFAULT_VECTORLENGTH 4
749 class CComDynamicUnkArray
755 CComDynamicUnkArray()
761 ~CComDynamicUnkArray()
773 return &m_ppUnk
[m_nSize
];
776 IUnknown
*GetAt(int nIndex
)
778 ATLASSERT(nIndex
>= 0 && nIndex
< m_nSize
);
779 if (nIndex
>= 0 && nIndex
< m_nSize
)
780 return m_ppUnk
[nIndex
];
785 IUnknown
*WINAPI
GetUnknown(DWORD dwCookie
)
787 ATLASSERT(dwCookie
!= 0 && dwCookie
<= static_cast<DWORD
>(m_nSize
));
788 if (dwCookie
!= 0 && dwCookie
<= static_cast<DWORD
>(m_nSize
))
789 return GetAt(dwCookie
- 1);
794 DWORD WINAPI
GetCookie(IUnknown
**ppFind
)
799 ATLASSERT(ppFind
!= NULL
&& *ppFind
!= NULL
);
800 if (ppFind
!= NULL
&& *ppFind
!= NULL
)
803 for (x
= begin(); x
< end(); x
++)
813 DWORD
Add(IUnknown
*pUnk
)
820 ATLASSERT(pUnk
!= NULL
);
823 newSize
= _DEFAULT_VECTORLENGTH
* sizeof(IUnknown
*);
824 ATLTRY(newArray
= reinterpret_cast<IUnknown
**>(malloc(newSize
)));
825 if (newArray
== NULL
)
827 memset(newArray
, 0, newSize
);
829 m_nSize
= _DEFAULT_VECTORLENGTH
;
832 for (x
= begin(); x
< end(); x
++)
841 newSize
= m_nSize
* 2;
842 newArray
= reinterpret_cast<IUnknown
**>(realloc(m_ppUnk
, newSize
* sizeof(IUnknown
*)));
843 if (newArray
== NULL
)
845 memset(&m_ppUnk
[m_nSize
], 0, (newSize
- m_nSize
) * sizeof(IUnknown
*));
848 m_ppUnk
[m_nSize
] = pUnk
;
852 BOOL
Remove(DWORD dwCookie
)
856 index
= dwCookie
- 1;
857 ATLASSERT(index
< dwCookie
&& index
< static_cast<DWORD
>(m_nSize
));
858 if (index
< dwCookie
&& index
< static_cast<DWORD
>(m_nSize
) && m_ppUnk
[index
] != NULL
)
860 m_ppUnk
[index
] = NULL
;
868 struct _ATL_CONNMAP_ENTRY
873 template <const IID
*piid
>
877 STDMETHOD(_LocCPQueryInterface
)(REFIID riid
, void **ppvObject
) = 0;
878 virtual ULONG STDMETHODCALLTYPE
AddRef() = 0;
879 virtual ULONG STDMETHODCALLTYPE
Release() = 0;
882 template<class T
, const IID
*piid
, class CDV
= CComDynamicUnkArray
>
883 class IConnectionPointImpl
: public _ICPLocator
<piid
>
885 typedef CComEnum
<IEnumConnections
, &IID_IEnumConnections
, CONNECTDATA
, _Copy
<CONNECTDATA
> > CComEnumConnections
;
889 ~IConnectionPointImpl()
893 for (x
= m_vec
.begin(); x
< m_vec
.end(); x
++)
898 STDMETHOD(_LocCPQueryInterface
)(REFIID riid
, void **ppvObject
)
900 IConnectionPointImpl
<T
, piid
, CDV
> *pThis
;
902 pThis
= reinterpret_cast<IConnectionPointImpl
<T
, piid
, CDV
>*>(this);
904 ATLASSERT(ppvObject
!= NULL
);
905 if (ppvObject
== NULL
)
908 if (InlineIsEqualGUID(riid
, IID_IConnectionPoint
) || InlineIsEqualUnknown(riid
))
917 return E_NOINTERFACE
;
921 STDMETHOD(GetConnectionInterface
)(IID
*piid2
)
929 STDMETHOD(GetConnectionPointContainer
)(IConnectionPointContainer
**ppCPC
)
933 pThis
= static_cast<T
*>(this);
934 return pThis
->QueryInterface(IID_IConnectionPointContainer
, reinterpret_cast<void **>(ppCPC
));
937 STDMETHOD(Advise
)(IUnknown
*pUnkSink
, DWORD
*pdwCookie
)
939 IUnknown
*adviseTarget
;
943 if (pdwCookie
!= NULL
)
945 if (pUnkSink
== NULL
|| pdwCookie
== NULL
)
947 GetConnectionInterface(&interfaceID
); // can't fail
948 hResult
= pUnkSink
->QueryInterface(interfaceID
, reinterpret_cast<void **>(&adviseTarget
));
949 if (SUCCEEDED(hResult
))
951 *pdwCookie
= m_vec
.Add(adviseTarget
);
956 adviseTarget
->Release();
957 hResult
= CONNECT_E_ADVISELIMIT
;
960 else if (hResult
== E_NOINTERFACE
)
961 hResult
= CONNECT_E_CANNOTCONNECT
;
965 STDMETHOD(Unadvise
)(DWORD dwCookie
)
967 IUnknown
*adviseTarget
;
970 adviseTarget
= m_vec
.GetUnknown(dwCookie
);
971 if (m_vec
.Remove(dwCookie
))
973 if (adviseTarget
!= NULL
)
974 adviseTarget
->Release();
978 hResult
= CONNECT_E_NOCONNECTION
;
982 STDMETHOD(EnumConnections
)(IEnumConnections
**ppEnum
)
984 CComObject
<CComEnumConnections
> *newEnumerator
;
985 CONNECTDATA
*itemBuffer
;
986 CONNECTDATA
*itemBufferEnd
;
990 ATLASSERT(ppEnum
!= NULL
);
995 ATLTRY(itemBuffer
= new CONNECTDATA
[m_vec
.end() - m_vec
.begin()])
996 if (itemBuffer
== NULL
)
997 return E_OUTOFMEMORY
;
998 itemBufferEnd
= itemBuffer
;
999 for (x
= m_vec
.begin(); x
< m_vec
.end(); x
++)
1004 itemBufferEnd
->pUnk
= *x
;
1005 itemBufferEnd
->dwCookie
= m_vec
.GetCookie(x
);
1009 ATLTRY(newEnumerator
= new CComObject
<CComEnumConnections
>)
1010 if (newEnumerator
== NULL
)
1011 return E_OUTOFMEMORY
;
1012 newEnumerator
->Init(itemBuffer
, itemBufferEnd
, NULL
, AtlFlagTakeOwnership
); // can't fail
1013 hResult
= newEnumerator
->_InternalQueryInterface(IID_IEnumConnections
, (void **)ppEnum
);
1014 if (FAILED(hResult
))
1015 delete newEnumerator
;
1021 class IConnectionPointContainerImpl
: public IConnectionPointContainer
1023 typedef const _ATL_CONNMAP_ENTRY
* (*handlerFunctionType
)(int *);
1024 typedef CComEnum
<IEnumConnectionPoints
, &IID_IEnumConnectionPoints
, IConnectionPoint
*, _CopyInterface
<IConnectionPoint
> >
1025 CComEnumConnectionPoints
;
1028 STDMETHOD(EnumConnectionPoints
)(IEnumConnectionPoints
**ppEnum
)
1030 const _ATL_CONNMAP_ENTRY
*entryPtr
;
1031 int connectionPointCount
;
1032 IConnectionPoint
**itemBuffer
;
1034 handlerFunctionType handlerFunction
;
1035 CComEnumConnectionPoints
*newEnumerator
;
1038 ATLASSERT(ppEnum
!= NULL
);
1043 entryPtr
= T::GetConnMap(&connectionPointCount
);
1044 ATLTRY(itemBuffer
= new IConnectionPoint
* [connectionPointCount
])
1045 if (itemBuffer
== NULL
)
1046 return E_OUTOFMEMORY
;
1049 while (entryPtr
->dwOffset
!= static_cast<DWORD_PTR
>(-1))
1051 if (entryPtr
->dwOffset
== static_cast<DWORD_PTR
>(-2))
1054 handlerFunction
= reinterpret_cast<handlerFunctionType
>(entryPtr
->dwOffset
);
1055 entryPtr
= handlerFunction(NULL
);
1059 itemBuffer
[destIndex
++] = reinterpret_cast<IConnectionPoint
*>((char *)this + entryPtr
->dwOffset
);
1064 ATLTRY(newEnumerator
= new CComObject
<CComEnumConnectionPoints
>)
1065 if (newEnumerator
== NULL
)
1067 delete [] itemBuffer
;
1068 return E_OUTOFMEMORY
;
1071 newEnumerator
->Init(&itemBuffer
[0], &itemBuffer
[destIndex
], NULL
, AtlFlagTakeOwnership
); // can't fail
1072 hResult
= newEnumerator
->QueryInterface(IID_IEnumConnectionPoints
, (void**)ppEnum
);
1073 if (FAILED(hResult
))
1074 delete newEnumerator
;
1078 STDMETHOD(FindConnectionPoint
)(REFIID riid
, IConnectionPoint
**ppCP
)
1081 const _ATL_CONNMAP_ENTRY
*entryPtr
;
1082 handlerFunctionType handlerFunction
;
1083 IConnectionPoint
*connectionPoint
;
1089 hResult
= CONNECT_E_NOCONNECTION
;
1090 entryPtr
= T::GetConnMap(NULL
);
1091 while (entryPtr
->dwOffset
!= static_cast<DWORD_PTR
>(-1))
1093 if (entryPtr
->dwOffset
== static_cast<DWORD_PTR
>(-2))
1096 handlerFunction
= reinterpret_cast<handlerFunctionType
>(entryPtr
->dwOffset
);
1097 entryPtr
= handlerFunction(NULL
);
1101 connectionPoint
= reinterpret_cast<IConnectionPoint
*>(reinterpret_cast<char *>(this) + entryPtr
->dwOffset
);
1102 if (SUCCEEDED(connectionPoint
->GetConnectionInterface(&interfaceID
)) && InlineIsEqualGUID(riid
, interfaceID
))
1104 *ppCP
= connectionPoint
;
1105 connectionPoint
->AddRef();
1116 #define BEGIN_CONNECTION_POINT_MAP(x) \
1117 typedef x _atl_conn_classtype; \
1118 static const ATL::_ATL_CONNMAP_ENTRY *GetConnMap(int *pnEntries) { \
1119 static const ATL::_ATL_CONNMAP_ENTRY _entries[] = {
1121 #define END_CONNECTION_POINT_MAP() \
1122 {(DWORD_PTR)-1} }; \
1124 *pnEntries = sizeof(_entries) / sizeof(ATL::_ATL_CONNMAP_ENTRY) - 1; \
1127 #define CONNECTION_POINT_ENTRY(iid) \
1128 {offsetofclass(ATL::_ICPLocator<&iid>, _atl_conn_classtype) - \
1129 offsetofclass(ATL::IConnectionPointContainerImpl<_atl_conn_classtype>, _atl_conn_classtype)},