VC Programming Technology (5) how to package the MFC controls in webpages

Source: Internet
Author: User
Tags microsoft website

ActiveX controls developed using MFC must depend on the MFC library for normal operation. However, you cannot ensure that your user's machine is installed with the same library as your development environment. Therefore, when you issue an ActiveX control, you must verify the existence of these dependent libraries.

   
You can solve this problem by packaging controls and their dependent library files.

   In use
When the object tag is used to embed ActiveX controls into a webpage, The codebase attribute used to specify the download location can point to the. Cab compressed package file. In
When packaging the MFC ActiveX control in the cab file, allow the control to include the. inf file
Control the installation of the control; allow related DLL (MFC library files) to be named and provide location; allow code signature and Automatic Code compression for faster download.

   
In this way, when the user first browses the webpage where your control is located, it will automatically prompt the control to download, including *. the OCX control file and DLL file involved in the INF text file (the control depends on the MFC library file, and the OCX control is also a special DLL), and the control and library file are automatically registered, then the control can be used normally. Controls and library files only need to be downloaded once.
When you use mfc dll, you will not download them (by default, the version number is the same as the existing files on the user's hard disk ).

   
The following uses the ActiveX Control created in drawing in ActiveX controls as an example to describe the packaging and web publishing process of the control:

1. Create an INF file

   INF
A file is a text file used to specify the files to be downloaded (such as dll library files and OCX control files) for the control operation ). INF
Files indicate which files must be bundled in a compressed cab file.

   
The content of the drawline. inf file is as follows:

   ; Sample
INF file for yourcontrol. ocx

   
[Version]

   
Signature = "$ China $"

   
Advancedinf = 2.0

 

   
[Add. Code]

   
Drawline. ocx = drawline. ocx

   
Mfc42.dll = mfc42.dll

   
Msvcrt. dll = msvcrt. dll

   
Olepro32.dll = olepro32.dll

 

   ; Needed
DLL

   
[Mfc42.dll]

   
File-win32-x86 = thiscab

   
Fileversion = 6.6.8063.0

   
Destdir = 11

   
Registerserver = Yes

 

   ; Needed
DLL

   
[Msvcrt. dll]

   
File-win32-x86 = thiscab

   
Fileversion = 7.0.20.0.3959

   
Destdir = 11

   
Registerserver = Yes

 

   ; Needed
DLL

   
[Olepro32.dll]

   
File-win32-x86 = thiscab

   
Fileversion = 5.2.20.0.3959

   
Destdir = 11

   
Registerserver = Yes

 

   
[Drawline. ocx]

   
File-win32-x86 = thiscab

   
CLSID = {1d388d32-9d43-4891-bfee-a775f78b9fbd}

   
Fileversion =

   
Registerserver = Yes

   ; End
INF file

 

   
"Thiscab" is a keyword that indicates that the required file is included in the cab package containing this INF file. You can also specify a relative path from an HTTP
Location to download the required DLL, for example:

   
File-win32-x86 = http: // your website address/needed. dll

   
The keyword file-win32-x86 identifies the platform as x86.

   
Fileversion indicates the file version number. You can
Right-click the file in resource manager to get the file version number. Select "properties" from the displayed list, and then select the "version" tab in the displayed dialog box. Sometimes you need to insert an additional
0. For example, if the ATL. dll version is 2.00.7026 in the dialog box. In the INF file, it must be changed to 2, 00, 0,
7026.

   
The file version of the control can be obtained through the Visual Studio version resource. From the File menu, select Open and click open ):
Resource to open the control ocx file. The required file versions are listed after fileversion.

   
"Destdir" is the directory to be downloaded to: 11. Specify the system directory Windows/system or WINNT/system32; 10.
Specify the windows or WINNT directory. If no destdir is specified (typically), the code is installed on a fixed
Occache temporary directory.
   
"CLSID" is the CLSID of the control to be installed.

Ii. Package files

    Download
Cabinet software development kit (also known as Cabinet SDK or cab Development Kit). After decompression, you can find the construction cab (. Cab)
The cabarc. EXE file. For the Cabinet software package, see the following Microsoft Website:

Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/dncabsdk/html/cabdl. asp

   
Control File, library file (vc6.0mfc library file including mfc42.dll, msvcrt. dll, olepro32.dll), package command file cabarc. EXE, and control
The. inf file installed by the ActiveX control (detailed description later) is placed in the same directory. Run the following doscommand to package the control:

  Cabarc-s 6144 n
Drawline. Cab mfc42.dll msvcrt. dll olepro32.dll drawline. ocx
Drawline. inf

3. Create a webpage containing controls

   
The content of the drawline.htm file is as follows:

   
<HTML>
     
<Head>
      
<Title> test page for Object
Drawlinectl </title>
     
</Head>
     
<Body>
       
<Object ID = "ocxtoolbar control"
Classid = "CLSID: 1d388d32-9d43-4891-bfee-a775f78b9fbd"
          
Codebase = "http: // localhost/testactivex/drawline. Cab # version = 0,001,"> </Object>

     
</Body>
   
</Html>

   
Testactivex is the virtual directory created on the local machine.

4. download and run the test control

   
Copy the web page files drawline.htm and the cab package files drawline. cab to the local virtual directory (such as testactivex) used for testing, and you can go to the browser
Enter the http: // localhost/testactivex/drawline.htm address to test the download and running of the control. If the control has been registered before the test
(Visual
Studio automatically registers the control). You also need to cancel the registration of the control. The registration and cancellation commands are as follows:

   
Registration: 
Regsvr32 
XXXX. ocx 
   
Cancel: 
Regsvr32 XXXX. ocx/u

   
Note that the above commands should be run in the directory where your control is located (such as the control program compilation directory Debug.

V. Other problems

   
If the system prompts "Windows has blocked this software because it cannot verify the publisher" when you open the webpage, you need to make the following settings:
   
On the IE menu bar, select "tools-Internet Options-security-Custom Level". In the displayed window, set the unsigned ActiveX Control to enabled (or prompted ).
Enable (or prompt) Any options of ActiveX control items ). Of course, this is only a test, without considering the system security issues. You can enhance the control running security by adding a signature to the control.

 

References:

   How to package
MFC controls: http://support.microsoft.com/kb/q167158/

   
Add a cab file: http://blog.csdn.net/MLiang/archive/2006/03/17/626912.aspx for ActiveX Spaces

   Creating
Signed CAB files for MFC and ATL controls:

   Http://msdn.microsoft.com/zh-cn/library/4kex18w6.aspx

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.