• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

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.
0
lavitz
Asked:
lavitz
  • 2
1 Solution
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now