Chapter 4 -- Getting Started: Implementing a Simple Object

[Previous] [Next]

Chapter 4

Throughout this book, we'll spend most of our time focusing on the under-the-hood aspects of ATL—how it works, what it does well, and what aspects of the library might still need a bit of improvement. With that goal in mind, we'll dedicate little print space to screen shots and hand-holding tutorials. That said, we still think you need to have a general sense of what ATL has to offer before we dive into the details of its implementation. In this chapter, we'll show you an overview of how to create a simple ATL-based COM object as a springboard for the details we'll examine in subsequent chapters. If you're already somewhat versed in ATL, you could skip directly to Chapter 5. (We'll also discuss the ATL wizards again in Chapter 9, in much more detail, so if you choose to read this chapter, don't be surprised if some of the material in Chapter 9 seems familiar.) But be aware that as this chapter unfolds, we'll resolve several misconceptions and answer some frequently asked questions about ATL as we discuss the following topics:

  • The build configurations generated by the ATL COM AppWizard
  • The proxy/stub makefile
  • How the clients you decide to support affect component design choices
  • How to use an ATL component in other applications
  • How to enhance the functionality of a component through proper versioning

Throughout the chapter, we'll use ATL to develop a simple COM object, a "Tip of the Day" component that provides random quotes similar to those found in the startup dialog boxes of various Microsoft applications. (See Figure 4-1.) As far as we know, there aren't any widely used "Tip of the Day" COM components in existence, so the code for these types of dialog boxes is typically reinvented or replicated from application to application. Indeed, the implementation of such functionality is generally language specific, framework specific, and user interface specific.

Figure 4-1. The Tip Of The Day dialog box found in Visual C++ 6.0.

Microsoft Visual C++ can generate the code required to support limited "Tip of the Day" functionality via its Components and Controls gallery, but code generation is a much less effective form of reuse and encapsulation than the language-independent, interface-based approach offered by COM components.

A better approach is to leverage the benefits of COM to create a TipOfTheDay component that could be used from browser-independent Web pages via Microsoft Active Server Pages (ASP), Microsoft Visual Basic projects, and traditional Microsoft Foundation Class (MFC) applications. Figure 4-2 shows this component added to a Web application. To support these clients, the TipOfTheDay component must have the following characteristics:

  • Expose an interface that supports both interpreted (scripting) languages and compiled languages. This requirement points to the use of a dual interface.
  • Not predetermine the user interface that will be used to display each tip. In other words, the TipOfTheDay component will provide the tip text but not the associated user interface.

click to view at full size.

Figure 4-2. The TipOfTheDay component used in a Web application.

Inside Atl
Inside ATL (Programming Languages/C)
ISBN: 1572318589
EAN: 2147483647
Year: 1998
Pages: 127 © 2008-2017.
If you may any questions please contact us: