Tutorial-Web Home > An Overview in Creating An ActiveX COM Object Component > Section 2: Registering and Using the Component










Site Menu

An Overview in Utilizing ASP to Provide Database Access Through Web Browsers

ASP Resource and Material Library

Search the Web for other ASP Tutorials

Available ActiveX Components and Source Code

A good reference guide to ASP and COM Objects
cover
More Resources











Registering to Function, Please have your DLL ready

We will need to be running this on an IIS Server version 4.0 or greater. Windows NT 4.0, 2000, or XP will work to accomplish this task. First, copy the AdditionHelper.dll to the server where the website will reside. Next, open a MS-DOS command line window on the server. When the command line window appears change the directory where you saved the dll. Type the following:

regsvr32 additionhelper.dll

This will register the DLL for use by the server. If this step is not complete your webpages will not know where to call the functions in the DLL.

We must now create the webpage which will use our function. Bring up notepad, InterDev, or your webpage creation tool of choice. (I will be using notepad since it is the most basic).

<HTML
<TITLE>My Cool DLL </TITLE>
<BODY>
<%
Dim finalanswer
Dim addthis

	Set addthis=Server.CreateObject("additionhelper.addme")

This piece of code will create the object which will allow us to interact with our dll "AdditionHelper". It references the class object "Addme".

	finalanswer=addthis.additionfunction(3,4)

Our variable, finalanswer will be equal to the results of the function "additionfunction" in the class "addme" in the dll "additionhelper". We are passing the numbers 3 and 4 to be added.

	Response.write finalanswer
%>
<BODY>
<HTML>

We are now displaying the result, 7.

You have now completed a simple ActiveX DLL which is called from a webpage. Obviously, these example functions could have just as easily been called from within the ASP Script itself. Over time I have been asked the following question:

1. Why don't you just write your functions into the programs you are creating. (Or better yet) Why don't you make include files with these functions?

This is a good question. There are many advatages in using and writing ActiveX DLLs and using them, but one must know where to draw the line. This can only be determined on a programmer by programmer basis. However, here are some good guidelines to follow if you are trying to decide the best place for your code:

1. Will you want to use this function on other websites or in other programs? For example, Are you writing a program that will be used on one website, but you are also writing a Visual Basic program which will need the same commands. If so, you can write one DLL and save yourself some time.

2. Will this program be distributed to numerous people?

3. Will this program need to be integrated into various programming languages?

4. Are the functions complex enough that performance is a variable?

If the answer is "yes" to any of these, your best bet is to write an ActiveX component and then call the functions that way. Otherwise you will be ok using include files.

Previous

For a good reference book check out:

Web Programming With COM and ASP
cover

If you found this information useful please contact me at webmaster@tutorial-web.com

© 2001,2002 Derrald Farnsworth-Livingston Web Development


Sections

Section 1: Creating the Component
Section 2: Registering and Using the Component

The Bookworm
Search the Tutorial-Web library for books on any topic!
Sponsors

Search Now:
In Association with Amazon.com