Dynamic Library (DLL) is an important way to speed up the execution speed of the application key part, but some people may not know that it is to speed up the server's execution of the server by calling the DLL in the ASP file. I will simply This section describes how to call the DLL in the ASP file. First, you must have a DLL file. This example creates an ActiveX DLL file via VB5.0, which simulates a throwing process. In the VB5.0 environment, create a new project and double-click the ActiveX DLL icon in the New Project window, VB will automatically add a class module to the project and set the project type to ActiveX DLL. Change the name property of the class module to CLSDICE in the attribute window. From the engineering menu, select the project properties to change the project name to MyDLL. From the File menu, select Save CLSDICE and save the class module as MyDICE.CLS. Add the following code:
Option expedition
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 coplass_initialize ()
MAX = 6
End Sub
This class module defines two attributes of the Clsdice object and a method that simulates the process of throwing. The maxpoint attribute represents the number of colors, adding the Property Let statement will enable the customer to modify the number of colors; the Result property indicates the number of points that last throws the color of the colors; the THROW method represents the action of the roll; the private sub class_initialize statement The size of the son is the default setting to 6 sides.
From the File menu, select Generate MyDLL.dll and save it to the appropriate place. At this point, we created a DLL file.
The second step is to reference the class clsdice in the ASP file.
All code for ASP (Active Server Page Active Server Pages) is running on the server, and customers can only view the results that are backup in HTML. It uses "<%" and "%>" tag to identify script code, do not return to the client, outside the code, using the HTML tag to identify content. The CREATEOBJECT function created a CREATEOBJECT function in the code of Dice.asp, which is 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 tag. Path is the path stored by mydll.dll on the machine
<%
On Error ResMe Next 'Can continue to execute when an unexpected error occurs?
If Request.form ("T1") = "" "" ") = 6
Else
Session ("Point") = Request.form ("T1")
END IF
'Use session ("Point") to store the number of colors
Set dice1 = server.createObject ("Mydll.Clsdice")
'Create a DICE1 object using the SET statement, where mydll is the project name when you create a DLL file above (Note: Not the name of the file), the name of CLSDice is a class module. To this we can use the MaxPoint, Result, and the Throw property (Method) to operate the DICE1 object.
If Request.servervariables ("Request_Method") = "post" then
Dice1.maxpoint = session ("Point") 'Sets the number of faces
Dice1.Throw 'throwing
%>