ACTIVEX
by A. Reyhan Serim
ActiveX is set of technologies that enables software
components to interact with one another in a networked environment, regardless
of the language in which they were created. ActiveX is built on the Component
Object Model (COM).
COM provides the infrastructure used when OLE (Object Linking and Embedding) objects communicate with each other. OLE is a mechanism that allows users to create and edit documents containing items or “objects” created by multiple applications.
COM is the technical cornerstone for the ActiveX technology; it defines how objects expose themselves for use within other objects and how objects can communicate between processes and across a network. COM also defines the object's life cycle. COM objects can be easily integrated for use in many languages, such as Java, Basic, and C++. COM objects are reusable binary components.
ActiveX controls, formerly
known as OLE controls, let you develop sophisticated controls based on the
COM that can be installed in dialog
boxes or any ActiveX control container application, including pages on the
Internet’s World Wide Web and Visual Basic applications. Unlike Visual Basic
(VBX) controls, ActiveX controls can be built in either 32-bit or 16-bit
versions. With some work, you can convert existing VBXs to ActiveX controls.
An ActiveX control is an COM-based object that can draw itself in its own window, respond to events (such as mouse clicks), and be managed through an interface that includes properties and methods similar to those in Automation objects. The only limitation on the kinds of ActiveX controls you can create is your imagination.
These controls can be developed for many uses, such as database access, data monitoring, or graphing. Besides their portability, ActiveX controls support features previously not available to custom controls, such as compatibility with existing OLE containers and the ability to integrate their menus with the OLE container menus. In addition, an ActiveX control fully supports Automation, which allows the control to expose writable properties and a set of methods that can be called by the control user.
Beginning with MFC 4.2, you
can create windowless ActiveX controls and controls that only create a window
when they become active. Windowless controls speed up the display of your
application and make it possible to have transparent and nonrectangular
controls. With MFC versions 4.2 and later, you can also load ActiveX control
properties asynchronously.
As seen in Figure 1, ActiveX consists of a client-side platform, a
server-side platform, development tools, authoring tools, and networking
technologies. ActiveX will provide users, Webmasters, and developers with a
rich platform for innovative applications on the Internet, while preserving
their investments in applications, tools, knowledge, and code.
|
|
ActiveX on the
client is the client-side platform that enables applications and content to be
run and viewed on an end user's system. Applications and content can be either
present on the client system itself or automatically downloaded from the server
and viewed and run on the client. ActiveX on the client consists of:
·
Microsoft Internet Explorer, which brings the benefits of ActiveX
to end users and enables them to run Java applets and ActiveX controls written
in Java, Visual C++, and other languages.
·
Scripting engines for running scripts written in VB Script and
JavaScript.
·
ActiveX controls bundled with Internet Explorer for viewing and
editing different kinds of content such as ActiveVRML™ (for 3D virtual reality
modeling), ActiveMovie™ (for audio/video), and more.
With ActiveX on the client, users can
run ActiveX controls written in different languages, such as Java, Visual C++,
Visual Basic, and others. ActiveX on the client supports HTML 3.0 content,
including support for frames, stylesheets, and tables.
ActiveX on the
server is the server-side platform that provides clients with Internet
services, applications, data, and content. Applications and content can be
hosted on the same server that runs the Web Server or on other systems. Data
can be hosted in any SQL database or any database that supports Open Database
Connectivity (ODBC). With ActiveX on the server, developers can write Common
Gateway Interface (CGI) applications, Internet Server application programming
interface (ISAPI) Dynamic Link Libraries (DLLs) that run on the server side,
and scripts. ActiveX on the Server consists of:
·
Microsoft Internet Information Server, which supports CGI
applications, ISAPI DLLs, connectivity to databases, and so forth.
·
Server side scripting, code named Denali.
·
Transactions, code named Viper.
·
Message Queuing, code named Falcon.
ActiveX Controls and Scripting give developers the
infrastructure needed to add language- and tool-independent extensions to Web
pages. ActiveX provides developers, end users, and Webmasters a wide
choice of existing technologies and applications that can be used for the
Internet/intranets as well as new technologies such as Java. Developers get a
wide selection of tools and languages to choose from in order to develop
Internet/intranet applications. For example, developers can build Internet/intranet
applications using Microsoft Visual C++, Microsoft's Java development tool
Visual J++, Borland C++, Symantec C++, and the next version of Microsoft Visual
Basic. Webmasters can choose from several authoring tools to develop powerful
content including applications, while Web producers have a choice of over 1,000
shrink-wrapped components, available today, to add interactivity to their Web
sites.
ActiveX is compatible with
existing investments in software, hardware, and human resources. Using ActiveX Controls lets developers take advantage
of existing OLE development tools and the investment they have already made in
OLE. For
example, developers can leverage their existing knowledge of Microsoft Visual
C++ to develop applications for the Internet and intranets using the same tool.
Visual Basic developers can leverage their existing Visual Basic knowledge to
develop scripts for the Internet using Visual Basic Scripting Edition (VB
Script), an open scripting language for the Internet. With Visual Basic,
developers can use their existing knowledge and code to develop Internet and
intranet applications. Java developers can write applications in Java that
expose COM interfaces and that use COM interfaces, building upon existing
investments in components and knowledge. ActiveX also provides support for a
wide selection of networking protocols and standards such as TCP/IP, HTTP, NNTP
and SMTP.
ActiveX combines the benefits of the World Wide Web and the
personal computer to enable interactive distributed applications and richer
communications between users. ActiveX has also greatly improved extending the
HTTP and FTP protocols. The ActiveX encapsulate a new protocol that supports
the concept of binding to a URL dynamically from within your application. An
application binds to a URL moniker, which then communicates through the
appropriate protocol to activate the OLE object.
Microsoft ActiveX supported standards
|
Area |
Standards and
Technologies in ActiveX (partial listing) |
|
Networking |
TCP/IP, IPX/SPX, PPP, SLIP, DNS, RIP, PPTP, DHCP, WINS, IPng,
SSL |
|
Web |
HTTP, HTML, VRML |
|
Communication |
RTP, T.120, T.127, H.323, RSVP |
|
Messaging |
SMTP, X.400, MIME, POP3 |
|
Databases |
ODBC (ISO 9942), SQL |
|
Programming Languages |
ANSI C (ISO 9899), ANSI C++, Java, Basic |
|
Directory |
X.500 |
|
Miscellaneous |
FTP, Gopher, Telnet |
An ActiveX component is a unit of executable code, such as
an .exe, .dll, or .ocx file, that follows the ActiveX specification for
providing objects. ActiveX technology allows programmers to assemble these
reusable software components into applications and services.
Component software development using ActiveX technology
should not be confused with object-oriented programming (OOP). OOP is a way to
build object-based software components; ActiveX is a technology that allows you
to combine object-based components created using many different tools. To put
it another way, OOP is concerned with creating objects, while ActiveX is
concerned with making objects work together.
Components provide reusable code in the form of objects.
An application that uses a component’s code, by creating objects and calling their
properties and methods, is referred to as a client.
Components can run either in-process or out-of-process
with respect to the clients that use their objects. In-process server objects are implemented in a dynamic-link library (DLL) and are
run in the process space of the controller. Since they are contained in a DLL,
they cannot be run as stand-alone objects. An in-process component, or
ActiveX DLL, runs in another application’s process. The client may be the
application itself, or another in-process component that the application is
using.
|
|
Out-of-process server objects, or ActiveX Exe, are
implemented in an executable file and are run in a separate process space.
Access to in-process objects is much faster than to out-of-process server
objects because automation does not need to make remote procedure calls across
the process boundary.
|
|
An ActiveX control, like a built-in control, is an object that you place on a form to enable or enhance a user's interaction with an application. ActiveX controls have events and can be incorporated into other controls. These controls have an .ocx file name extension.
|
|
ActiveX documents are
forms that can appear within Internet browser windows. Visual Basic ActiveX
documents offer built-in viewport scrolling, Hyperlinks, and menu negotiation.
ActiveX documents are designed the same as Visual Basic
forms. They can contain insertable objects, such as Microsoft Excel pivot
tables. They can also show message boxes and secondary forms.
You
link to ActiveX documents from an HTML page with a combination of HMTL and
VBScript. In the following example, an ActiveX document is reached from a
hyperlink on an HTML page.
·
Use HTML to provide a link to
the HTML page referencing the ActiveX document.
Since
the ActiveX document will replace the HTML page in Internet Explorer, it's
necessary to place the component's OBJECT tag on a separate HTML page, then
jump to that page — which will promptly disappear when the ActiveX document has
been loaded.
The
following HTML code creates a hyperlink from the first page to the second (the
one that downloads the ActiveX document):
<a href="Accounts.htm">View or update
accounts</a>
·
Use HTML to provide a means for
the browser to download, register, and navigate to the ActiveX document.The
following HTML fragment instructs Internet Explorer to download the ActiveX
component and register the ActiveX document in the Windows registry:
<OBJECT
classid="clsid:2F390484-1C7D-11D0-8908-00A0C90395F4"
codebase="Accounts.cab#version=1,0,0,0">
</OBJECT>
The OBJECT tag in this example
includes:
·
The ActiveX document's class ID
so that it can be included or found in the Windows registry.
·
A CODEBASE attribute to tell the
browser where to find the component if it's not already on the client machine
(and a version number to check against for updating).
·
On the same page, place VBScript
that instructs Internet Explorer to navigate immediately to the ActiveX
document through its .vbd file (this file was created when the ActiveX document
was compiled, and contains a pointer to the component providing the ActiveX
document's objects).
<SCRIPT
LANGUAGE="VBScript">
Sub Window_OnLoad
Document.Open
Document.Write
"<FRAMESET>"
Document.Write "<FRAME
SRC=""Accounts.vbd"">"
Document.Write
"</FRAMESET>"
Document.Close
End Sub
</SCRIPT>
This code fragment contains only the name of the .vbd
file is given, rather than a fully-qualified path. Using this relative path to
the file, Internet Explorer will look for it in the same directory as the .htm
file containing the VBScript.
ActiveX controls enliven and add power to your HTML
pages. In addition to controls you create, you can use three controls provided
with the Professional and Enterprise editions of Visual Basic to extend
standard applications with Internet technology.
Using
HTML and VBScript, you can include ActiveX controls on an HTML page, set their
properties, call their methods, and handle their events. Given this, an HTML
page containing controls is somewhat like a Visual Basic designer.
In general,
ActiveX controls help to make HTML pages more vibrant with interactive or
animated user interface features.
You
reference and script ActiveX control behavior with a combination of HMTL and
VBScript. In the following example, two label-style controls are embedded to
provide clickable table of contents entries.
·
Use HTML to provide a means for
the browser to download, register, and reference the ActiveX controls.
<OBJECT
classid="clsid:2F390484-1C7D-11D0-8908-00A0C90395F4"
codebase="http://www.mysite.com/controls/label.ocx#version=1,0,0,0"
id="Welcome"
width="150"
height="20"
align="center"
vspace="0"
>
<PARAM name="Caption"
value="Welcome Page">
<PARAM name="FontName"
value="News Gothic MT">
<PARAM name="FontSize"
value="11">
<PARAM name="FontBold"
value="1">
<PARAM name="ForeColor"
value="000000">
</OBJECT>
<OBJECT
classid="clsid:2F390484-1C7D-11D0-8908-00A0C90395F4"
codebase="http://www.mysite.com/controls/label.ocx#version=1,0,0,0"
id="Catalog"
width="150"
height="20"
align="center"
vspace="0"
>
<PARAM NAME="Caption"
value="Our Catalog">
<PARAM NAME="FontName"
value="News Gothic MT">
<PARAM NAME="FontSize"
value="11">
<PARAM NAME="FontBold"
value="1">
<PARAM NAME="ForeColor"
value="000000">
</OBJECT>
The
OBJECT tags in this fragment include:
·
The controls' class IDs so that
they can be included or found in the Windows registry.
·
An ID attribute to use when
referencing the controls in VBScript (similar to the Name property in Visual
Basic).
·
A CODEBASE attribute to tell the
browser where to find the component if it's not already on the client machine
(and a version number to check against for updating).
·
PARAM NAME tags to set the
controls' property values.
·
Use VBScript to call handle
click events so that clicking each control will load a specific .htm file in a
specific HTML frame:
<SCRIPT
LANGUAGE="VBScript">
Sub Welcome_Click
Parent.Parent.Frames(1).Location.Href="Welcome.htm"
Welcome.ForeColor = 000000
Sub Catalog_Click
Catalog.ForeColor = 000000
End Sub
</SCRIPT>