Overview of ActiveX technology (II.)

Source: Internet
Author: User
6.visualc++5.0 's support for ActiveX

vc++5.0 (Enterprise Edition) provides a complete solution for Internet development, with the following contents:

* Develop ActiveX control and ActiveX documentation using MFC or ATL.

* Use ISAPI to design a Web server-side part.

* Use WinInet to develop applications that access files over the Internet.

* Use Asynchronousmonikers to generate applications that download data from the Internet.

* Use ACTIVEXSDK to develop other types of internet-based Win32 applications, including activexscriptinghost,microsoftwebconferencing.

6.1. Develop ActiveX control with VC5.0

VC++5.0 offers two ways to develop ActiveX Control: MFC and ATL (Activetemplatelibrary). Using MFC, you can ignore the details of the control interface and focus on the function of the control itself, but the resulting control is relatively large. Also, if the client wants to run this ActiveX control, it must have a corresponding
Version of the MFC class library DLL, otherwise you must download these huge class libraries at the same time; with ATL, the generated controls are relatively small because of the standard class libraries that do not involve MFC, but developers must understand the details of COM and OLE technology. In most cases, you can use MFC to develop ActiveX control, which is easier. And Because InternetExplorer3.0 provides a MFC4.1 class library, and InternetExplorer3.0 is a component provided by WINDOWS95, it is not necessary to download MFC's class libraries in most cases, as long as ActiveX control uses MFC4.1 or earlier versions.

Using MFC to develop ActiveX control, you can build an engineering framework with Mfcactivexcontrolwizard. VC will automatically generate three classes: (assuming MyName is the name of the control.) )

*cmynameapp: Derived from class COleControlModule, while class COleControlModule is derived from CWinApp;

*cmynamectrl: Derived from class COleControl, while class COleControl is derived from CWnd;

*cmynameproppage: Derived from class COlePropertyPage, while class Coleproppage is derived from CDialog;

As you can see, this framework is somewhat similar to a typical MFC application. Most of the work of developers is in Cmynamectrl, such as adding properties, methods, and events with ClassWizard, handling displays, and so on.

After compiling the OCX file, using VC to provide the Activextestcontainer test this control, you can also use Ole/comobjectviewer to browse the control interface information and type library.

The application of 6.2.ActiveX control on the Web

Given the security of the web, to establish a good trust relationship with the client on the server, you must set up a code signature (CodeSigning) for each ActiveX control that is used on the web. VC5.0 provides a tool for generating code signatures for testing purposes. If it is to be formally issued, it must apply to the relevant organizations.
(See http://www.microsoft.com/intdev/signcode/)

Use ActiveX control on a Web page and wrap it to compress the dynamic Connection library and information file into an extension cab (Cabinet) file. You can use the tools provided by VC5.0 to wrap ActiveX control. In the HTML file, insert the ActiveX control using the OBJECT tag and access the ActiveX control using VBScript or JScript. When the client browses this page with InternetExplorer, it can automatically unpack the file. For security reasons, InternetExplorer sets a different scripting for the download, initialization, legal code signing of the ActiveX part, and whether to allow the
Security level, which can be set by the user as needed. In the following example, the ActiveX control "Mschart.ocx" is used, and when you click the control with the mouse, the title of the control changes.


<object

Classid= "clsid:31291e80-728c-11cf-93d5-0020af99504a"

Codebase= "MSCHART. cab#version=1,0,0,0 "

Id=chart1

width=400

height=200

Align=center

>

</OBJECT>


<scriptlanguage= "VBScript" >

Subchart1_click ()

document.chart1.titletext= "MyTitle"

Endsub


Here, you must provide the ClassID and file path or URL of the OCX. When the client browses this page, it first finds the ClassID in the local registry and, if it exists, does not need to download it. Otherwise, the control must be searched and downloaded according to the path specified by codebase. The ID in the Label object is the name of the OCX's object, used to
Accesses and sets object properties, invokes object methods, and so on.

6.3. Develop ActiveX Document server with VC5.0

MFC4.2 does not support the development of ActiveX containers, but it supports ActiveX servers. A standard ActiveX Document server can be generated whenever an application framework is built when using Mfcappwizard, and you choose to support ActiveDocument. When you run this application, the Document object is automatically registered. To test this ActiveX document, you can run any ActiveX document container, such as Microsoftbinder, MicrosoftWord, and so on, and then insert this object.

6.4.vc5.0 ActiveX Server Framework

*isapi (INTERNETSERVERAPI)

ISAPI provides a simple and efficient way to extend support for Web servers. Developers can design the build is API server extension dynamic Connection library (Isapiserverextensiondll), which can be invoked by the HTTP server. For example, when a client user fills out a form and presses the Submit button, the data entered will be transmitted to the HTTP server, activating the appropriate ISAPI extension application, which can process the user's input and perform the appropriate action. Or, according to the user's request to access the database, read user-specified data, dynamically generate HTML files, and then back to the client.

*ISAPI Filter (isapifilters)

An ISAPI filter is a dynamic connection library that runs on an HTTP server that supports ISAPI. Its role is to monitor server and client events, when a predetermined event occurs, the filter is invoked to encrypt or compress the data to be passed, or to authenticate. In other words, the ISAPI filter provides the ability to preprocess data that is passed between the server and the customer.

Comparison of *ISAPI and Universal Gateway Interface (CGI)

ISAPI provides a Web server with an alternative solution for common Gateway interface applications. Unlike CGI, ISAPI extension applications and HTTP servers run in the same address space and do not need to create new processes, and therefore do not require time-consuming communication between those processes. ISAPI applications can unload from the HTTP server, freeing up memory space for other processes. CGI must create separate execution files and URL mappings for each task, and the HTTP server will start a new process when it receives up to every request. In addition, CGI does not have the functionality that corresponds to the ISAPI filter.

6.5.WinInet (microsoftwin32internetextensions)

VC5.0 provides api:wininet for developing client based web-based applications and encapsulates them into several MFC classes, such as CInternetSession, CHttpConnection, and so on. With these classes, developers do not need to know the details of TCP/IP and Winsock, as long as they create class objects for specific applications.

6.6.AsynchronousMonikers

Because of current network bandwidth limitations, users often want to be able to download data asynchronously, such as downloading a picture of a Web page asynchronously and displaying the download progress. MFC provides a class CAsyncMonikerFile to implement this functionality.

6.7.ActiveXSDK

VC5.0 also provides a dedicated Win32activex development tool: Activexsoftwaredevelopmentkit (ACTIVEXSDK). ACTIVEXSDK contains a series of interface definitions and Internet-related WIN32 functions, including Activexscriptingcomponent, Webbrowsingobject, WebPost APIs, and so on. Users can use these interfaces and APIs to develop web-facing applications or ActiveX components.


6.8.visualc++6.0

September 1998, Microsoft will launch the visualc++6.0. In addition to retaining VC5.0 ActiveX support, VC6.0 also supports DHTML,MFC and ATL's class libraries and templates. Users can easily develop applications similar to the Web browser interface.

7.visualbasic5.0 's support for ActiveX

7.1.VisualBasic Parts

A part (Component) of VisualBasic5.0 (VB) is a file (Exe,dll,ocx) composed of executable code that can be used for other applications or parts. Previous versions of VB allowed users to generate parts called "Oleserver", VB5.0 extended part design features, supported event raising, asynchronous Callbacks (Call-backs), and enhanced the ability to create ActiveX controls and ActiveX documents


The VB5.0 ActiveX components (Component) include:

*activex Control

ActiveX control runs in the same process as the client application. Using VB5.0 to create ActiveX controls that can be used with VB or other development tools and Web browsers is similar to the general design of VB applications. You can add property pages to ActiveX control and debug them in real time. In addition, VB5.0 provides a powerful set of database access controls that developers need to write a small amount of code to complete a general database operation.

*activex Document

VB5.0 's ActiveX documentation provides built-in window scrolling, hyperlinks, and menu support, embedded directly in a Web page. Creating ActiveX Documents is exactly the same as designing a VB form (form), where users can choose to generate Activexdocumentdll or Activexdocumentexe. Either type, VB generates a VBD (visualbasicdocument) file that resembles a form file. You can browse this file directly with Internet Explorer, or use VBScript or JScript to access it.

*activexdll

Activexdll provides objects that run in the same process as the application. An application can create objects, set object properties, and invoke the object's methods. Activexdll generally do not need to establish a user interface.

*activexexe

Activexexe provides objects that run in a different process than the application. After an application creates an object and invokes the object's methods, you can continue with your work. When the object's work is complete, it notifies the application.

Activexdll and Activexexe are called VisualBasic Code parts (codecomponent).

7.2. Packaging ActiveX Parts

The ActiveX components described above can be packaged using VB5.0 SetupWizard to generate a CAB file with a Lempel-ziv compression algorithm, which is published on the web. SetupWizard will be the relevant dynamic link library and information files packaged together. ActiveX components that are generated using VB5.0 can be packaged into safescripting and safeinitializing.

The application of 7.3.ActiveX documents on the Web

To add an ActiveX document to a Web page, first wrap the ActiveX document into a CAB file. Because InternetExplorer reads an ActiveX document, the document replaces the current Web page, so the ActiveX document (that is, the markup object for HTML) is typically placed in a separate HTML file. For example, the following statement establishes a hyperlink:


<ahref= "Activexdoc.htm" >LinktoaActiveXDocument</A>

Where activexdoc.htm is an HTML file that downloads an ActiveX document:


<object

Classid= "Clsid:2f390484-1c7d-11d0-8908-00a0c90395f4"

codebase= "activexdoc.cab#version=1,0,0,0" >

</OBJECT>


This statement downloads the Activexdoc.cab and registers the ActiveX document in the Windows registry.

The application of 7.4.VisualBasic code parts on the Web

VisualBasic code parts include Activexdll and activexexe that can be run on the server side or downloaded from the client.

If a activexdll is running on the server side, the server is running Internetinformationserver, You can access it using the functions provided by the OLEISAPI2.DLL of VB, or use VBScript or JScript based on activeserverpages.

If you want the client to download a code part, first wrap the part into a CAB file. For example, a ActiveXDLL:MyDLL.DLL is generated with the VB5.0 Enterprise Edition, which has only one class: MyClass, and its only way is to display the Login dialog box. This part is packaged with SetupWizard and a CAB file is generated. The following statement downloads the Mydll.cab on the client:


<objectid=myclass

Classid= "Clsid:503b3e09-2191-11d2-8e90-00104b64f7b7"

codebase= "Mydll.cab" >

</OBJECT>


<inputtype=buttonvalue= "Loginnow" name= "Btnlogin" >


<!--

Whenthebuttonisclicked,callthe "LogIn" method.

-->

<scriptlanguage= "VBScript" >

<!--

Subwindow_onload

Myclass.login

Endsub

Subbtnlogin_onclick ()

Myclass.login

Endsub

-->

</Script>


Among them, Objectid is the name of a class in this activexdll. When this web page is downloaded and displayed, the method login for the MyClass class is invoked and the Login dialog box is displayed on the client.

7.3.visualbasic6.0

Microsoft plans to launch VisualBasic6.0 in September 1998. The beta version is currently being tested. In addition to continuing to support Internetexplorerdocumentobjectmodel (DOM) development, VB6.0 offers two exciting new features compared to VB5.0:

*dynamichtml Editor

Developers can create DHTML files or templates just as they would for ordinary VB programs.

*webclasses;

Developers can build the WebClass class corresponding to ASP file one by one on the Web server side, each class can access ASP objects, track debugging in Visualbasicide, and generate an ISAPI dynamic connection library.


8. Summary

As with the Internet and web technology, the development of ActiveX technology, new and more powerful development tools make the server and client application development, Web site building becomes simpler, and easy to expand and reuse. As Microsoft includes WindowsNT, Internetinformationserver, Activeserverpages, and Microsoftfrontpage, The complete Internet solution, such as InternetExplorer, is widely used, and ActiveX technology will be much more developed.


Reference documents:

1.visualc++ Technical Insider (second edition), [Beauty]davidj.kruglinski, Wang Guoyin translation,
Tsinghua University Press.

2.ActiveX Developer's Guide, [Beauty]erictall,markginsburg, Zhang, mechanical
Industrial publishing House.

3.visualbasic6.0:youwon ' Tbelievewhatjusthittheweb,joshuat
Rupin,microsoftinteractivenetworkdeveloper (MIND), August 1998.

4.introductiontoactivexcontrols,microsoftcorp.,msdn,1998 year August.


5.dynamichtmlandthebigpicture,johnswenson,msdnonline,1997 year November.

6.abriefpreviewofthevisualbasic5.0developmentenvironment,michaelotey,windowsntmagazine,1997 year April.

7.http://www.microsoft.com/,microsoft company, including MSDN, MSJ and other technical resources.


8.http://www.activex.com, the third party developed ActiveX control.

9.http://www.active-x.com, documentation on ActiveX technology.

10.http://www.winntmag.com,windowsntmagazine Magazine.


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.