Dynamic connection library (DLL) is an important way to speed up the execution of key parts of the application, but I am afraid most people do not know about it, that is, dll can be called in ASP files to speed up server execution. Next I will briefly introduce the steps for calling DLL in ASP files.
First, you must have a DLL file. In this example, you can create an ActiveX DLL file through VB5.0. This file simulates a rolling process.
In the VB5.0 environment, create a project and double-click the ActiveX dll icon in the new project window. VB automatically adds a class module for the project and sets the project type to ActiveX DLL. In the Properties window, change the class module name attribute to clsdice. From the project menu, select project 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 attributes and a method of the clsdice object. These attributes and methods simulate the rolling process. The maxpoint attribute indicates the number of shards, and the addition of the property let statement enables the customer to modify the number of shards. The result attribute indicates the number of rollback points. The throw method indicates the rollback action; the private sub class_initialize statement sets the number of partitions to six by default.
From the File menu, select generate mydll. dll and save it to the appropriate place. So far, we have created a DLL file of our own.
The second step is to reference the clsdice class in the ASP file.
All codes of ASP (Active Server Pages on the Active Server Page) are run on the server. You can only view the results returned in HTML format. It uses the "<%" and "%>" tags to identify the script code and does not return the code back to the client. Outside the code, it uses HTML tags to identify the content. In the following dice. ASP code, the Createobject function is used to create a clsdice object instance, which comes from the ActiveX. DLL--MYDLL.DLL file created above. The following example uses the VBScript language.
'Load the library of the type specified in the metadata tag. PATH is the path where mydll. dll is stored on the machine.
<HTML>
<Head> <title> Use DLL in ASP files </title> <Body>
<%
On Error resume next 'continue executing when an unexpected error occurs in the program
If request. Form ("T1") = "" then
Session ("point") = 6
Else
Session ("point") = request. Form ("T1 ")
End if
'Use SESSION ("point") to store the number of partitions
Set dice1 = server. Createobject ("mydll. clsdice ")
'Use the set statement to create a dice1 object. mydll is the project name when the DLL file is created above (Note: it is not the file name), and clsdice is the class module name. Now we can use the maxpoint, result, and throw attributes (methods) to operate dice1 objects.
If request. servervariables ("request_method") = "Post" then
Dice1.maxpoint = SESSION ("point") 'sets the number of partitions
Dice1.throw
%>
<Form method = "Post" Action = "dice. asp">
When the number of partitions is <input type = "text" name = "T1" size = "5" value = <% = SESSION ("point ") %> hour </P>
<Input type = "Submit" value = "throttling" name = "B1"> </P>
</Form>
Result: <% = dice1.result %> point </P> '.
<%
Else
Dice1.maxpoint = SESSION ("point ")
%>
<Form method = "Post" Action = "dice. asp">
When the number of partitions is <input type = "text" name = "T1" size = "5" value = <% = SESSION ("point ") %> hour </P>
<Input type = "Submit" value = "throttling" name = "B1"> </P>
</Form>
<%
End if
%>
</Body>