How to package MFC controls in a Web page

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
When you embed ActiveX Controls in a Web page using the OBJECT tag, theCODEBASE attribute used to specify the download location can point to file. This is the recommended way to package MFC ActiveX Controls.Packaging an MFC ActiveX Control in a cabinet file allows an .inf file tobe included to control installation of the ActiveX Control, allows fordependent DLLs to be named and a location for them provided, allows forcode signing, and automatically compresses the code for quicker download.
More information
ActiveX controls are embedded in Web pages using the OBJECT tag. TheCODEBASE attribute of the OBJECT tag specifies the location from which todownload the control. CODEBASE can point to a number of different filetypes successfully.

For instance, CODEBASE can point directly to an .ocx file as follows:
Because this downloads and installs only the .ocx file, this solutionrelies on any necessary supporting DLLs already existing on the clientmachine. In most cases, it should not be assumed that these DLLs will existon the client and be the correct version.

Another alternative is for CODEBASE to point to an .inf file, for example:
An .inf file controls the installation of an .ocx file and its supportingfiles. This method is NOT recommended because it is not possible to sign an.inf file (see the REFERENCES section for references on code signing).

The best solution is for CODEBASE to point to a cabinet file. With thismethod, supporting DLLs can be referenced and the cabinet file signed.

NOTE: If the directions below for referencing the MFC DLLs are followed,the MFC DLLs will not be downloaded if they already exist on the client.The CODEBASE line will resemble the following:
Note here that the #Version information applies to the version of thecontrol specified by the CLASSID parameter of the OBJECT tag.

Cab Packaging Overview

In the Cabinet Software Development Kit (also called Cabinet SDK, or CABDevelopment Kit) you will find the necessary tools to construct cabinet(.cab) files. See the following Microsoft Web site:The cabinet file that CODEBASE points to should contain the .ocx file andan .inf file that will control the installation of the ActiveX Control.Dependent DLLs that may already exist on the system, such as the MFC DLLs,should not be included in this cabinet file. Instead, the MFC DLLs, andother dependent DLLs, should be packaged in separate cabinet files andreferenced by the control's .inf file. The following example illustrateshow to package the MFC Spindial sample control.

The OBJECT tag to include the Spindial control in a Web page resemblesthe following:
   <OBJECT ID="Spindial1" WIDTH=200 HEIGHT=200   CLASSID="CLSID:06889605-B8D0-101A-91F1-00608CEAD5B3"   CODEBASE=",0,0,001">         <PARAM NAME="_Version" VALUE="65536">         <PARAM NAME="_ExtentX" VALUE="2646">         <PARAM NAME="_ExtentY" VALUE="1323">         <PARAM NAME="_StockProps" VALUE="0">         <PARAM NAME="NeedlePosition" VALUE="2">   </OBJECT>				
In this case, must contain two files, Spindial.ocx andSpindial.inf. The command to build this cabinet file is similar to thefollowing depending on the path to your installation of the CabinetDevelopment Kit:
   C:\CabDevKit\cabarc.exe N spindial.ocx spindial.inf				
The following is an example .inf for the MFC Spindial control. This .inffile can be modified to download any MFC ActiveX Control by changingSpindial's information to the desired MFC ActiveX Control's information.See comments below.
   ; ========================= spindial.inf ========================   ; This .inf file will control the installation of the MFC Spindial   ; control. This control has been compiled with Visual C++ version 4.2.   ; The FileVersion tags in the dependent DLLs section on this file   ; reflect this requirement.   [version]   ; version signature (same for both NT and Win95) do not remove   signature="$CHICAGO$"   AdvancedINF=2.0   [Add.Code]   spindial.ocx=spindial.ocx   ; These are the necessary supporting DLLs for MFC 4.2 ActiveX Controls   mfc42.dll=mfc42.dll   msvcrt.dll=msvcrt.dll   olepro32.dll=olepro32.dll   ; thiscab is a keyword which, in this case, means that Spindial.ocx   ; can be found in the same .cab file as this .inf file   ; file-win32-x86 is an x86 platform specific identifier   ; See the ActiveX SDK - ActiveX Controls - Internet Component Download -   ; Packaging component code for automatic download   [spindial.ocx]   file-win32-x86=thiscab   ; *** add your controls CLSID here ***   clsid={06889605-B8D0-101A-91F1-00608CEAD5B3}   ; Add your ocx's file version here.   FileVersion=1,0,0,001   RegisterServer=yes   ; dependent DLLs   [msvcrt.dll]   ; This is an example of conditional hook. The hook only gets processed   ; if msvcrt.dll of the specified version is absent on client machine.   FileVersion=4,20,0,6164   hook=mfc42installer   [mfc42.dll]   FileVersion=4,2,0,6256   hook=mfc42installer   [olepro32.dll]   FileVersion=4,2,0,6068   hook=mfc42installer   [mfc42installer]   file-win32-x86=VALUE=   ; If dependent DLLs are packaged directly into the above cabinet file   ; along with an .inf file, specify that .inf file to run as follows:   ;InfFile=mfc42.inf   ; The file actually contains a self extracting executable.   ; In this case we specify a run= command.   run=%EXTRACT_DIR%\mfc42.exe   ; ====================== end of spindial.inf =====================				
The following sections of this .inf file will need to be modified dependingon your control and the version of MFC that you are using to build yourcontrol:
  • Any reference to spindial should be changed to the name of your control. This includes comments and the following:
       spindial.ocx=spindial.ocx   [spindial.ocx]					
  • The following should be changed to the correct CLSID and FileVersion for your control:
       clsid={06889605-B8D0-101A-91F1-00608CEAD5B3}   FileVersion=1,0,0,001						
    The CLSID above can be obtained for your control from the control's ODLfile. The CLSID is associated with the coclass for the control. Forinstance, the above CLSID was obtained from the following section ofSpindial.odl:
       [ uuid(06889605-B8D0-101A-91F1-00608CEAD5B3),     helpstring("Spindial Control"), control ]     coclass Spindial						
    The FileVersion for the control can be obtained from the version resourcefor the control. As is true of any file with a version resource, this canbe obtained by opening the file (Spindial.ocx in this case ) versionresource with Visual Studio. From the File menu, select Open, and click Open as: Resources. Open the Version resource; the FileVersion that you are interested in is listed after FILEVERSION.
  • The last change that you need to make is to enter the correctFileVersion for each of the MFC DLLs, [mfc42.dll], [olepro32.dll], and[mscvrt.dll]. Note that if you are using Visual C++ 4.1 or earlier, you need to change any reference to Mfc42.dll to Mfc40.dll and any reference toMsvcrt.dll to Msvcrt40.dll.
The following FileVersions should be used:

VC 4.1 and earlier, use:

   Olepro32.dll   4,1,0,6038   Mfc40.dll      4,1,0,6139   Msvcrt40.dll  4,10,0,6038				

VC 4.2b and earlier, use:

   Olepro32.dll   4,2,0,6068   Mfc42.dll      4,2,0,6256   Msvcrt.dll    4,20,0,6164				

VC 5.0, use:

   Olepro32.dll   5,0,4055,1   Mfc42.dll     4,21,0,7022   Msvcrt.dll     5,0,0,7022				

VC 5.0sp1, use:

   Olepro32.dll   5,0,4055,1   Mfc42.dll     4,21,0,7160   Msvcrt.dll     5,0,0,7128				

VC 5.0sp2, use:

   Olepro32.dll   5,0,4055,1   Mfc42.dll     4,21,0,7160   Msvcrt.dll     5,0,0,7128				

VC 5.0sp3, use:

   Olepro32.dll   5,0,4230,1   Mfc42.dll     4,21,0,7303   Msvcrt.dll     5,0,0,7303				

VC 6.0, use:

   Olepro32.dll   5,0,4261,0   Mfc42.dll      6,0,8168,0   Msvcrt.dll     6,0,8168,0				

Notice that all versions of MFC between 4.2 and 6.0 use file always contains the latest version of the DLLs because they arebackward-compatible. If you are not compiling with a later build of MFC,you may not want to specify the latest FileVersion. Doing so may trigger anunnecessary download of the MFC DLLs.
For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
Safe Initialization and Scripting for ActiveX Controls
Signing Code with Microsoft Authenticode Technology
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
264570 INFO: WebCast: How Does Internet Component Download Work?

Article ID: 167158 - Last Review: 06/22/2014 18:18:00 - Revision: 7.0

  • kbcab kbctrl kbhowto kbinprocsvr KB167158