- 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
- Chapter 32. Using ATL to Create MTS and COM+ Components
- Part VIII: Finishing Touches
- Chapter 33. Adding Windows Help
- Part IX: Appendix
ActiveX Control Interfaces
Like all other COM objects, including the OLE controls before them, ActiveX controls are manipulated through interfaces. In the original OLE control and OLE container specification, OLE controls were required to support certain interfaces, whether or not they needed or used them. This requirement left some controls bloated with code and overhead they didn't need.
Currently, the only interface a simple COM object is required to implement is IUnknown. To be considered an ActiveX control, though, a COM object still must implement the interfaces required so that programming tools such as Visual C++ or Visual Basic can use it, but all other interfaces are optional. The capability to be hosted inside a development environment is what separates ActiveX controls from simpler COM objects.
It wasn't always this way, however. In December 1995, Microsoft published the OLE Controls and OLE Container Guidelines Version 2.0. This was an extension of Version 1.1. With the advent of ActiveX controls, the standard was changed to the 1996 standard for ActiveX controls and ActiveX containers, and is again an extension to the previous standard. The next section discusses the specifics of an ActiveX control.
An ActiveX control exposes interfaces. Likewise, a container exposes interfaces to the ActiveX control. ActiveX controls and ActiveX containers link through interfaces. Approximately 26 interfaces exist for ActiveX controls and their containers. The next section, "ActiveX Controls," discusses the new interfaces. This is not considered an all-inclusive list, because a few other interfaces are used, but these represent the main interfaces.
In Table 28.3, notice that each object supports the IUnknown interface. This is now the only interface that a container can assume is implemented by every COM object. If you implement only the IUnknown interface, however, you will have a COM object that does pretty much nothing. The idea is to implement only the interfaces needed to support the control.
When you write the code for your control, you must know which interfaces the control supports, and you also must realize that all containers do not support all interfaces. In order for your control to be compatible with as many containers as possible, you must check for the support of your interfaces by the container and degrade your control's functionality gracefully in the event an interface is not supported. This process is comparable to error checking—except that you still want your control to function, but with degraded capability or through an alternative interface.
The most important interfaces used by ActiveX controls are IOleControl and IDispatch. As discussed earlier, IDispatch is the mechanism through which ActiveX controls built with MFC communicate. IOleControl encapsulates the basic functionality of an ActiveX control. Table 28.3 shows the COM interfaces an ActiveX control or an ActiveX container can support to facilitate the operations between them. With MFC, most of the interfaces are hidden from you. You will use them, but you might not realize it. You can always explicitly use an interface if you want, but MFC has encapsulated most of the interfaces to make them easier for you to use.
Table 28.3. COM Interfaces for Facilitating Operations Between Controls and Containers
| ActiveX Control | Control Site | Client Site | Container |
| IClassFactory2 | IOleControlSite | IOleClientSite | IOleInPlaceUIWindow |
| IOleObject | IUnknown | IOleInPlaceSite | IOleInPlaceFrame |
| IDataObject | IAdviseSink | IUnknown | |
| IViewObject | IDispatch | ||
| IPersistStorage | IUnknown | ||
| IOleInPlaceActiveObject | |||
| IOleCache | |||
| IPersistStreamInit | |||
| IOleControl | |||
| IConnectionPointContainer | |||
| IConnectionPoint | |||
| IProvideClassInfo | |||
| IProperNotifySink | |||
| ISpecifyPropertyPages | |||
| IPerPropertyBrowsing | |||
| ISimpleFrameSite | |||
| IDispatch | |||
| IUnknown |
The important thing to remember is that the interfaces a control supports define that control. However, you should implement only the interfaces your control requires to function. This idea will become more apparent in the following section on ActiveX controls.
ActiveX Controls | Next Section

Account Sign In
View your cart