ATL-Implemented Sink Interface

Environment: VC++ 6.0

Overview

From my experimence, it's always a pain to implement sink interface with MFC wizard. But ATL is much more straightforward and easy to do the same job. Thanks to the new VC++ 6.0 wizard, we can add ATL to MFC project now. So we can implement the sink interface using ATL way. I would like to share my experimence a little tricky thing I figure out with you. Don't use the wizard class wrapper generated class, bypassing it and hook up with server by yourself, you can pass a HDC, HWND or other window handle to the ATL server. If you used MFC wizard class wrapper, normally it gernerates an error message in its automatically generated header file: not emitted because of invalid return type or parameter type.

Here are my procedures:

  1. Create a ActiveX with ATL(Clicker) which expose the connection interface _IClickItEvents and three event functions: OnCtrlMouseMove(long x, long y), OnCtrlMouseClick(long x, long y), OnCtrlError(BSTR errorMsg). An incoming interface was created as well. Which expose functions: SetMode(int 0), PaintOverlay(HDC* pHDC).

  2. Create a MFC dialog based application(ClickerClient) project. Right click the project name in the class view window and choose "new ATL object", then choose "Add ATL support". There will be an error message box show up, just ignore it. Draw an Clicker activeX on the dialog in the resource file.

  3. Include the Clicker.h and Clicker_i.c to you dialog cpp file. Don't use the Wizard generated class CClickIt, use following code find the IUnknow and IClicker of your ActiveX instance:
    IClickIt*   spclicker;
    IUnknown*  pUnk = GetDlgItem(IDC_CLICKIT)->GetControlUnknown();
    pUnk->QueryInterface(IID_IClickIt, (void**) &spclicker));
    

  4. Create a ATL message event handler class like you did in the ATL client project.

  5. Create an instance of message event handler in the InitDialog() and Advise the server connection point there.

  6. Unadvise the server connection point and delete the message handler object in the DestroyWindow().

  7. Try pass a HDC to the server interface function PaintOverlay(HDC* pHDC). Server will paint a rectangle on you DC.

Demo Information

Download the Clicker_source.zip and ClickerClient.zip The demo server code will generate an ActiveX clicker.dll, you need to register it before you play with it.The demo client code will generate a dialog application which showing the mouse position in the control, mouse click position in the control, also paint the dialog by calling to the server PaintOverlay(HDC* pHDC) function.

Downloads

Download client & server demo project - 80 Kb


Comments

  • Humm?

    Posted by Mr.Prakash on 03/06/2004 11:38am

    I have implemented sink in MFC and its quite straight forward. In fact i found the ATL sink a bit tricky for adding each sink methods.

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds