This article creates an ActiveXDLL file through VB5.0. This file simulates a process of throwing a color sub, and introduces you to the topic of how to call DLL in ASP.
Dynamic join library (DLL) is an important way to speed up the execution of key parts of an application, but one thing is probably not known to most people, that is, the ASP file can also call DLLs to speed up the execution of the server. Below I will briefly introduce the steps of calling DLLs in an ASP file.
First of all, there must be a DLL file. This example is to create an ActiveXDLL file through VB5.0. This file simulates a process of throwing a color sub.
In the VB5.0 environment, create a new project and double-click the ActiveXDLL icon in the New Project window. VB will automatically add a class module to the project and set the project type to ActiveXDLL. 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, select Save clsDice to save the class module as myDice.cls. Add the following code:
OptionExplicit
PrivateMax,PointAsInteger
PublicPropertyGetResult()AsInteger
Results=Point
EndProperty
PublicPropertyGetMaxpoint()AsInteger
Maxpoint=Max
EndProperty
PublicPropertyLetMaxpoint(numAsInteger)
Max=num
EndProperty
PublicSubThrow()
Randomize
Point=Int(Rnd*Max)+1
EndSub
PrivateSubClass_Initialize()
Max=6
EndSub
This class module defines two properties and a method of the clsDice object. These properties and methods simulate the process of throwing the color coin. The Maxpoint property represents the number of faces of the color coin. Adding the PropertyLet statement will enable the customer to modify the faces of the color coin; the Result property represents the number of points of the last throwing of the color coin; the Throw method represents the action of throwing the color coin; the PrivateSubClass_Initialize statement sets the default number of faces of the color coin to 6 faces.
From the File menu, select Generate MYDLL.DLL and save it to the appropriate place. At this point, we created our own DLL file.
The second step is to refer to the class clsDice in the ASP file.
All code of ASP (ActiveServerPages) is run on the server, and customers can only view the results returned in HTML. It uses the "<%" and "%>" tags to identify script code, and does not pass it back to the client, and uses HTML tags to identify content outside the code. 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 scripting language.
<!--METADATATYPE="typelib"FILE="Path/mydll.dll"-->