[Previous] [Next]

Chapter 20


Imagine a world in which you could program any Microsoft Windows application using a sophisticated yet easy-to-use scripting language. Imagine further that all scripting languages were the same so that once you learned to write scripts for one application, you could write scripts for others, too. While you're at it, consider how useful it would be if programs written in Microsoft Visual C++, Microsoft Visual Basic, and other programming languages could also access the features exposed to this hypothetical language.

Sound too good to be true? It's not. Thanks to the COM-based technology known as Automation, any MFC application can be turned into a scriptable application. Automation is a standardized means for exposing an application's features to clients written in Visual Basic; Visual Basic for Applications (VBA); Visual Basic, Scripting Edition (VBScript); and other languages. It solves the problem posed by these languages' inability to talk to COM objects using conventional COM interfaces, but it isn't restricted to dialects of Visual Basic; clients written in C++ and other languages can also use Automation.

Microsoft is actively encouraging application developers to build Automation support into their programs and has led the way by building Automation capabilities into many of its flagship applications. Microsoft Excel, for example, is a powerful Automation server. So are Microsoft Word, Microsoft PowerPoint, and other Microsoft Office applications. By exposing an application's feature set through Automation, you make that application a powerful tool in the hands of users who are willing to learn a scripting language. You also give developers the means to use your application as a platform for building their own applications.

Automation is a versatile tool with talents that extend beyond mere scripting. It's also used to build software components for Active Server Pages, and it's one of the key technologies employed by ActiveX controls. In this chapter, you'll learn what Automation is, how it works, and how you can use MFC to write Automation-enabled applications. A Visual C++ programmer can have a simple Automation server up and running in no time flat. With a little know-how, you can build Automation servers that expose complex, hierarchically structured object models. Visual C++ and MFC also simplify the creation of Automation clients—programs that use the services provided by Automation servers.

The CHM file was converted to HTML by chm2web software.