HOWTO: Packaging MFC Controls for Use Over the Internet

Last reviewed: February 9, 1998
Article ID: Q167158
The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, versions 4.1, 4.2b, 5.0, 5.0sp1
  • Microsoft Internet Explorer versions 3.0, 3.01, 3.02, 4.0, 4.01 for Windows 95
  • Microsoft Internet Explorer versions 3.0, 3.01, 3.02, 4.0, 4.01 for Windows NT 4.0

SUMMARY

When you embed ActiveX Controls in a web page using the <OBJECT> tag, the CODEBASE attribute used to specify the download location can point to a .cab file. This is the recommended way to package MFC ActiveX Controls. Packaging an MFC ActiveX Control in a cabinet file allows an .inf file to be included to control installation of the ActiveX Control, allows for dependent DLLs to be named and a location for them provided, allows for code signing, and automatically compresses the code for quicker download.

MORE INFORMATION

ActiveX controls are embedded in web pages using the <OBJECT> tag. The CODEBASE attribute of the <OBJECT> tag specifies the location from which to download the control. CODEBASE can point to a number of different file types successfully.

For instance, CODEBASE can point directly to an .ocx file as follows:

CODEBASE="http://example.microsoft.com/somecontrol.ocx#version=4,70,0,1086"

Since this downloads and installs the .ocx file only, this solution relies on any necessary supporting DLLs already existing on the client machine. In most cases, it should not be assumed that these DLLs will exist on the client and be of the necessary version.

Another alternative is for CODEBASE to point to an .inf file, for example:

   CODEBASE="http://example.microsoft.com/doyoutrustme.inf"

An .inf file will control the installation of an .ocx and its supporting files. 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 this method, supporting DLLs can be referenced and the cabinet file signed. Please note: if the below directions 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 look similar to the following:

   CODEBASE="http://example.microsoft.com/acontrol.cab#version=1,2,0,0"

Note here that the #Version information applies to the version of the control specified by the CLASSID parameter of the <OBJECT> tag.

Cab Packaging Overview

In the Cabinet Software Development Kit (also called Cabinet SDK, or CAB Development Kit) you will find the necessary tools to construct cabinet (.cab) files. The CAB SDK may be downloaded from http://www.microsoft.com/workshop/prog/cab/cabdl.htm.

The cabinet file that CODEBASE points to should contain the .ocx file and an .inf file which 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, and other dependent DLLs, should be packaged in separate cabinet files and referenced by the control's .inf file. The following example illustrates how to package the MFC Spindial sample control.

The <OBJECT> tag to include the Spindial control in a web page will look similar to the following:

   <OBJECT ID="Spindial1" WIDTH=200 HEIGHT=200
   CLASSID="CLSID:06889605-B8D0-101A-91F1-00608CEAD5B3"
   CODEBASE="http://example.microsoft.com/spindial.cab#Version=1,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 Spindial.cab must contain two files, Spindial.ocx and Spindial.inf. The command to build this cabinet file will be similar to the following depending on the path to your installation of the Cabinet Development Kit:

   C:\CabDevKit\cabarc.exe -s 6144 N spindial.cab spindial.ocx spindial.inf

The "-s 6144" parameter passed to cabarc.exe reserves space in the cabinet for code signing. The following is an example .inf for the MFC Spindial control. This .inf file can be modified to download any MFC ActiveX Control by changing Spindial'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
   msvcrt.dll=msvcrt.dll
   mfc42.dll=mfc42.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=http://activex.microsoft.com/controls/vc/mfc42.cab
   ; 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 mfc42.cab 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 depending on your control and the version of MFC that you are using to build your control:

Any reference to spindial should be changed to the name or 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 ODL file. The CLSID is associated with the coclass for the control. For instance, the above CLSID was obtained from the following section of Spindial.odl:

   [ uuid(06889605-B8D0-101A-91F1-00608CEAD5B3),
     helpstring("Spindial Control"), control ]
     coclass Spindial

The FileVersion for the control can be obtained from the version resource for the control. As is true of any file with a version resource, this can be obtained by opening the file (Spindial.ocx in this case ) version resource with Visual Studio. From the File menu, select Open, and click Open as: Resources. Open the Version resource and the FileVersion that you are interested in is listed after FILEVERSION.

The last change that you will need to make is to enter the correct FileVersion for each of the MFC DLLs, [mfc42.dll], [olepro32.dll], and [mscvrt.dll]. Note that if you are using VC 4.1 or earlier, you will need to change any reference to mfc42.dll to mfc40.dll and any reference to msvcrt.dll to msvcrt40.dll.

The following FileVersions should be used:

VC 4.1 and earlier, use http://activex.microsoft.com/controls/vc/mfc40.cab

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

VC 4.2b and earlier, use http://activex.microsoft.com/controls/vc/mfc42.cab

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

VC 5.0, use http://activex.microsoft.com/controls/vc/mfc42.cab

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

VC 5.0sp1, use http://activex.microsoft.com/controls/vc/mfc42.cab

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

VC 5.0sp2, use http://activex.microsoft.com/controls/vc/mfc42.cab

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

VC 5.0sp3, use http://activex.microsoft.com/controls/vc/mfc42.cab

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

Notice that all versions of MFC between 4.2 and 5.0sp3 use Mfc42.cab. This .cab file will always contain the latest version of the DLLs as they are backward 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 an unnecessary download of the MFC DLLs.

REFERENCES

  • ActiveX SDK - Packaging component code for automatic download
  • ActiveX SDK - Safety API Reference
  • ActiveX SDK - Signing with Microsoft Authenticode Technology
  • ActiveX SDK - Cabinet (.cab) File Technology: Data Compression and Disk Layout
  • Internet Client SDK – Component Development, ActiveX Controls

(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Robert Duke, Microsoft Corporation


Additional query words: 4.00
Keywords : AXSDKCompDownload MfcOLE
Technology : kbole
Version : WINDOWS NT: 4.1, 4.2b, 5.0, 5.0sp1
Platform : WINDOWS winnt
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 9, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.