Dynamic link library (DLL) is an important method to speed up the execution of key parts of the application, but there is one thing that most people may not know, that is, the ASP file can also be called by calling the DLL. To speed up the execution of the server, let me briefly introduce the steps of calling DLL in the ASP file.
First, there must be a DLL file. In this example, an ActiveX DLL file is created through VB5.0. This file simulates a process of throwing dice.
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. In the Properties window, change the name attribute of the class module to clsDice. From the Project menu, select Project Properties and change the project name to MyDLL. From the File menu, choose 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 clsDice Object has two properties and one method. These properties and methods simulate the process of throwing dice. Among them, 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 final number of points of the dice; the Throw method represents the action of throwing the dice; the Private Sub Class_Initialize statement will The number of sides of the child is set to 6 by default.
From the File menu, choose Generate MYDLL.DLL and save it to the appropriate location. At this point, we have created our own DLL file.
The second step is to reference the class clsDice in the ASP file.
All codes of ASP (Active Server Pages) are run on the server, and customers can only view the results returned in HTML form. It uses "<%" and "%>" tags to identify script code and does not pass it back to the client. Outside the code, HTML tags are used to identify content. In the code of Dice.asp below, the CreateObject function is used to create a clsDice object instance, which comes from the ActiveX.DLL--MYDLL.DLL file created above, as follows The examples use the VBScript scripting language.
'Load the type library specified in the METADATA tag. Path is the path where mydll.dll is stored on the machine
The result is: <% = dice1.Result %>Point
'Return resultThe above is the detailed content of How to call DLL in ASP file. For more information, please follow other related articles on the PHP Chinese website!