Microsoft Windows CE 3.0 Technical Articles  

How to Write and Use ActiveX Controls for Microsoft Windows CE 3.0

Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Microsoft Corporation

June 2000

Summary:This paper introduces ActiveX controls, discusses how to build and distribute ActiveX controls for Windows CE, and describes how to use ActiveX controls in Windows CE-based applications. (8 printed pages)

Contents

Overview
Introducing ActiveX Controls
Building ActiveX Controls for Windows CE–Based Devices
    Using MFC
    Using ATL
Creating a Design Mode Control
Distributing ActiveX Controls
Using ActiveX Controls in Applications for Windows CE–Based Devices
Using ActiveX Controls in eMbedded Visual C++ 3.0
Conclusion
For More Information

Overview

The Microsoft Windows CE operating system is designed to be compact, powerful, and fast. It is used in embedded systems and devices such as the Pocket PC and Handheld PC. Software written for these systems and devices must also be compact and responsive.

Microsoft ActiveX is a set of technologies that enables software components to interact with one another in a networked environment, regardless of the language in which the components were created. An ActiveX control is a user interface element created using ActiveX technology. ActiveX controls are small, fast, and powerful, and make it easy to integrate and reuse software components. This paper introduces ActiveX controls, discusses how to build and distribute ActiveX controls for Windows CE, and describes how to use ActiveX controls in Windows CE-based applications.

Introducing ActiveX Controls

Reuse is a central goal in software design. Reusing instead of rewriting code saves development effort. ActiveX controls are reusable software components that can quickly add specialized functionality to Web sites, desktop applications, and development tools. ActiveX controls have become the primary architecture for developing programmable software components for use in a variety of different containers, ranging from software development tools to user productivity tools.

ActiveX controls are a COM technology. COM is a software architecture that allows applications to be built from binary software components. COM is the underlying architecture that forms the foundation for higher-level software services, such as those provided by OLE, a technology for transferring and sharing information among applications.

Although OLE was originally based on dynamic data exchange (DDE), it was redesigned shortly after the initial release of OLE and based on COM. This new release of OLE gave developers the ability to add new interfaces to an OLE component without needing to recompile the component's clients. If a component was replaced by a newer version, new clients could take advantage of new interfaces, but existing clients could continue to use the old interfaces.

At the same time as the redesign of OLE, the Microsoft Visual Basic version 2.0 development system introduced Visual Basic custom controls (VBX) to the development community. VBXs were self-contained code modules, written in C or C++, which could be embedded in any Visual Basic–based application by dragging and dropping them onto a form.

The next advance leading toward ActiveX controls was the proliferation of 32-bit technology. VBX could only be compiled for 16-bit applications. Because COM was 32-bit compatible, it was the ideal basis for a new control technology. Furthermore, controls developed using COM could be written in any language and hosted in applications developed in any language. OLE custom controls (OCX) were introduced and replaced VBX technology. The original OLE control specification required each component to implement a minimum of nine specified interfaces, with a total of 60 methods and seven optional interfaces. This detailed specification of well-defined interfaces made OLE controls easy to use but tiresome for control developers to create.

The final incident motivating the development of ActiveX controls was the arrival of the Internet, particularly the popularity of the Web. Initially, the size of the control was not a concern because RAM and hard disk space were becoming less expensive each year, but the prospect of downloading controls over a slow connection made size a concern. If users became frustrated because a page with a large component was taking too long to download, they could find Web content elsewhere. The ActiveX control specification was created as an answer to this problem.

ActiveX controls are required to support only one interface, IUnknown, and two API functions, DllRegisterServerand DllUnregisterServer. These two functions ensure that ActiveX controls are self–registering; that is, they can add and remove the necessary information for their use in the target system's registry.

The IUnknowninterface exposes three methods: QueryInterface, AddRef, and Release. A client calls QueryInterfaceto find out if an object supports a particular interface, and to obtain a reference to it. AddRefand Releaseare used for memory management. Each instance of an ActiveX control has a reference count. Whenever a method, such as QueryInterface, returns an interface pointer to a client, the method must first call AddRefon the specified interface, which increments the reference count of the instance. Whenever a client is finished using an interface, the client is responsible for calling Releaseon it, which decrements the reference count. When the reference count reaches zero, the instance is deleted and its memory is freed.

Because an ActiveX control does not have to support the standard set of interfaces required for an OLE control, a container application must have specific knowledge about the interface for an ActiveX control in order to use it. However, ActiveX controls are small, fast, lightweight, and resource efficient, making them ideal for use on Windows CE–based devices.

ActiveX controls for Windows CE also support the following features that may be enabled to increase a control's efficiency and effectiveness in certain applications: