Calling a DLL in an ASP file
Dynamic join libraries (DLLs) are an important way to speed up the execution of critical parts of your application, but I'm afraid most people don't know that the ASP file can also speed up the execution of the server by calling the DLL, and I'll briefly describe the steps to invoke the DLL in the ASP file.
First, you must have a DLL file, which, in this case, creates an ActiveX DLL file through VB5.0, which simulates the process of a roll dice.
In a VB5.0 environment, create a new project and double-click the ActiveX DLL icon in the New Project window, and VB will automatically add a class module to the project and set the project type to an ActiveX DLL. In the Properties window, change the Name property of the class module to Clsdice. From the Engineering menu, select Engineering Properties and change the project name to Mydll. From the File menu, select Save Clsdice to save the class module as MYDICE.CLS. Add the following code:
Option Explicit
Private Max, point as Integer
Public Property Get Result () as Integer
result = Point
End Property
Public Property Get MaxPoint () as Integer
MaxPoint = Max
End Property
Public Property Let MaxPoint (num as Integer)
Max = num
End Property
Public Sub Throw ()
Randomize
Point = Int (Rnd * Max) + 1
End Sub
Private Sub Class_Initialize ()
Max = 6
End Sub
This class module defines two properties of the Clsdice object and a method that simulates the process of the dice. Where the MaxPoint attribute represents the number of faces of the dice, adding the Property Let statement will enable the customer to modify the number of faces of the dice; The result attribute represents the point of the last throw, and the throw method represents the action of the dice; Private Sub Class_ The Initialize statement sets the number of faces of the dice by default to 6 sides.
From the File menu, select Build MYDLL.DLL and save it to the appropriate location. So far, we have created a DLL file of our own.
The second step is to refer to the class Clsdice in the ASP file.
All code for ASP (Active Server Page Active Server Pages) is run on the server, and customers can only view results that are returned in HTML. It uses the "<%" and "%>" tags to identify the scripting code, not back to the client, and use HTML tags to identify the content outside the code. The CreateObject function is used in the following dice.asp code to create an instance of the Clsdice object from the Activex.dll--mydll.dll file created above, and the following example uses the VBScript scripting language.
' Load the type library specified in the METADATA tab. Path is the MyDLL.DLL on the machine
<body>
<%
On error Resume Next ' continues execution when an unexpected error occurs
If Request.Form ("T1") = "" Then
Session ("point") = 6
Else
Session ("point") =request.form ("T1")
End If
"Use the session (" point ") to store the number of faces of the dice
Set dice1=server.createobject ("Mydll.clsdice")
' Use the SET statement to create the Dice1 object, where Mydll is the project name when the DLL file was created (note: Not the name of the file), Clsdice is the name of the class module. We can then use the Maxpoint,result and throw properties (methods) to manipulate the Dice1 object.
If Request.ServerVariables ("request_method") = "POST" Then
Dice1. MaxPoint = Session ("point") ' Set the number of faces of the dice
Dice1. Throw ' Roll dice
%>
<form method= "POST" action= "dice.asp" >
When the surface number of the dice is <input type= "text" name= "T1" size= "5" value=<% = Session ("point")%>> </p>
<input type= "Submit" value= "Dice" name= "B1" ></p>
</form>
The result is: <% = Dice1. Result%> point </p> ' return results
<%
Else
Dice1. MaxPoint = Session ("point")
%>
<form method= "POST" action= "dice.asp" >
When the surface number of the dice is <input type= "text" name= "T1" size= "5" value=<% = Session ("point")%>> </p>
<input type= "Submit" value= "Dice" name= "B1" ></p>
</form>
<%
End If
%>
</body>