Click here to Skip to main content
15,883,981 members
Articles / Desktop Programming / ATL

An ATL Component in C++ that fires COM events

Rate me:
Please Sign up or sign in to vote.
4.19/5 (12 votes)
14 Jun 20048 min read 88.3K   3K   38  
A COM component that implements interprocess communication, and illustrates firing events to a COM container such as Visual Basic
#pragma once

template<class T>
class CProxy_IIPCEvents :
	public IConnectionPointImpl<T, &__uuidof(_IIPCEvents)>
{
public:
	HRESULT Fire_MessageReceived( LONG  lData,  BSTR  sMsg,  LONG  lLenght)
	{
		HRESULT hr = S_OK;
		T * pThis = static_cast<T *>(this);
		int cConnections = m_vec.GetSize();

		for (int iConnection = 0; iConnection < cConnections; iConnection++)
		{
			pThis->Lock();
			CComPtr<IUnknown> punkConnection = m_vec.GetAt(iConnection);
			pThis->Unlock();

			IDispatch * pConnection = static_cast<IDispatch *>(punkConnection.p);

			if (pConnection)
			{
				CComVariant avarParams[3];
				avarParams[2] = lData;	avarParams[2].vt = VT_I4;
				avarParams[1] = sMsg;	avarParams[1].vt = VT_BSTR;
				avarParams[0] = lLenght;	avarParams[0].vt = VT_I4;
				DISPPARAMS params = { avarParams, NULL, 3, 0 };
				hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &params, NULL, NULL, NULL);
			}
		}
		return hr;
	}
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
I am a Surgeon by trade, but have been programming since I could reach the keyboard! I run a surgical website and am MD of a company that writes Surgical Software.

Comments and Discussions