VB6 ASP compiled into DLL components for the simplest tutorial with all project source files _ Application Tips

Source: Internet
Author: User
Tags eval
1. New DLL
Open vb6--> file--> new project--> Select ActiveX dll--> OK


2, the default project, class renaming
Project renaming: Engineering--> Engineering 1 properties (this name corresponds to the project name in the body of the window)--> rename the project name to Asp2dll in the Open dialog box (when the DLL component is registered in the system, the default calling method in ASP is "project name. Class name")--> Are you sure


Class Rename Rename the name to demo in the Properties window


3, the definition of ASP basic objects
Add Module: Engineering--> Add Module--> Select "Module"--> Open


Renaming modules: Engineering Resource Manager--> module--module1--> rename Module1 to "Aspmod" in the Properties window


Add the module code, which is used in almost all ASP DLL components that use VB encapsulation, where the Asp2dll change to the project name or to be consistent at the time of the call, as follows:
Copy Code code 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, all the way down, the module, class module, project files are saved in a folder
5. Call ASP object in class module
Engineering Resource Manager--> class module--> double click Demo to switch to Demo class module code Editor, paste code, initialize class call and class destroy, code as follows:
Copy Code code as follows:

Private Sub Class_Initialize ()
Asp2dll_initialize
End Sub
Private Sub Class_Terminate ()
Asp2dll_terminate
End Sub

At this point, a basic DLL framework is over, and the following can be used to refine the functions you need to encapsulate.
6. Create a new test function
Under the Demo class module, paste the following two-segment test functions.
Copy Code code as follows:

Public Sub Hello ()
Response.Write ("Hello world! ")
Exit Sub
End Sub

7, compile the build DLL
File--> build asp2dll.dll--> Select project folder OK, OK, so if there is no error message prompt, the DLL component has been compiled successfully.
8, registration, uninstall components
Created in the directory where the ASP2DLL.dll component resides
Register. bat batch file, enter:
Copy Code code as follows:

Iisreset/stop
REGSVR32/S ASP2DLL.dll
Iisreset/start

Uninstall. bat batch file, enter:
Copy Code code as follows:

Iisreset/stop
regsvr32/u/S ASP2DLL.dll
Iisreset/start

Double-click to run Registration. BAT, the successful registration will prompt: "ASP2DLL.dll in the DllRegisterServer success." ”

9, in the ASP program to invoke just packaged DLL components and test functions
In step 2, we know that "when a DLL component is registered in the system, the default invocation method in ASP is the ' project name. Class name ', so you should create the object: Set Obj = Server.CreateObject (" project name. Class Name "), as follows:
Copy Code code as follows:

<%
Dim Asp2dll
Set Asp2dll = Server.CreateObject ("Asp2dll. Demo ")
Asp2dll.hello ()
Set Asp2dll = Nothing
%>

10, including engineering documents and all related content package download link (20110221 update download link) package download

A few things to note when compiling DLLs:
1, avoid using VB to retain the keyword as a function or variable name;
2, regular, partial VBScript functions such as eval need to load "engineering--> reference-->microsoft Script Control 1.0" and "Microsoft VBScript Regular Expressions 5.5" ;
3, packaging and can not bring about the nature of the speed upgrade, the virtual host, remote servers need to have component registration authority;
4, to the existing component name or modify the DLL file, you must first stop IIS, and then restart the IIS register DLL components;
5, VB6 SP6 Lite green version download link

From: Http://www.dlstu.cn/code/default.asp?cateID=20 Thank the author's hard work, things are too good, that is, Web access is too slow
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.