Tutorial-Web Home > An Overview in Creating An ActiveX COM Object Component > Section 2: Registering and Using the Component
|
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).
This piece of code will create the object which will allow us to interact with our dll "AdditionHelper". It references the class object "Addme".
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.
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.
Web Programming With COM and ASP
If you found
this information useful please contact me at webmaster@tutorial-web.com
|
Section 2: Registering and Using the Component
|