Special Edition Using Microsoft® Visual Studio for Enterprise Development

Previous chapterNext chapterContents


- 8 -
Using ActiveX Client Components in an I-net Environment

by Azam A. Mirza

Learn about the techniques for using ActiveX controls in web development tools. This chapter discusses different scenarios for using ActiveX controls on client machines and on the server side, and the impact of each approach.
Learn how Internet Explorer takes advantage of ActiveX controls and how it handles issues such as licensing, authentication, and downloading of controls.
Learn about the interaction of ActiveX components with Java code. Learn how ActiveX controls can be used from within Visual J++ projects.

The centerpiece of Microsoft's ActiveX strategy is ActiveX controls--streamlined versions of OCX controls designed specifically for I-net environments. They provide packaged functionality in a binary format that you can use to build component-based applications.

A key advantage of ActiveX controls over other comparable technologies is their capability to be used in a wide variety of development tools and programming languages. ActiveX controls aren't used exclusively for web development. Thousands of business and commercial client/server applications also take advantage of ActiveX controls. For example, Microsoft Internet Explorer uses ActiveX controls to enhance your web pages with sophisticated formatting features and animation.

This chapter, however, is devoted to using ActiveX controls in I-net environments. I'll discuss techniques for incorporating ActiveX components in your web sites with the Visual InterDev and FrontPage 97 development tools. I'll also discuss the issues involved in using ActiveX components with Internet Explorer and how ActiveX and Java work together in Visual J++.

Using ActiveX Controls in Web Sites

ActiveX is a set of technologies that help you create interactive content for your web sites. With ActiveX, you can incorporate multimedia, interactive objects, and sophisticated applications that come together to create a truly dynamic experience. ActiveX provides the functionality that brings all this together to create truly energized web sites.


For more information about ActiveX technologies, see Chapter 13, "An Inside Look at Active Server Pages and Internet Information Server."

A strong point for ActiveX is its integration of existing technologies with the new web-based technologies such as Java and HTML. By leveraging tried-and-true and mature technologies such as OLE and COM/DCOM, ActiveX builds on stable and standards-based technologies for providing functionality in the I-net environment.


For more information about COM/DCOM, see Chapter 4, "Using Microsoft's Object Technologies."

ActiveX provides a multitude of benefits for developers embracing World Wide Web technologies, including

FIG. 8.1
The Microsoft Network's web site is an example of using ActiveX components to create a dazzling web experience.


ON THE WEB:To use ActiveX controls with Netscape Navigator, you must use the ActiveX plug-in for Netscape, ScriptActive, from NCompassLabs, available at NCompassLabs's web site at http://www.ncompasslabs.com.

Understanding Techniques for Using ActiveX Components

ActiveX is an open platform for I-net software development. Figure 8.2 shows how ActiveX technologies encompass all aspects of the web, from clients to servers to development tools to authoring tools to networking technologies.

On the server side, Active Server Pages and Active Server Components provide support for ActiveX functionality. On the client side, ActiveX controls and the client platforms that support hosting of ActiveX controls provide ActiveX functionality.


For more information about using Active Server Pages, see Chapter 13, "An Inside Look at Active Server Pages and Internet Information Server."

Microsoft has released two development products that allow you to take advantage of these ActiveX technologies on the client and the server by making it possible to use ActiveX controls as part of the development environment. These products include Visual InterDev and FrontPage 97; the next two sections discuss using ActiveX controls in these tools.


For more information about using Visual InterDev to create web content, see Chapter 14, "Developing Active Content with Visual InterDev."

ActiveX Components and Visual InterDev

This section doesn't discuss how to develop web pages with Visual InterDev. It's more a discussion of the techniques to employ in using ActiveX controls when doing Visual InterDev development.

FIG. 8.2
Microsoft provides a comprehensive set of products for taking advantage of ActiveX technologies.

Visual InterDev is a powerful development environment that provides support for using ActiveX technologies on the server and the client. On the server side, Visual InterDev leverages the power of Active Server Pages to provide support for building and using Active Server Components. Figure 8.3 shows how Visual InterDev interacts with Active Server Pages and Active Server Components.

FIG. 8.3
Visual InterDev provides a rich programming environment for using Active Server Components.

Active Server Components are actually ActiveX controls without any user interface elements. Active Server Components, also referred to as server-side ActiveX controls, are used to provide two kinds of functionality:

Tools such as Visual Basic and Visual C++ provide full support for creating Active Server Components. The choice of tool selected for creating Active Server Components depends on your familiarity with the tool and the functionality being developed. As obvious, Visual C++ is a great tool for building components requiring speed and performance. On the other hand, Visual Basic provides a rapid development environment for building components. To get a feel for how Active Server Components work, look at the components provided with Active Server Pages, such as the TextStream component.


See "ActiveX Server Components Included with Visual InterDev," Chapter 14

On the client side, ActiveX controls provide packaged functionality for building dynamic web sites. Visual InterDev provides full support for building web sites that incorporate ActiveX controls for accomplishing various tasks, such as using command buttons, text boxes, and grids. The main distinction between ActiveX controls and Active Server Components is that ActiveX controls employ user interface elements to enhance the look, feel, and functionality of your web application.

Visual InterDev provides support for using any ActiveX control. It also includes an extensive collection of controls for taking advantage of most Windows graphical elements, such as labels, text boxes, and image controls.

The most common method of using client-side ActiveX controls in Visual InterDev is to include them in Active Server Pages when you develop web applications. When a client browser such as Internet Explorer accesses an Active Server Page with an ActiveX control, the control is downloaded to the client machine and then executed as part of the web page. Figure 8.4 shows the relationship between ActiveX controls, Active Server Pages, and client browsers.


See "Using Client-Side ActiveX Components," Chapter 15

FIG. 8.4
Active Server Pages execute on the server and generate an HTML script that's sent to the browser along with any needed ActiveX controls.


NOTE: If you try to access a page that uses client ActiveX controls with Netscape Navigator, the page will load without the ActiveX control, and no errors will be generated.

ActiveX Components and FrontPage 97 (Visual InterDev Edition)

FrontPage 97 is a graphical HTML development tool that helps you build web pages in a visual environment. Visual InterDev includes a version of FrontPage 97 called FrontPage 97 Visual InterDev Edition. The stripped-down version of FrontPage 97 in Visual InterDev doesn't include support for some advanced functions such as WebBots. One main difference between Visual InterDev and FrontPage 97 is that the latter allows you to insert ActiveX controls into HTML pages in WYSIWYG (What You See Is What You Get) mode. When FrontPage 97 displays a control in the page, you can drag and drop it within the HTML text. Figure 8.5 shows an HTML page in FrontPage 97 with an ActiveX control placed on it.


See "The FrontPage 97 HTML Editor," Chapter 14

FIG. 8.5
The WYSIWYG nature of FrontPage 97 makes it easy to place controls precisely where you want them to appear.

Using ActiveX Components with Internet Explorer

If you've used Internet Explorer to surf the World Wide Web, you've surely come across sites that incorporate ActiveX controls to provide powerful functionality. Internet Explorer is a container application that supports hosting ActiveX controls, Active documents, and so on. Figure 8.6 shows how Internet Explorer interacts with ActiveX control-enabled web pages.

FIG. 8.6
As a container application, Internet Explorer handles downloading, displaying, and executing ActiveX controls.

As a container application, Internet Explorer takes care of many administrative tasks associated with using ActiveX controls in web pages. Specifically, Internet Explorer takes care of

The following sections discuss how you can make sure that your controls are appropriately signed and packaged for downloading to client machines and how Internet Explorer handles control updates.

Signing and Marking ActiveX Controls

If you've installed Internet Explorer on your machine and tried to navigate to a web site that uses an unsigned ActiveX control, you're familiar with the security dialog boxes that inform you about possible security problems. The easiest way to get around these dialog boxes is to properly sign and mark your ActiveX controls before deployment.


TIP: When installed, Internet Explorer defaults to the High security setting, with the idea that it's safe to have more security than less when going to unknown web sites. The High setting won't allow you to download any controls that haven't been properly signed and registered by the web site. You can change the security setting by using the Internet Options dialog box (View, Internet Options).

The signing and marking of controls refer to two distinct operations:


ON THE WEB:VeriSign is the certificate-issuing authority used to obtain digital certificates for ActiveX controls. You can reach VeriSign at http://www.verisign.com.

Signing a control assures that the control's developer is positively identified and that the control hasn't been changed in any way since it was signed. If you make any changes to your control, you must re-sign it. The signature on a control is checked only once when the control is first downloaded. After that, Internet Explorer doesn't recheck the signature on the control.

However, signing the control isn't enough by itself. You must also mark your controls safe for initialization and safe for scripting. What this means is that the control has been marked as safe to be initialized by Internet Explorer and the scripts included with the control are safe for execution. If you mark your control as safe for initializing, you're asserting that no matter what values are used to initialize your control, it won't do anything that would damage a user's system or compromise the user's security. If you mark your control as safe for scripting, you're asserting that your control won't do anything to damage a user's system or compromise security regardless of how your control's methods and properties are manipulated by the web page's script. In other words, it has to accept any method calls (with any parameters) or property manipulations in any order without doing anything bad.

During development, you can do some things to make sure that a control is safe for marking. Make sure that the control

Downloading and Updating ActiveX Controls

When Internet Explorer encounters a web page with an ActiveX control (or multiple controls), it first checks users' local system Registries to find out whether that component is available on their machines. If it is, Internet Explorer displays the web page and activates the control. If the control isn't already installed on the users' computers, Internet Explorer automatically finds and installs the component over the web, based on a location specified by the developer creating the page.

The web page developer provides this information by setting the control's CODEBASE property, which specifies an URL location or set of locations where the control can be found and downloaded on the Internet. Internet Explorer then uses this information to locate the control and download the component automatically.

Before a component is downloaded, Internet Explorer displays a message notifying users of the download. Users can choose to cancel the download or proceed. If the control is digitally signed, a digital certificate provides the name of the software vendor supplying the control and verifies that the control hasn't been tampered with. Figure 8.7 shows a digital certificate displayed for an ActiveX control before it's downloaded.

FIG. 8.7
The digital certificate identifies the control's publisher and the digital certification authority that signed it.

The information is carried by the control itself, so the digital certificate will be displayed automatically before downloading with no development work required by the person who uses that control on a web page.


NOTE: By default, controls are downloaded into an ActiveX control cache located in the \windows\occache directory.

The Component Download Service in Internet Explorer supports versioning, so new versions of the control can be detected and automatically downloaded as required.

ActiveX controls include a mechanism to prevent the unlicensed use of controls in web pages. The licensing mechanism works by allowing controls to be distributed with a developer license or a runtime license. Under a developer license, developers can use the control for development purposes in tools such as Visual Basic, Visual C++, and Visual InterDev. Under a runtime license, users can only view the control within an existing application or web page, but can't insert the control into a tool for further development purposes.


TIP: Most controls include a binary file with the .lic extension that includes information about the license. Development tools use this file to determine whether a control can be used in the development environment.

Using ActiveX Controls with Visual J++

Visual J++ is the Java development tool that allows you to take full advantage of the technology. Visual J++ provides full support for the Java virtual machine (VM) on the Win32 platform. The Java VM supports the integration between Java and the Component Object Model (COM), which is the underlying technology for ActiveX. To take advantage of the integration between Java and COM, you must use Visual J++.

The integration of ActiveX and Java allows you to take advantage of the full breadth of options available for developing web applications. As a Visual J++ developer, you can take advantage of ActiveX controls as part of your Java development efforts to gain access to resources such as the system services. Figure 8.8 shows the integration between Java and ActiveX.

FIG. 8.8
Microsoft's extension of Java to include support for ActiveX results in a rich environment for developers and users.


NOTE: If you're a Java developer, you can leverage the thousands of available ActiveX controls in your applications by using ActiveX and Java integration in Visual J++. However, this makes your application Win32 specific, and you lose the cross-platform benefits of Java applications.

Because the Visual J++ compiler supports the integration between Java and ActiveX, you can refer to ActiveX controls directly from your Java source code. To use this facility, you must first import the ActiveX control into a Java class in Visual J++. Visual J++ includes the Java Type Library Wizard for this purpose.

The Java Type Library Wizard

The Java Type Library Wizard in Visual J++ imports the type information stored in ActiveX controls into a Java class file. The wizard imports the type library information into a directory with the same name as the type library. To use the wizard, follow these steps:

1. Choose Tools, Java Type Library Wizard from the menu. The Java Type Library Wizard dialog box appears (see Figure 8.9).

FIG. 8.9
The Java Type Library Wizard dialog box displays all the controls registered on the system.

2. Choose the controls you want to import and click OK. The wizard imports the control and creates a summary.txt file, the path to which appears in the wizard output window in Developer Studio.

3. Double-click the file path in the output window to open the summary.txt file in the editor (see Figure 8.10).

After you run the wizard and create the imported classes, you can use the import statement in your Java code to refer to the classes as shown here:

// import the classes in package named importedclass 
import importedclass.*;


For more information about using ActiveX controls in Visual J++, see Chapter 7, "Creating Components with Visual J++."

FIG. 8.10
The summary.txt file lists the Java signatures of all the methods for the ActiveX control.

The OLE/COM Object Viewer

The OLE/COM Object Viewer included with Visual J++ is used to browse the methods and properties exposed by ActiveX components. To use the OLE/COM Object Viewer, follow these steps:

1. Choose Tools, OLE/COM Object Viewer from Developer Studio's menu. The OLE/COM Object Viewer appears (see Figure 8.11).

FIG. 8.11
The OLE/COM Object Viewer is a graphical tool for browsing ActiveX control properties and methods.

2. From the Explorer pane on the left, select an object to browse. The corresponding interface and object information is displayed in the right pane.

3. To view the Type Library information on a control, right-click the control's name and choose View Type Information from the pop-up menu. The ITypeLib Viewer appears, as shown in Figure 8.12.

FIG. 8.12
The ITypeLib Viewer provides a graphical display of all properties, methods, and interfaces defined for the control.

4. Close the OLE/COM Object Viewer when finished.

The Object Viewer is a simple but powerful tool that's very helpful in determining the functionality provided by an OLE/COM object such as an ActiveX control. You can browse through properties and methods of various objects to determine the correct calling procedures and the number of arguments required by an object.

From Here...

This chapter discusses the use of ActiveX controls in various aspects of I-net environments. You learned about the various issues involved with using ActiveX controls with Internet Explorer and about the security issues involved with ActiveX control usage. ActiveX controls are an integral part of web-based development with tools such as Visual InterDev or FrontPage 97.

For more information, see these chapters:


Previous chapterNext chapterContents


© Copyright, Macmillan Computer Publishing. All rights reserved.