Calling a DLL in an ASP file
Author: Chen Minjie
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.
<!--METADATA type= "typelib" file= "Path/mydll.dll"-->
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.