About the article with COM encapsulation ASP code, suggest to join the essence area

Source: Internet
Author: User
Tags iis join reference fast web
Encapsulation | Essence ActiveX is a kind of code encapsulation technology that is widely used in Windows series, which improves the reusability of program code, accelerates the development speed of program project, and is commonly called "component". 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.

(The above program is in VB6 Enterprise Edition, Windows2000 Server Chinese edition test passes)




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.