Microsoft HomeproductssearchsupportshopWrite Us   Microsoft Home
Magazine
 |  Community
 |  Workshop
 |  Tools & Samples
 |  Training
 |  Site Info

Workshop  |  Component Development

Psssst: A 'COM Artist' Shares the Secret of Creating ActiveX Controls


Nancy Winnick Cluts
Developer Technology Engineer
Microsoft Corporation

February 27, 1997

The following article was originally published in the Site Builder Network Magazine.

Attention, programmers: Want to create an ActiveX™ control to activate your Web site? If you know how to create a Component Object Model (COM) object, you already can.

It's really that simple. For programmers, the meat of the ActiveX learning curve is understanding COM technology.

I learned COM when I needed to create shell extensions for my book, Programming the Windows 95 User Interface Non-SBN link. (Get that shameless plug in early, I always say). The current crop of tools for creating COM objects wasn't available, so I had to do most of the hard work myself. Today, I just use Microsoft® Visual C++® and create ActiveX controls using the OLE Control Wizard. This tool creates the basic framework (code) and registry requirements for a stub ActiveX control.

Basics of COM

COM objects are either implemented within executables (EXEs) or within Dynamic Link Libraries (DLLs). COM objects implemented in EXEs are called local servers, while those implemented in DLLs are called in-process servers. An in-process COM server exposes its functions so that outside applications can use the functionality of its DLL.

The COM library uses a class identifier (a CLSID value) to uniquely identify each COM object. An application then uses this identifier to determine which object the application wants to use. For example, if you create and register a COM object that provides functionality akin to the Microsoft Windows® 95 tree-view control--showing, let's say, a Web-site hierarchy, once you registered this object, other applications can call the functions you expose in it.

Because ActiveX controls are COM objects, you can provide this control (with all the appropriate documentation, of course) as an ActiveX control, and Web developers can place it on their pages and use scripting to activate it. Now wouldn't it be loverly if some smart cookie wrote something like that?

The ActiveX Architecture

ActiveX is a broad set of Internet technologies based on the COM object model. COM is what allows ActiveX objects to interoperate across networks (intranets and the Internet). When COM is working across networks, it is called Distributed COM (DCOM). COM provides the aggregation (the way in which one object can make use of another object) for ActiveX. COM also provides the mechanism for packaging the parameters to functions (known as marshalling) so that those parameters can be passed across processes (and machines!).

Open and Independent

ActiveX relies on an open industry protocol as the basis for its cross-machine infrastructure standards, and it is language- and tool-independent. For example, COM uses the Open Software Foundation's (OSF) DCE Remote Procedure Call (RPC), so tool vendors other than Microsoft can use this technology. You don't have to use Microsoft tools to create ActiveX objects (of course, I wouldn't object if you did). You aren't limited to Windows as your operating system, either: ActiveX is a cross-platform solution that will work on many of the popular systems including Unix, your Macintosh, Windows 95 and Windows NT 4.0, and even on Windows NT 3.51 and Windows 3.1. You aren't limited to C as your language of choice; COM objects are supported in a variety of languages, including Java, Visual C, Visual Basic®, PASCAL, and (gasp!) COBOL Non-MS link!

Binary Reuse

COM objects are reusable as binary components. Once you write an application that uses the object, it won't have to recompile the object to use it. Someone can install your ActiveX control and immediately start scripting to use it.

Reference Counting

COM provides reference-counting for objects. One copy of the object is loaded and a count is kept on the object each time the object is used (referred to). When the reference count for an object goes to zero, the object knows that it is no longer in use, and the object can be deleted and the resources it is using can be freed.

Java and ActiveX

The Java virtual machine (VM) for Microsoft Internet Explorer is an ActiveX control. ActiveX automatically exposes Java classes as ActiveX controls, which integrates the Java language with scripting and other languages. COM does the hard work by wrapping the Java VM.

Nancy Winnick Cluts recently turned down the Nobel Prize in literature because the press tour might have cost her a shot at Mother of the Year honors. She next plans to raise kangaroos on her ranch.


Want someone to walk you through creation of COM objects? A good place to start is the ActiveX Tutorial Samples in the Site Builder Workshop. These samples (and associated white papers) will help you create basic COM objects. The tutorial builds on itself--which means that you keep adding functionality and building on your knowledge base. Other technical articles and resources available that might help you understand COM are:

ActiveX Controls Overview

ActiveX Controls FAQ

ActiveX Software Developer's Kit

The Component Object Model Specification Non-SBN link

The COM Programmer's Cookbook Non-SBN link

Inside COM Non-SBN link by Dale Rogerson (MS Press, ISBN 1-57231-349-8)

For technical how-to questions, check in with the Web Men Talking, the Site Builder Network's answer pair.


Did you find this article useful? Gripes? Compliments? Suggestions for other articles? Write us!

Back to topBack to top

© 1998 Microsoft Corporation. All rights reserved. Terms of use.

 

Magazine Home
Ask Jane
DHTML Dude
Extreme XML
For Starters
More or Hess
Servin' It Up
Site Lights
Web Men Talking
Member Community Home
Benefits: Freebies & Discounts
Benefits: Promote Your Site
Benefits: Connect with Your Peers
Benefits at a Glance
Online Special-Interest Groups
Your Membership
SBN Stores
Join Now
Workshop Home
Essentials
Content & Component Delivery
Component Development
Data Access & Databases
Design
DHTML, HTML & CSS
Extensible Markup Language (XML)
Languages & Development Tools
Messaging & Collaboration
Networking, Protocols & Data Formats
Reusing Browser Technology
Security & Cryptography
Server Technologies
Streaming & Interactive Media
Web Content Management
Workshop Index
Tools & Samples Home
Tools
Samples, Headers, Libs
Images
Sounds
Style Sheets
Web Fonts
Training Home
SBN Live Seminars
SBN Live Chats
Courses
Peer Support
CD-ROM Training
Books & Training Kits
Certification
SBN Home
New to SBN?
What's New on SBN
Site Map
Site Search
Glossary
Write Us
About This Site