- Table of Contents
- Copyright
- About the Authors
- About the Contributors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- How to Use This Book
- What You Need to Use This Book
- What's New in Visual C++ 6.0
- Contacting the Main Author
- Part I: Introduction
- Chapter 1. The Visual C++ 6.0 Environment
- Part II: MFC Programming
- Chapter 2. MFC Class Library Overview
- Chapter 3. MFC Message Handling Mechanism
- Chapter 4. The Document View Architecture
- Chapter 5. Creating and Using Dialog Boxes
- Chapter 6. Working with Device Contexts and GDI Objects
- Chapter 7. Creating and Using Property Sheets
- Chapter 8. Working with the File System
- Chapter 9. Using Serialization with File and Archive Objects
- Part III: Internet Programming with MFC
- Chapter 10. MFC and the Internet Server API (ISAPI)
- Chapter 11. The WinInet API
- Chapter 12. MFC HTML Support
- Part IV: Advanced Programming Topics
- Chapter 13. Using the Standard C++ Library
- Chapter 14. Error Detection and Exception Handling Techniques
- Chapter 15. Debugging and Profiling Strategies
- Chapter 16. Multithreading
- Chapter 17. Using Scripting and Other Tools to Automate the Visual C++ IDE
- Part V: Database Programming
- Chapter 18. Creating Custom AppWizards
- Chapter 19. Database Overview
- Chapter 20. ODBC Programming
- Chapter 21. MFC Database Classes
- Chapter 22. Using OLE DB
- Chapter 23. Programming with ADO
- Part VI: MFC Support for COM and ActiveX
- Chapter 24. Overview of COM and Active Technologies
- Chapter 25. Active Documents
- Chapter 26. Active Containers
- Chapter 27. Active Servers
- Chapter 28. ActiveX Controls
- Part VII: Using the Active Template Library
- Chapter 29. ATL Architecture
- Chapter 30. Creating COM Objects Using ATL
- Chapter 31. Creating ActiveX Controls Using ATL
- ATL Control Classes
- Connection Points
- Creating Scriptable Controls
- Summary
- Chapter 32. Using ATL to Create MTS and COM+ Components
- Part VIII: Finishing Touches
- Chapter 33. Adding Windows Help
- Part IX: Appendix
Connection Points
Connection points are used by connectable objects to establish bidirectional communication. Connectable objects communicate with their clients through connection-point interfaces—back-channel interfaces that allow a COM server to notify its clients of events. Two interfaces are implemented by a connectable object:
- IConnectionPoint is implemented by a control or other COM object and allows a container or client of the COM object to request event notifications.
- IConnectionPointContainer is used by a client to query a COM object about IConnectionPoint interfaces supported by the object. This interface includes functions that return a pointer to a known IConnectionPoint interface or enumerate IConnectionPoint interfaces supported by a control.
Most ActiveX controls are connectable objects. Other types of COM objects can implement the IConnectionPointContainer and IConnectionPoint interfaces, however, and thus become connectable objects. Figure 31.4 illustrates the coupling between a connectable client and server.
Figure 31.4 The interfaces used to implement connectable objects.
A client interested in a specific IConnectionPoint interface first invokes QueryInterface, requesting the IConnectionPointContainer interface from the server. If an interface pointer is returned, the particular IConnectionPoint interface is requested through IConnectionPointContainer. If the request is successful, the client passes a pointer to its notification sink to the server through the IConnectionPoint interface. The server transmits event notifications to the client using the pointer to the notification sink.
The simplest way to support connection points in a project built by using ATL is to select the Support Connection Points option when using the ATL Object Wizard. A definition of an outgoing interface will be added to the project IDL file. Listing 31.5 is a fragment of an IDL file with an example of an outgoing interface for a COM class named Bothway.
Example 31.5. Defining an Outgoing Interface for a Connectable Object
library CONNECTEXAMPLELib
{
importlib("stdole31.tlb");
importlib("stdole2.tlb");
[
uuid(FCB636B8-FD81-4AB2-B455-9F2BEDA22FBF),
helpstring("_IBothwayEvents Interface")
]
dispinterface _IBothwayEvents
{
properties:
methods:
};
[
uuid(F7706E85-129F-4B2D-A694-90EF33F3357D),
helpstring("Bothway Class")
]
coclass Bothway
{
[default] interface IBothway;
[default, source] dispinterface _IBothwayEvents;
};
};
Note that the outgoing interface is named _IBothwayEvents. The outgoing interface is prefixed with _I and has Events added to the name of the COM class.
To implement connection-point methods for your COM class, you must follow these steps:
- Add methods and properties to the IDL definition for the outgoing interface.
- Compile the IDL using the MIDL compiler to create a type library containing the connection-point information. The easiest way to do this is to build the ATL project.
-
After the build is complete, right-click the ATL class in the Class View window, and select Implement Connection Points from the pop-up menu. A dialog box appears, as Figure 31.5 shows.
Figure 31.5 Implementing connection points for a COM server.
The Implement Connection Point dialog box contains a list of interfaces you can use to implement connection points. In most cases, this dialog box contains only one entry.
- Check the outgoing interface and click OK.
The connection-point class is created with a name generated by prefixing CProxy to the interface name. For the _IBothwayEvents example, the generated class is named CProxy_IBothwayEvents. The connection-point class contains member functions that can be used to generate events that are sent out to the client. These functions are named by prefixing Fire_ to the name of the outgoing interface method defined in IDL. For an outgoing method defined as SayHey in IDL, the connection-point class contains a function with the following name:
Fire_SayHey()
The new connection-point class is added to the multiple inheritance list for the control. You then can fire any event directly. Here's an example:
if(eyesShut && snoringLoudly)
Fire_DadIsSleeping();
Connection points were developed for use in ActiveX controls. ActiveX controls use connection points to coordinate the interfaces used between controls and their containers.
Creating Scriptable Controls | Next Section

Account Sign In
View your cart