www.pudn.com > GEOPC_modified_2005621145656299.rar > implconnect.h, change:2005-04-06,size:6130b


 
#include <olectl.h> 
 
#define BEGIN_INOUT_PARAMS() \ 
	{ HRESULT _hr = S_OK; 
#define OUT_PARAM(ptr) \ 
	if (ptr) *ptr = 0; else _hr = E_POINTER; 
#define IN_PARAM(ptr) \ 
	if (NULL == ptr) _hr = E_POINTER; 
#define END_INOUT_PARAMS(_hrReturn) \ 
	if (FAILED(_hr)) return _hrReturn; } 
 
#define SAFE_RELEASE(pInterface) \ 
	pInterface->Release(); \ 
	pInterface = NULL; 
 
class CImpIEnumConnectionPoints : public IEnumConnectionPoints 
{ 
public: 
	CImpIEnumConnectionPoints(LPUNKNOWN pUnk, ULONG, IConnectionPoint **); 
    ~CImpIEnumConnectionPoints(void); 
 
	// 
	// IUnknown methods 
	// 
 
	STDMETHODIMP         QueryInterface(REFIID iid, LPVOID *ppv); 
	STDMETHODIMP_(ULONG) AddRef(void); 
	STDMETHODIMP_(ULONG) Release(void); 
 
 
	// 
	// IEnumConnectionPoints interface methods 
	// 
 
	STDMETHODIMP         Next(ULONG cRequested, IConnectionPoint **ppCP, ULONG *pcFetched); 
         
	STDMETHODIMP         Skip (ULONG celt); 
         
	STDMETHODIMP         Reset(void); 
         
	STDMETHODIMP         Clone(IEnumConnectionPoints **ppEnum); 
 
private: 
	// 
	// Member Variables 
	// 
 
	long				m_lRefCount;		// Object reference count 
	LPUNKNOWN			m_pUnkOuter;		// IUnknown for ref counting 
	ULONG				m_lCurrentElem;		// Current element 
	ULONG				m_lNumElem;			// Number of elements in us 
	IConnectionPoint	**m_ppCPList;		// list of interfaces 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// 
//	Implementation class for the IEnumConnections Interface 
// 
///////////////////////////////////////////////////////////////////////////// 
class CImpIEnumConnections : public IEnumConnections 
{ 
public: 
	CImpIEnumConnections(IUnknown *pUnkOuter, ULONG lCount, CONNECTDATA *pConnectData); 
	~CImpIEnumConnections(void); 
 
	// 
	// IUnknown methods 
	// 
 
	STDMETHODIMP         QueryInterface(REFIID riid, LPVOID *ppv); 
	STDMETHODIMP_(ULONG) AddRef(void); 
	STDMETHODIMP_(ULONG) Release(void); 
 
 
	// 
	// IEnumConnections interface methods 
	// 
 
	STDMETHODIMP		Next(ULONG cRequested, CONNECTDATA *pCD, ULONG *pcFetched); 
 
	STDMETHODIMP		Skip(ULONG celt); 
 
	STDMETHODIMP		Reset(void); 
 
	STDMETHODIMP		Clone(IEnumConnections **ppEnum); 
 
private: 
	// 
	// Member Variables 
	// 
 
	long				m_lRefCount;		// Object reference count 
	LPUNKNOWN			m_pUnkOuter;		// IUnknown for ref counting 
	ULONG				m_lCurrentElem;		// Current element 
	ULONG				m_lNumElem;			// Number of elements in us 
	CONNECTDATA			*m_pDataList;		// Connection list 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// 
//	Implementation class for the IConnectionPoint Interface 
// 
///////////////////////////////////////////////////////////////////////////// 
class CImpIConnectionPoint : public IConnectionPoint 
{ 
public: 
	CImpIConnectionPoint(IN IUnknown *pUnk, IN IID iid, 
		IN OPTIONAL HRESULT (*lpfnAdviseNotify)(IUnknown *, BOOL) = NULL); 
	~CImpIConnectionPoint(void); 
 
	// 
	// IUnknown methods (partial delegation to parent) 
	// 
 
	STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);	// Implemented locally 
	//	mvs01242001 - Now implemented in object 
	//	Do not pass this along to the outer object, else we will end up in  
	//	a circular object count loop. Just decrement the refrence count. 
//	STDMETHODIMP_(ULONG) AddRef(void)						{ return m_pUnkOuter->AddRef();} 
//	STDMETHODIMP_(ULONG) Release(void)						{ return m_pUnkOuter->Release();} 
	STDMETHODIMP_(ULONG) AddRef(void); 
	STDMETHODIMP_(ULONG) Release(void); 
 
 
	// 
	// IConnectionPoint interface methods 
	// 
 
	STDMETHODIMP		GetConnectionInterface(IID *pIID); 
 
	STDMETHODIMP		GetConnectionPointContainer(IConnectionPointContainer **ppCPC); 
 
	STDMETHODIMP		Advise(IUnknown *pUnkSink, DWORD *pdwCookie); 
 
	STDMETHODIMP		Unadvise(DWORD dwCookie); 
 
	STDMETHODIMP		EnumConnections(IEnumConnections **ppEnum); 
 
 
	// 
	// Helpers used to determine is the client has registered for callbacks 
	// 
 
	BOOL				IsAdvised(void) const				{ return (m_pCallBack ? TRUE : FALSE); } 
 
	BOOL				GetEnabled(void) const				{ return m_bEnabled; } 
	void				SetEnabled(BOOL bEnabled); 
 
 
	// 
	// Thread management 
	// 
 
	void				Lock  (void)		{ EnterCriticalSection(&m_Lock); } 
	void				UnLock(void)		{ LeaveCriticalSection(&m_Lock); } 
 
private: 
 
	void				CleanupSinks(void); 
 
public: 
 
	// 
	// Callback interface 
	// 
 
	IID					m_iid; 
	IUnknown			*m_pCallBack; 
 
private: 
	// 
	// Member Variables 
	// 
 
	LPUNKNOWN			m_pUnkOuter;	// Pointer to outer or controlling IUnknown 
	HRESULT				(*m_lpfnAdviseNotify)(IUnknown *, BOOL);	// Callback function 
 
	BOOL				m_bEnabled;		// Flag indicating if OnDataChange() calls are active 
 
	CRITICAL_SECTION	m_Lock;			// Connection point critical section 
	//	mvs01242001 - keep a local refrence count. 
	long				m_lRefCount;		// Object reference count 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// 
//	Implementation class for the IConnectionPointContainer Interface 
// 
///////////////////////////////////////////////////////////////////////////// 
class CImpIConnectionPointContainer : public IConnectionPointContainer 
{ 
public: 
	CImpIConnectionPointContainer(IUnknown *pUnk, CImpIConnectionPoint **ppCPList, long lCount = 1); 
	~CImpIConnectionPointContainer(void); 
 
	// 
	// IUnknown methods (delegates to parent) 
	// 
 
	STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)	{ return m_pUnkOuter->QueryInterface(riid, ppv);} 
	STDMETHODIMP_(ULONG) AddRef(void)						{ return m_pUnkOuter->AddRef();} 
	STDMETHODIMP_(ULONG) Release(void)						{ return m_pUnkOuter->Release();} 
 
 
	// 
	// IConnectionPointContainer interface methods 
	// 
 
	STDMETHODIMP		EnumConnectionPoints(IEnumConnectionPoints **ppEnum); 
 
	STDMETHODIMP		FindConnectionPoint(REFIID riid, IConnectionPoint **ppCP); 
 
private: 
	// 
	// Member Variables 
	// 
 
	LPUNKNOWN				m_pUnkOuter;	// Pointer to outer or controlling IUnknown 
	CImpIConnectionPoint	**m_ppCPList;	// Pointer to connection point object list 
	long					m_lCount;		// Object list size 
};