Home > Articles > Programming > Visual Basic

  • Print
  • + Share This
This chapter is from the book

Using Your Own ActiveX DLL with ASP

You can do a lot by using VBScript code in an Active Server Page, but VBScript of course lacks the power of full-blown Visual Basic, not to mention all the IDE features you may be used to. However, by using the Server.CreateObject function, you can create instances of your own ActiveX DLL's on an ASP page.

First, create and test your ActiveX DLL in a normal Visual Basic environment. Then, you need to install and register the DLL on the Web server so it can be used from an ASP page. Creating an ActiveX DLL is covered in more detail in Chapter 16, "Classes: Reusable Components."

      See "Creating an ActiveX DLL," p. 368.

Once you have created your ActiveX DLL, install it on the Web server. If you already have the Visual Basic runtime files installed on the Web server, the installation of your DLL may be as simple as copying the DLL over and running REGSVR32 to register it.

After the DLL is installed and registered, you can create an object from a class in the DLL with the Server.CreateObject statement:

Set objVariable = Server.CreateObject("MyProject.MyClass")

After an object has been created, you can access it from the current ASP page. To pass it along to another page, you can store it in a session variable, as in the GLOBAL.ASA example in the previous section.

Using ActiveX DLLs with ASP is very simple; just access the methods and properties from VBScript:

Response.Write objVariable.GetUserData("Smith")

VBScript only uses variants, so be careful when declaring functions in your DLL. Arrays and other data types do not always work the same as they would in standard Visual Basic. You should create a small test function in your DLL so that you will be familiar with the VBScript limitations.

  • + Share This
  • 🔖 Save To Your Account