1. Create a DLL
Open VB6 --> file --> new project --> select ActiveX DLL --> OK
2. Rename the default project and class
Project rename: Project --> Project 1 Property (this name corresponds to the project name in the form) --> In the displayed dialog box, rename "project name" to ASP2DLL (when the DLL component is registered in the system, the default calling method in asp is "project name. class Name ") --> OK
Class rename in the Properties window rename the name to Demo
3. define basic ASP objects
Add module: Project --> Add module --> select "module" --> open
Rename module: Engineering resource manager --> module -- Module1 --> rename Module1 to "ASPMod" in the Properties window"
Add the module code. This Code is applicable to almost all asp DLL components encapsulated by vb. Change the ASP2DLL to the project name or be consistent during the call. The Code is as follows:Copy codeThe Code is As follows: Public objContext As ObjectContext
Public Application As ASPTypeLibrary. Application
Public Server As ASPTypeLibrary. Server
Public Session As ASPTypeLibrary. Session
Public Response As ASPTypeLibrary. Response
Public Request As ASPTypeLibrary. Request
Public Sub ASP2DLL_Initialize ()
On Error Resume Next
Set objContext = GetObjectContext
Set Application = objContext. Item ("Application ")
Set Server = objContext. Item ("Server ")
Set Session = objContext. Item ("Session ")
Set Request = objContext. Item ("Request ")
Set Response = objContext. Item ("Response ")
End Sub
Public Sub ASP2DLL_Terminate ()
On Error Resume Next
Set Application = Nothing
Set Server = Nothing
Set Session = Nothing
Set Request = Nothing
Set Response = Nothing
Set objContext = Nothing
End Sub
Public Function Eval (ByRef strEval)
Dim EvalObject As New ScriptControl
EvalObject. Language = "VBScript"
Eval = EvalObject. Eval (strEval)
Set EvalObject = Nothing
End Function
4. Save the newly created DLL
File --> Save the project, and click "OK" to save all the modules, class modules, and project files in the same folder.
5. ASP objects are called in the class module.
Project Resource Manager --> class module --> double-click Demo to switch to the Demo class module code editor, paste the code, initialize class calls and class destruction. The Code is as follows:Copy codeThe Code is as follows: Private Sub Class_Initialize ()
ASP2DLL_Initialize
End Sub
Private Sub Class_Terminate ()
ASP2DLL_Terminate
End Sub
So far, a basic DLL framework has ended. You can complete the encapsulated functions as needed.
6. Create a new test function
Paste the following two test functions under the Demo module.Copy codeThe Code is as follows: Public Sub hello ()
Response. Write ("Hello World! ")
Exit Sub
End Sub
7. compile and generate DLL
File --> Generate ASP2DLL. dll --> select the project folder and click OK. If no error message is displayed, the dll component has been compiled successfully.
8. Register and uninstall Components
Create a directory in which the ASP2DLL. dll component is located
"Register. bat" for batch file processing, input:Copy codeThe Code is as follows: iisreset/stop
Regsvr32/s ASP2DLL. dll
Iisreset/start
"Unload. bat" batch file, input:Copy codeThe Code is as follows: iisreset/stop
Regsvr32/u/s ASP2DLL. dll
Iisreset/start
Double-click "register. bat" and the message "DllRegisterServer in ASP2DLL. dll" is displayed ."
9. Call the encapsulated DLL component and test function in the ASP program.
In step 2, we know that "when the DLL component is registered in the system, the default calling method in asp is 'Project name. class name '. Therefore, you should create an object as follows: set Obj = Server. createObject ("project name. class Name), the Code is as follows:Copy codeThe Code is as follows: <%
Dim ASP2DLL
Set ASP2DLL = Server. CreateObject ("ASP2DLL. Demo ")
ASP2DLL. hello ()
Set ASP2DLL = Nothing
%>
10. Package Download Links (20110221 update download link) for all content including project files
Note the following points when compiling a DLL:
1. Avoid using vb to retain keywords as function or variable names;
2. Regular Expressions and some Vbscript functions such as Eval need to load "project --> reference --> Microsoft Script Control 1.0" and "Microsoft VBScript Regular Expressions 5.5 ";
3. encapsulation does not substantially increase the speed. The virtual host and remote server must have the component registration permission;
4. For an existing component name or a dll file modified, you must stop IIS and restart IIS to register the dll component;
5. VB6 SP6 simplified green Version Download link
Original from: http://www.dlstu.cn/code/default.asp? CateID = 20 thanks to the author for his hard work. Things are too good, that is, the Website access is too slow.