Use VB to encapsulate ASP code into DLL files

Source: Internet
Author: User

A long time ago, I sorted out the documents and reviewed them.

Use VB to encapsulate ASP and create a SayHello Test Program

1. Open VB6 and create ActiveX DLL

2. Add Microsoft Active Server Pages Object Library selection to the project reference

3. Add the following code:

'Code Start

'Declaration part
Private MyScriptingContext As ScriptingContext
Private MyApplication As Application
Private MyRequest As Request
Private MyResponse As Response
Private MyServer As Server
Private MySession As Session

'The following defines public functions (accessing ASP objects in VB, in VB, MyApplication can be equivalent to Application in ASP. MyRequest is equivalent to Request in ASP. MyResponse is equivalent to Response in ASP. MyServer is equivalent to Server in ASP. MySession is equivalent to Session in ASP. use)

Public Sub OnStartPage (PassedScriptingContext As ScriptingContext)
Set MyScriptingContext = PassedScriptingContext
Set MyApplication = MyScriptingContext. Application
Set MyRequest = MyScriptingContext. Request
Set MyResponse = MyScriptingContext. Response
Set MyServer = MyScriptingContext. Server
Set MySession = MyScriptingContext. Session
End Sub

Public Sub OnEndPage ()
Set MyScriptingContext = Nothing
Set MyApplication = Nothing
Set MyRequest = Nothing
Set MyResponse = Nothing
Set MyServer = Nothing
Set MySession = Nothing
End Sub

'Create a user-defined function SayHello

Public Sub SayHello ()
MyResponse. Write ("Hello World ")
End Sub

'Code End

4. Change the class name to HelloWorld and change the project name to TestVBCode.

5. Generate the TestVBCode. DLL file and run the register component command Regsvr32 path \ TestVBCode. DLL on Windows to register the file. (The uninstall component command is Regsvr32/u path \ TestVBCode. DLL)

6. Create the Test. asp file. The Code is as follows:


'Vb self-built function call format
'Set object name = Server. CreateObject ("project name. Class Name ")
'Object name. self-built function name

Set MyTestObj = Server. CreateObject ("TestVBCode. HelloWorld ")
MyTestObj. SayHello

7. The result of running the Test. asp file is as follows:

Hello World

The above instances will open the door to your vbprogramming world

Come on!

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: 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.