Contacting ActiveX Components

Your Active Server Pages are not limited to the functionality provided by VBScript and the built-in objects discussed in this chapter. The CreateObject method of the Server object can do for your Active Server Pages what the CreateObject() function can do for your VB applications. It opens a door to the services of any existing OLE Server application, as well as custom ActiveX components (ActiveX DLLs). Actually, it is possible to contact ActiveX EXE components too, but things can get messy. ActiveX DLLs are in-process components: they are loaded and become part of the application that calls them. ActiveX EXEs arc out-of-process components. No matter how many applications call an ActiveX EXE component, only one instance of the component is running in the memory. This can lead to hard-to-tackle problems. For example, what if an application sets a global variable and another application
changes it? Writing ActiveX EXEs that function properly at all times is not a simple task, and by default, neither the PWS nor the lIS supports ActiveX EXEs.

To contact the StringClass component from within an ASP file, you must first create the DLL file and then register it with the system. If you haven’t done so already, open the NumStr project and make the NumStrings.dll file. Then register it with the REGSVR32 utility.

To access the methods of the StringClass, you must create an object variable with the following statement:

The STR variable is your gateway to the methods exposed by the StringClass class. To convert a numeric value to a string, use the following line:

It shows the NUMSTR.ASP page, which uses the Number2String method of the StringClass component to display integers as strings. Notice that the Number2String method returns a lowercase string. To convert it to lower caps, you must call the LowerCaps method. You can combine the two calls into one with·the following statement:

To test this ASP file, copy it from the CD to your Web server’s root folder, and open it with Internet Explorer by entering its URL in the browser’s Address box 127.0.0.1/numstr.aspl. You must also make sure that the StringClass component has been registered, To register a Class, you must first create a DLL and then register it with the REGSVR32uWity. Open the NumStr project in the.VISualBasic IDE, and choose File Build StringClass.dll. Once the DLL file is created, close Visual Basic, open a IX>S window, and switch to the folder where the DLL resides. Then issue the following command:

REGSVR32.EXE is a utility for registering ActiveX components on the host system. For more information on registering ActiveX components, see the section “Registering an ActiveX Component”

Once the component is registered, any script running on your server can contact it and call its methods, just like any other system component. You can register all the components you created in Chapter 15 and contact them from your server side scripts. Notice that these components need not be downloaded.

Scroll to Top