Полезная информация

ActiveX Programming with Visual C++


Introduction

ActiveX development is at the brink of an amazing explosion of possibilities. If you participate at all on the Internet newsgroups or mail lists, you know what we mean. The number of developers doing ActiveX development has increased dramatically. The type of development and the level of sophistication that applications are supporting are incredible. All the work that Microsoft has done over the past five plus years, starting with OLE 2, is beginning to pay off.

I remember sitting in an auditorium five years ago listening to a two and one-half hour lecture on OLE Automation and thinking, "Great, just what we need . . . another macro language!," and also thinking that I had no clue what OLE was going to do for development and the Windows platform. Well OLE 2 took all of us to new levels in the development of integrated components.

With the advent of ActiveX, the future is looking brighter than ever. This book is devoted to bringing that technology down to earth and into your hands. After reading this book, you should feel confident that you can tackle any project or application involving ActiveX, COM, and Windows.

You and This Book

When writing this book the question "Who is the target audience?" often came up. We didn't want to answer that question by saying, "It's for the beginner ActiveX developer," and then produce a "cookie cutter" copy of every other book on the market simply because it was safe or easy to do so. We also didn't want to say, "This book is only for advanced programmers," because that would exclude a lot of developers. Not because we feel you aren't able to understand the material, but because we would have to assume so much about your particular experience and knowledge and omit a lot of basic information just to squeeze everything into a book of this size. We also didn't want to lose anyone or make the book so hard to read that no one would buy it.

The target audience for the book is the intermediate to experienced Windows VC++ developer. We do make some assumptions about your knowledge of basic ActiveX/OLE/COM architecture and of how to use the VC++ development environment. For example, you should know what an ActiveX Automation Server is or at least have a pretty good idea what it is. You should know how to compile applications and how to use the VC++ IDE without having to search the manuals to find out how to "update your project dependencies," for example.

In this book, we describe how to create ActiveX controls using MFC, ATL, and BaseCtl. The material is covered in a relatively small number of pages and advances fairly rapidly from the basic concepts to advanced features. For those readers who are not familiar with ActiveX development, we recommend starting with MFC, since MFC hides a lot of the details from you. Move to ATL as your comfort level increases, and tackle BaseCtl as the last subject.

We believe that this approach enables you to do one-to-one comparisons among the different tools and get a feel for how easy it is to perform a set of tasks or a particular implementation. For example, you can compare the size of the applications, speed of the applications, development effort, learning curve, and so on.

You will also find that every topic is covered by every tool. Too many times, books focus on a single method of implementation, never affording you the opportunity to judge for yourself which tool makes the most sense for you. When we cover a section on how to create COM interfaces using MFC, you can rest assured that we also show you how to do the same with ATL and the BaseCtl.

Finally we believe our approach provides abundant coverage. At this time, no other publication demonstrates how to create ActiveX components with all three tools, let alone with as much detail as we provide in this book. And probably most important, this book generates experience. If you walk away from this book thinking, "You know, I don't know everything about ActiveX, but with a little time, I can learn anything I want to about it," then we'll be happy.

What You Need to Use This Book

All of the samples in this book were developed and tested by using Microsoft Visual C++ 5.0. While a majority of the samples and examples involve Microsoft products directly, MFC and ATL, you are not restricted in how you apply the fundamental principles of ActiveX development. You may use any tool and obtain similar results.

How This Book Is Organized

This book is organized into five parts, with 16 chapters that cover a variety of aspects of ActiveX programming. By no stretch of the imagination do we imply that we cover all aspects of ActiveX development within this text. We cover only those topics that we believe are of the most importance when using ActiveX on a day-to-day basis.

This book assumes that you are reading the chapters in order, as they do build upon the concepts, materials, and experiences gained from previous chapters. The following sections provide an overview for each of the five parts of the book.

Part I: Introduction to ActiveX

Chapter 1 is an overview of ActiveX and what it means to you as a developer. Chapter 2 examines the different types of ActiveX components that can be created and the advantages and disadvantages of each. Chapter 2 also looks at the types of tools available for creating components and their relative strengths and weaknesses.

Part II: ActiveX Automation Servers

Chapter 3 examines in detail the creation of ActiveX Automation Servers using MFC. The chapter starts with the most fundamental aspects of server creation involving methods and properties. It also covers how to expand the basic MFC framework in order to add new features such as shared objects and single instance servers. Chapter 4 explains how to use ATL to create Automation Servers, and, finally, Chapter 5 explores the ActiveX BaseCtl sample and how it, too, can be used to create Automation Servers.

Part III: ActiveX Controls

Part III, like Part II, contains chapters on MFC, ATL, and BaseCtl. Chapters 6 and 7 explain how to create ActiveX controls using MFC. Chapter 6 looks at how to implement some of the basic features of controls, such as methods, properties, and events. Chapter 7 examines more advanced concepts such as asynchronous properties and Drag and Drop support. Chapters 8 and 9 explain how to use ATL to create controls, and Chapters 10 and 11 explain how to use the BaseCtl sample to create controls.

Part IV: COM Objects and Custom Interfaces

Chapter 12 is a detailed description of creating COM objects and Custom Interfaces using MFC. This chapter along with Chapters 13 and 14 focus on how to create the most fundamental aspect of ActiveX development: interface development. Chapter 13 examines using ATL to create COM objects, and Chapter 14 shows how you can implement COM interfaces without a framework such as MFC and ATL.

Part V: Using Your Component and Advanced Topics

Chapter 15 looks at the types of containers and testing applications that are available to you as an ActiveX developer so that you can use and test your newly created components. Chapter 16 introduces you to more advanced concepts of ActiveX, such as DCOM, the Internet, and OLE DB, to name a few. These two chapters are not full descriptions of the topics listed but merely brief explanations of the concepts involved and how you can exploit them.

Conventions Used in This Book

To make this book easier to understand, the following conventions are used:

Characters that you are asked to type are shown in bold font.

A word or phrase used for the first time appears in italic font and is usually accompanied by a definition.

Bulleted lists are used for items that do not require a special order.

Numbered lists are used when you need to follow items or steps in a particular sequence.

This book also includes special Notes, Tips, and Cautions, which are set off, as follows:

NOTE: This is an example of a Note. Notes provide additional information about issues that you should consider in using the described features or point out specific areas of interest in a particular section of code.



Descriptive heads are added to code listings to help you easily find and use the sample code and the application files shown throughout this book. The sample code in this book can be found on Que's Web site located at http://www.quecorp.com/activexvc.

Occasionally within code listings, lines of code are too long to fit on one line. When this occurs, the code is broken into two of more lines. Boldface font is used to emphasize some lines of code in listings.

Some code fragments are included in the text. These fragments are set in monospace font, for example, #include "CPATLControl.h".

Parting Remark

Writing this book has been a tremendous learning experience. ActiveX development is far and away one of today's most exciting aspects of PC and client/server development. The tool sets and applications have finally matured to the level that real progress and advances can be made in component and applications development. We truly hope that we can all look back in another five years and think, "Wow, look how far we've come since then. And, of course, look how much is still ahead of us ."