Methods for calling DLLs in ASP files

Source: Internet
Author: User

Dynamic join libraries (DLLs) are an important way to speed up the execution of critical parts of an application, but I'm afraid that most people don't know that the ASP file can also be used to speed up the execution of the server by calling the DLL, so let me briefly describe the steps to call the DLL in the ASP file.
First, you have to have a DLL file, this example creates an ActiveX DLL file through VB5.0, which simulates a dice process.
In a 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 as an ActiveX DLL. In the Properties window, change the Name property of the class module to Clsdice. From the Project menu, select Project Properties to 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 two properties and a method for the Clsdice object, which simulates the process of rolling the dice. Where the MaxPoint attribute represents the number of polygons of the dice, adding a Property Let statement will enable the client to modify the number of sides of the dice; The result property represents the point at which the last throw is outstanding, and the Throw method represents the action of the dice; Private Sub Class_ The Initialize statement sets the number of sides of the dice by default to 6 faces.

From the File menu, choose Generate MYDLL.DLL and save it to the appropriate place. At this point, 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 Pages active Servers pages) is run on the server, and customers can only view results that are returned as HTML. It uses "<%" and "%>" tags to identify script code, does not pass back to the client, and uses HTML markup to identify the content outside of the code. In the following dice.asp code, the CreateObject function is used 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"-

' Loads the type library specified in the METADATA tag. Path is the mydll.dll that is stored on the machine.



<body>

<%

On Error Resume Next ' can continue execution when the program has an unexpected error

If Request.Form ("T1") = "" Then

Session ("point") = 6

Else

Session ("point") =request.form ("T1")

End If

' Use session ("point") to store the number of sides 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 above (note: Not the name of the file), Clsdice is the name of the class module. At this point we can use the Maxpoint,result and the Throw property (method) to manipulate the Dice1 object.

If Request.ServerVariables ("request_method") = "POST" Then

Dice1. MaxPoint = Session ("point") ' Set the number of sides of the dice

Dice1. Throw ' Dice

%>

<form method= "POST" action= "dice.asp" >

<p> when the dice face number is <input type= "text" name= "T1" size= "5" value=<% = Session ("point")%>> when </p>

<p><input type= "Submit" value= "Dice" name= "B1" ></p>

</form>

<p> Result: <% = Dice1. Result%> point </p> ' return results

<%

Else

Dice1. MaxPoint = Session ("point")

%>

<form method= "POST" action= "dice.asp" >

<p> when the dice face number is <input type= "text" name= "T1" size= "5" value=<% = Session ("point")%>> when </p>

<p><input type= "Submit" value= "Dice" name= "B1" ></p>

</form>

<%

End If

%>

</body>

The above code is compiled and run on Windows nt4.0+sp3+iis4.0+ie5.0+vb5.0, but there are many flaws, but my intention is to show you how to call the DLL in ASP, so I did not go to perfect it.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.