ASP invoke DLL and encapsulate DLL instance _ application Tips

Source: Internet
Author: User
Open VB6, create a new ActiveX DLL
2. Add Microsoft Active Server Pages Object Library selection in project references
3, fill in the code as follows:
Copy Code code as follows:

' Code Start
' Declaration section
Private Myscriptingcontext as ScriptingContext
Private MyApplication as Application
Private Myrequest as Request
Private Myresponse as Response
Private MyServer as Server
Private MySession as session
' Definition of common functions (in VB to access ASP objects, that is, in VB can be equated with MyApplication in ASP application, Myrequest equivalent to the ASP in the request, Myresponse equivalent to ASP in the response, MyServer equivalent to the ASP in the server, mysession equivalent to the ASP in the session 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 custom function SayHello
Public Sub SayHello ()
Myresponse.write ("Hello World")
End Sub
' Code End

4. Change the class name to read: HelloWorld the project name to: Testvbcode
5, Generate TestVBCode.DLL files, and use the Windows Run Registration Component Command REGSVR32 path \testvbcode.dll registration can be used. (Uninstall Component command for regsvr32/u path \testvbcode.dll)
6, the establishment of test.asp files, code as follows
Copy Code code as follows:

<%
' VB self-constructing function call format
' Set object name =server.createobject (' project name. Class Name ')
' Object name. Name of the self-created function
Set mytestobj = Server.CreateObject ("Testvbcode.helloworld")
Mytestobj.sayhello
%>

7. The results of running the test.asp file are shown as follows:
Hello World
===========================================================
For more complex applications, you can extend this example to the outside.
Such as:
Copy Code code as follows:

Public Sub CONNSTR2 ()
Set conn = Myserver.createobject ("ADODB. Connection ")
Conn. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & Myserver.mappath ("Codata.mdb")
Set RS = conn. Execute ("SELECT * FROM News")
Do but not Rs. Eof
Myresponse.write (RS ("News_title") & "<br>")
Rs. MoveNext
Loop
Rs. Close
Set conn = Nothing
End Sub

This is a database-connected code encapsulation, of course, here to add ADO reference.
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.