Using VB to write ActiveX DLL to realize ASP programming

Source: Internet
Author: User
Tags iis implement reference client fast web
ASP is a widely used programming language for fast building dynamic Web sites, the default built-in development language is VBScript, because the combination of ASP and Microsoft Windows series operating system is very good, Make the ASP has become the NT development platform for the web development of the preferred language and environment. He has a simple and easy to learn, easy to develop a variety of advantages, but he also has a fatal weakness, is that he is a scripting language to perform, speed will be affected, more crucially, the use of ASP to develop a project, the entire project in the delivery of customer use, is associated with all of the ASP script source code, will not be able to keep the business process confidential, the source code leaks will cause a lot of damage, although Microsoft also introduced the corresponding software to encrypt the ASP program, but there are many restrictions, and will reduce the speed of the program and two times the difficulty of development and debugging, Does ASP's project really want to expose all the source code?

Of course, the answer is certainly negative, because there is no absolute impossibility in the world, then follow me to see how to use VB ActiveX DLL to encapsulate the ASP program, that is, we can use the ActiveX DLL to do all the things that ASP can do, The ActiveX DLL is a compiled DLL file, others are not aware of your source code, but also to ensure their own trade secrets and core technology, and achieve the same effect, the use of fully encapsulated ActiveX DLLs than the full application of ASP script language execution speed is much faster, Especially when the large number of operations with the obvious! After our specific tests, when manipulating 10,000 database records, the Web application encapsulated as an ActiveX DLL is about 21% faster than the pure ASP code, and in the current slow-moving network in China, Speed is a critical part of a Web site. And the use of ActiveX DLL to develop Web programs, than the simple use of ASP better, after all, the ASP can only use VBScript to develop, can not enjoy the advantages of VB, and ActiveX DLL can take full advantage of all the characteristics of VB.

Let's take a look at what an ActiveX DLL is. ActiveX is Microsoft proposed a widely used in the Windows family of a code encapsulation technology, improve the reusability of program code, speed up the development of program projects, commonly known as "components." In VB6 's integrated development environment, we can see several ActiveX projects:

1, ActiveX EXE

This is a activex/com server component that runs outside the process, which means that they run a different procedure than the client code that initializes the component. Although you can access the ActiveX EXE with ASP, it is not recommended that you change the IIS metabase, which allows all executables to be started by scripting code running on the server.

2. ActiveX OCXs

These special components include the additional support required by the host application to display and manipulate components in the GUI environment. You can also put OCX components in the Web page. However, OCX is an application interface and cannot be created using ASP.

3. ActiveX Document DLL and ActiveX document EXE

An active document can display a VB form in an OLE file box application, such as IE or office Binder. But they cannot be applied in ASP.

4. ActiveX DLLs

These activex/com components and the client that initializes the component run in the same process. And the ActiveX DLL we're going to discuss is the entire component. General Microsoft's additional components and other third-party manufacturers to provide a variety of components are this type of ActiveX DLL, but not all of the use of VB written, can also use Vc/java and so on language to develop.

After discussing what an ActiveX DLL is, we begin to formally write our own ActiveX DLL to implement the same functionality in ASP, as we all know, the ASP built in response, Request, Server, Session, Application five objects, in fact, these five built-in objects are IIS console initialization of five ActiveX DLL components, since IIS can initialize these five components for ASP, we can of course also directly in our ActiveX DLL to implement our programming, which means that we can access ASP's built-in objects by referencing these components in a VB application.

As soon as you install a Web server with PWS4 or IIS4, you have a library of objects called Microsoft Active Server Pages object, which we can reference in VB's ActiveX DLL application. By referencing this object library, we get an object (Class): ScriptingContext, this object is also the core object of our entire article discussion. The relationships within the object library are as follows:

Object Library Class class member

Asptypelibrary ScriptingContext Application

Request

Response

Session

Server

With the above diagram, we can easily understand the class scriptingcontent. Let's take a look at a concrete example:

1, use VB6 to create a new ActiveX DLL project

2, refer to the Microsoft Active Server Pages Object Library.

3. Create two component events: OnStartPage and OnEndPage

4, create a reference to the class Scriptingcontent in the event OnStartPage.

5, the instantiation class scriptingcontent.

TEST.CLS (class implementation)

' The Declaration of the object

Dim RP as Response

Dim RQ as Request

Dim AP as Application

Dim SR as Server

Dim SN as session

' Triggers this event when the component is created

Public Sub OnStartPage (MYSC as Scriptingcontent)

' To instantiate the object

Set RP=MYSC. Response

Set RQ=MYSC. Request

Set SR=MYSC. Server

Set AP=MYSC. Application

Set SN=MYSC. Session

Rp.write "<br>activex DLL component has been created! <br> "

End Sub

' Triggers this event when the component is destroyed

Public Sub OnEndPage ()

Rp.write "<br>activex DLL component has been destroyed! <br> "

' Destroy objects

Set rp=nothing

Set rq=nothing

Set sr=nothing

Set ap=nothing

Set sn=nothing

End Sub

' Define a component method of our own

Public Sub HelloWorld ()

Rp.write "<H1>Hello,World!</H1>"

End Sub

In this way, we create an ActiveX DLL that can access the ASP's built-in objects. We name this component project as a, compile this project into a DLL file First.dll in VB, and we register this DLL file in the system. Next, we need a simple ASP program with almost no code to invoke this component:

Test.asp



<title> Test ActiveX Dll</title>


<body>

<%

Dim Testme

' Create the component we just compiled successfully, once the component is created, and the output text on the foliage ' ActiveX DLL component has been

' Created! ”

Set Testme=server.createobject ("First.test")

' Method of calling a component

Testme. HelloWorld

' Log off the component, and automatically display the ActiveX DLL component as it is logged out! ”

Set testme=nothing

%>

</body>


With the simple example above, we can see that using an ActiveX DLL can also achieve the same functionality as the ASP, and the benefits of code secrecy and the more efficient operation of the program. ActiveX DLLs and Pure ASPs have their own advantages and disadvantages, so long as we use these two technologies properly, such as the proper encapsulation of business logic in an ActiveX DLL, or the use of DLL encapsulation technology where confidentiality is required, it is possible to write efficient and fast Web applications.


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.