How to call DLL in ASP file

怪我咯
Release: 2017-03-30 13:30:07
Original
1631 people have browsed it

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



Use DLL# in the ASP file
##

<%

On Error Resume Next 'The program can continue to execute when an unexpected error occurs

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

Session("point") = 6

Else

Session("point")=Request.Form("T1")

End If

'Use Session("point") to store the number of dice faces

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), and clsDice is the name of the class module. At this point we can use Maxpoint, Result and Throw attributes (methods) to operate on the dice1 object.

If Request.ServerVariables("Request_Method")="POST" then

dice1.Maxpoint = Session("point") 'Set the number of sides of the dice

dice1.Throw 'Throw dice

%>



When The number of dice is >







The result is: <% = dice1.Result %>Point

'Return result

<%

Else

dice1 .Maxpoint = Session("point")

%>



When the number of faces of the dice is >





<%

End If

%>



The above code is in WINDOWS NT4.0 +SP3+IIS4.0+IE5.0+VB5.0 compiled and ran successfully, but there are still many defects. However, my original intention was to introduce you to how to call DLL in ASP, so I did not improve it.


The 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!