Step 2 Create the CAB File
This section describes creating CAB files for distributing ATL and MFC controls over the Internet. If you need more information about CAB files, see the Cabinet File Reference in the Platform SDK section Setup and System Management Services\Setup API\Overview\Cabinet Files. The Platform SDK is included with the Visual C++ 5.0 online documentation and in the MSDN Library.
To create a CAB file:
1. Create an INF file (see Creating an INF File below).
2. Run the CABARC utility (available in the CAB&SIGN directory on the CD) to make the CAB file.
INF Files
An .inf file contains data that Microsoft® Windows 95/98, Windows NT 4.0, and Windows 2000 and later use to load and register a bundled control (as well as any files required by that control). Each section of the .inf file is described below.
Read Carefully:
Before talking about the sections of the .inf file let’s take the following scenario:
A developer created an COM Object using ATL. The control is called MyCtrl.ocx which, in order to run, needs the dependent DLL called MyFile.DLL.
The developer wants to package the COM Object with its related DLL into a .cab file that is distributable over Internet.
Note: since the control was created using ATL then atl.dll is needed on the user machine in order to run the control.
The developer wrote the following MyFile.inf:
[version]
signture="$CHICAGO$"
AdvancedINF=2.0
[Add.Code]
MyFile.DLL = MyFile.DLL
ATL.DLL = ATL.DLL
MyCtrl.ocx = MyCtrl.ocx
[MyFile.DLL]
file-win32-x86=thiscab
FileVersion=
DestDir=11
RegisterServer=yes
[ATL.DLL]
file-win32-x86=thiscab
FileVersion=
DestDir=11
RegisterServer=yes
[MyCtrl.ocx]
file-win32-x86=thiscab
clsid={46A5E7C2-3003-11D4-8735-00E0295AF9CE}
FileVersion=
DestDir=11
RegisterServer=yes
All explanations that follow depend on the above mentioned scenario.
Creating the .INF File
The first section in the .inf file is the [version] section. In the sample .inf, this section has the following format:
[version]
signature="$CHICAGO$"
AdvancedINF=2.0
The signature= tag specifies that the .inf version is compatible with Windows 95/98, Windows NT 4.0, and Windows 2000 and later.
The AdvancedINF= tag identifies the version of Advpack.dll that Internet Explorer 4.0 must load in order to parse this .inf file. In this case, version 2.0 is required.
The [Add.Code] Section of the .inf File:
The second section of the .inf file is the largest section. In addition to the section immediately following the [Add.Code] tag, this section includes the subsections that are identified by the [MyFile.DLL], [atl.dll], [MyCtrl.ocx] tags.
The [Add.Code] section maps files required by a given .ocx file to subsections in the .inf file. In the sample .inf file, this section has the following format:
[Add.Code]
MyFile.DLL = MyFile.DLL
ATL.DLL = ATL.DLL
MyCtrl.ocx = MyCtrl.ocx
The First line in this section maps MyFile.DLL (the file that contains the needed DLL) to a subsection of the same name.
The Second line in this section maps ATL.DLL to a subsection of the same name. The ATL.DLL is required on a user's computer before the control will successfully run.
The Third line in this section maps MyCtrl.OCX (the file that contains the sample control) to a subsection of the same name.
[MyFile.DLL]
file-win32-x86=thiscab
FileVersion=
DestDir=11
RegisterServer=yes
The first line in this subsection specifies that the x86 binary is found in the same .cab file as the .inf file.
The second line specifies the File’s version.
The Third line in this subsection specifies the destination directory on the user’s machine where the file will be installed.
The fourth line specifies that Internet Explorer 4.0 and later should register the control (using the specified version number).
[ATL.DLL]
file-win32-x86=thiscab
FileVersion=
DestDir=11
RegisterServer=yes
The first line in this subsection specifies that the x86 binary is found in the same .cab file as the .inf file.
The second line specifies the File’s version.
The Third line in this subsection specifies the destination directory on the user’s machine where the file will be installed.
The fourth line specifies that Internet Explorer 4.0 and later should register the control (using the specified version number).
The [MyCtrl.ocx] subsection of the [Add.Code] section:
The [MyCtrl.ocx] subsection has the following format:
[MyCtrl.ocx]
file-win32-x86=thiscab
clsid={46A5E7C2-3003-11D4-8735-00E0295AF9CE}
FileVersion=
DestDir=11
RegisterServer=yes
The first line in this subsection specifies that the x86 binary is found in the same .cab file as the .inf file.
The second line specifies the control's CLSID.
The third line specifies the control's version.
The fourth line in this subsection specifies the destination directory on the user’s machine where the file will be installed.
The fifth line specifies that Internet Explorer 4.0 and later should register the control (using the specified CLSID and version number).
Important Note: Note that if your control requires that a DLL be registered before the control (as required in our scenario), its corresponding entry in the .inf file must precede the control's entry in the file. Also, note that the order of the source files in the command line that is passed to Cabarc.exe must match the order of the file references in the .inf file.
Building the .cab File
Once you have installed Cabarc.exe and built the .inf file for your package, you can build the cab file. In the case of the sample .cab file, this entailed running Cabarc.exe with the following arguments:
C:\cab&sign\Cabarc –s 6144 n MyControl.cab MyFile.DLL MyCtrl.ocx MyFile.inf
Where MyControl.cab is the name of the generated .cab file.
(C:\cab&sign\Cabarc can be written at the command prompt for a list of options for the utility Cabarc.exe)
Note:
1.The order of the files is related to the order indicated inside the .inf file.
2.You must run the Cabarc.exe in the directory containing your control .inf files.