IPC Using Connection Points and EventSinks

As a programmer I often find a need for an IPC(Inter-Process Communication) Mechanism for interacting between serveral processes. I like using COM and OLE since interfaces are simplified, and interaction between components becomes easy. Most IPC techniques requires marshalling, prameters descriptors, and enormous overhead on the design and testing processes. the ATL environment supply a suitable framework for COM Events dispatching with default marshling.

To generate a simple OLE Server that expose an interface to be connected from multiple clients follow these steps:

OLE Server

  1. Start a new ATL project selecting the SERVER - Executable (EXE)
  2. A new skeleton was created. select "Insert/New ATL Object" from the 'Insert' Menu and specify the parameters for the interface you want to create , don't forget to check the 'Support Connection Points' checkbox. it is recommended to check the marshlink checkbox and even to create a custom marshler if all you need is Local IPC.
  3. Select other options depended on your project and generate the interface code.
  4. Add methods/properties to your exposed interface.
  5. On the dispinterface(EventSink) add methods for the events to be passed to the calling process.
  6. Now as you can see in your interface generated header file your interface inheret from ConnectionPointContainerImpl<> to support connction points you must implement a proxy that uses the dispinterface discussed earlier. ATL Framework can do it for by simply right-clicking on the Interface implementation file and choosing implement connection point.
  7. A propery page will appear asking you to select header filename and interface to implement select the appropriate and click OK.
  8. Now from the exposed interface you can use the Fire_"EventName" to call the caller application with parameters.

The Client

  1. Start a new project (Win32,MFC,or whatever you wish)
  2. Import the IDL. you can use the #import directive to generate .tlh,.tli files .
  3. Now implement the dispinterface (The EventSink) using a class derived from the IDispatch + Invoke method and Query Interface.
  4. To 'install' the event sink you must use an instance of the exposed interface , use QueryInterface to get the IConnectionPointContainer from it, after an object of this type was retrieved use FindConnectionPoint to get the IConnectionPoint object and Advise method to connect the EventSink.

The Demo Project

The sample project was created on MSDEV 6sp4 tested on Win2k Proffesional Edition. It consist of OLEServerSampler.exe that expose the IDoInterProcConnections interface and the _IDoInterProcConnectionsEvents sink. and HelloSampler.exe a console application that implement an EventSink and connect to the OLEServerSampler Process.

Downloads

Download demo project - 224 Kb


Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds