Simplest connectable object.

callBackServer.zip
  1. Set up the project.

    Start Visual C++ IDE, goto file/new/project. Type the Project's name "callBackServer". Accept defaults.


  2. Supply the main CoClass

    1. In the ClassView right click on the "callBackServer classes". Choose New ATL Object/Simple Object/Next.
    2. Supply the class short name as "TheCoClass" and Interface name as "IMain". Click on Attributes.
    3. Check the "Support Connection Points" in. OK.

  3. Finish declaration of the event interface

    In the ClassView right click on _IMainEvents and add method "action" without arguments.


  4. Build the project


  5. Supply the connection point.

    In the ClassView right click on TheCoClass. Choose "Implement Connection POint...". Check the _IMainEvents. OK.


  6. Fix the wizard's bug

    Go to TheCoClass.h file and replace
    CONNECTION_POINT_ENTRY(IID__IMainEvents)
    with
    CONNECTION_POINT_ENTRY(DIID__IMainEvents)


  7. Fire the event.

    Supply a method mainMethod() to the IMain interface. Include a call to Fire_action() in the method's body.


  8. Build the client application.

    1. Start Excel.
    2. Use Tools/references of the VBA view to check in the server's tlb.
    3. Declare a TheCoClass variable using WithWEvents keyword.
    4. Catch a double click event in the spreadsheet module and include a call to mainAction.
    5. Implement the action() function
    6. Observe that action() is called everytime the mainAction is called.
    
    Dim WithEvents server As CALLBACKSERVERLib.TheCoClass
    Dim c As Range
    
    Private Sub server_action()
        c.Value = 666
    End Sub
    
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        Set c = Target
        If server Is Nothing Then
            Set server = New CALLBACKSERVERLib.TheCoClass
        End If
        server.mainMethod
    End Sub
    
    
    
Hosted by www.Geocities.ws

1