Wrap com interfaces


I need advice in question - is my atl+com project going in correct way.

I have to use some two Com interfaces. One of them I need to implement. So I created it by atl wizzard, adding Simple ATL objects and implement interface one of them. I decided to encapsulate/wrap them by making next simple atl object with two functions - run and stop
Run function do CoCreateInstance on some interfaces, set some options and other things.
I decided to do so for simplicity ( I dont know am i right).

At the end I have made windows dll project that create instance of my interface and fire run function.
lavitzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pgnatyukCommented:
I read your question twice and do not know what to say and where you need an advice.
Anyway you need a test application to verify your com. So begin from it and you will see what and how can be improved in your com - you will use these interfaces and will understand what is convenient and what has to be updated.

Few useful links, if you need:
CodeProject. ATL Under the Hood
http://www.codeproject.com/KB/atl/atl_underthehood_.aspx

CodeProject. Beginner's Tutorial: COM/ATL Simple Project
http://www.codeproject.com/KB/atl/com_atl.aspx
0
lavitzAuthor Commented:
Its hard to explain.
ok, I have Com app that works fine. It have implemented ISensNetwork interface. Now I dont known how to add this to other part of project. I mean, how to catch this moment where event occurs. I have idea to deliver some function or object that will be fired in event function(ConnectionMade). But then, the whole logic is inside com part. I need some solution that throw this event outside my Com interface


class CMySensNetwork2 (...CUT...)
{
public:
	(...CUT...)
public:


	// ISensNetwork Methods
public:
	STDMETHOD(ConnectionMade)(BSTR bstrConnection, unsigned long ulType, SENS_QOCINFO * lpQOCInfo)
	{
		Beep(50, 80);
// this function execute when event occur
		return E_NOTIMPL;
	}
	STDMETHOD(ConnectionMadeNoQOCInfo)(BSTR bstrConnection, unsigned long ulType)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(ConnectionLost)(BSTR bstrConnection, unsigned long ulType)
	{

		return E_NOTIMPL;
	}
	STDMETHOD(DestinationReachable)(BSTR bstrDestination, BSTR bstrConnection, unsigned long ulType, SENS_QOCINFO * lpQOCInfo)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(DestinationReachableNoQOCInfo)(BSTR bstrDestination, BSTR bstrConnection, unsigned long ulType)
	{
		return E_NOTIMPL;
	}
};



// ---- in main.cpp


int _tmain(int argc, _TCHAR* argv[])
{

	// TODO: Add your implementation code here

	IEventSubscription*         pIEventSubscription = 0;
	static IEventSystem*		pIEventSystem =0;
	static IMySensNetwork2*		pSubscriber;


	HRESULT hr = 0;

	hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

	hr = CoCreateInstance(
		CLSID_MySensNetwork2,
							NULL,
							CLSCTX_SERVER,
							IID_IMySensNetwork2,
							(void**)&pSubscriber);

	//-----------------

	if (FAILED(hr))
	{
		return FALSE;
	}

	//----------------


	hr = CoCreateInstance( CLSID_CEventSystem, 0, CLSCTX_SERVER, IID_IEventSystem, (void**)&pIEventSystem);
	if (FAILED(hr))
	{
		return FALSE;
	}

	// Get a new IEventSubscription object.
		hr = CoCreateInstance(
								CLSID_CEventSubscription,
								NULL,
								CLSCTX_SERVER,
								IID_IEventSubscription,
								(LPVOID *) &pIEventSubscription
								);

		if (FAILED(hr))
		{		
			return FALSE;
		}

/*
		hr = pIEventSubscription->put_SubscriptionID(OLESTR("{cd1dcbd6-a14d-4823-a0d2-8473afde360f}"));
		if (FAILED(hr))
		{
			return FALSE;
		}
*/

		hr = pIEventSubscription->put_SubscriptionName(OLESTR("Connection 1"));
		if (FAILED(hr))
		{
			return FALSE;
		}

		hr = pIEventSubscription->put_MethodName(OLESTR("ConnectionLost"));
		if (FAILED(hr))
		{
			return FALSE;
		}

		//SENSGUID_EVENTCLASS_NETWORK
		hr = pIEventSubscription->put_EventClassID(OLESTR("{d5978620-5b9f-11d1-8dd2-00aa004abd5e}"));
		if (FAILED(hr))
		{
			return FALSE;
		}


		hr = pIEventSubscription->put_SubscriberInterface(pSubscriber);
		if (FAILED(hr))
		{
			return FALSE;
		}

		hr = pIEventSystem->Store(PROGID_EventSubscription, pIEventSubscription);
		if (FAILED(hr))
		{
			return FALSE;
		}

		pIEventSubscription->Release();
		pIEventSubscription = NULL;
		pSubscriber->Release();

		WaitMessage();

	return 0;
}

Open in new window

0
pgnatyukCommented:
If I understand you...

You can find here a tutorial about a simple client application
ATL Client Application Tutorial
http://www.codeguru.com/cpp/com-tech/atl/tutorials/article.php/c41

You will see how you can work with the connection points in ATL. BEGIN_SYNC_MAP,... everything is there.

Here is an official Microsoft sample
AtlEvnt.exe sample shows how to creates ATL sinks by using the ATL IDispEventImpl and IDispEventSimpleImpl classes
http://support.microsoft.com/kb/194179
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.