HOWTO: Downloading Dependent DLLs in IE with .inf File

Last reviewed: October 3, 1997
Article ID: Q165075
The information in this article applies to:
  • Microsoft Internet Explorer (Programming), version 3.0, 3.01, 3.02, 4.0

SUMMARY

It is often necessary to download dependent DLLs along with an ActiveX Control. MFC and VB controls have this requirement.

This article will explain three ways which this can be done.

MORE INFORMATION

There are three ways to include dependent DLLs in the download for a control. The first way is to include the DLL(s) in the CAB file for the control along with the OCX and INF files. The downside of this is that the DLL will be downloaded any time the control is downloaded. In some cases, this is appropriate. The next way is to package the dependent DLL(s) in a separate CAB file and refer to that in the INF file for the control. The third way also packages the DLL in a separate CAB file but the CAB file is referred to in the control’s INF file with a hook. Using a hook allows the download process to execute an INF or EXE file contained in the dependent CAB file.

To add a dependency for an OCX (Simpdll.dll in this example), a section similar to the section for the control is added to the [AddCode] section of the INF file:

   [Add.Code]
   TestDw.ocx=TestDw.ocx
   simpdll.dll=simpdll.dll

A section is then added to the INF file to control the installation of the DLL:

   [simpdll.dll]
   FileVersion=1,0,0,1
   file-win32-x86=thiscab

This is the first way mentioned to include a DLL dependency in a download.

To include the DLL in a separate CAB file, all that is necessary is to change the location from "thiscab" to the URL at which the dependent CAB will be located:

   file-win32-x86=http://example.microsoft.com/simpdll.cab

In this case, Simpdll.cab contains only simpdll.dll.

Multiple DLLs can be added to the INF and CAB files above if necessary.

The third way to package dependent DLLs is to refer to the dependent DLL’s CAB file using a hook. With this technique, an INF or EXE file in the dependent CAB can be executed on download.

The following section from an .inf file controls the dependent DLL download for MFC controls:

   [Add.Code]
   ...
   msvcrt.dll=msvcrt.dll
   mfc42.dll=mfc42.dll
   olepro32.dll=olepro32.dll

   [msvcrt.dll]
   FileVersion=4,20,0,6164
   hook=mfc42installer

   ...

   [mfc42installer]
   file-win32-x86=http://activex.microsoft.com/controls/vc/mfc42.cab
   run=%EXTRACT_DIR%\mfc42.exe

In this case, the MFC DLLs are packaged in a self-extracting .exe file, which is contained in the .cab file (mfc42.cab). However, tools to make self-extracting .exe files are not currently available from Microsoft. Therefore, you will either need to package dependent DLLs with an .inf file or reference the .inf file in the installation hook:

   [yourinstaller]
   file-win32-x86=http://example.microsoft.com/simpdll.cab
   InfFile=your.inf

Or, you will need to build a self extracting EXE file using third party tools.

To illustrate, the following is the .inf file used to install the dependent MFC DLLs. You can modify this to install your own DLLs in the same way that the MFC DLLs are installed.

   ; ========================= Mfc42.inf =========================

   ; This file will control the download of the MFC 4.2 DLLs

   [version]
   ; version signature (same for both NT and Win95) do not remove
   signature="$CHICAGO$"
   AdvancedINF=2.0

   [SourceDisksNames]
   ; This section specifies that all sources are in the "default"
   ; location.
   1="default",,1

   [DefaultInstall]
   ; Default section to process and copy all files under the section
   ; mfcdllsx.files and Register DLLs under the section mfcdllsx.register.
   CopyFiles=mfcdllsx.files
   RegisterOCXs=mfcdllsx.register

   [DestinationDirs]
   ; Destination Directories for CopyFiles Sections.
   ; 11 indicates LDID_SYS - system directory
   mfcdllsx.files=11

   [mfcdllsx.files]
   ; ,,,32 - Suppress version conflict dialog and don't overwrite newer
   ; DLLs
   msvcrt.dll,,,32
   mfc42.dll,,,32
   olepro32.dll,,,32

   [mfcdllsx.register]
   ; msvcrt.dll is not self registering
   %11%\mfc42.dll
   %11%\olepro32.dll

   ; ====================== Mfc42.inf ======================

A DLL needs to be listed in the .register section if it exports a DllRegisterServer function. This can be determined by examining the DLL with the Visual C compiler's Dumpbin.exe utility. You can also run Regsvr32 on the DLL, which attempts to register the DLL. Regsvr32 loads the DLL, verifies that DllRegisterServer is properly exported by calling GetProcAddress() on the DLLRegisterServer function. If it succeeds, the function DllRegisterServer is exported and is then called.

Beware, however, that running Regsvr32 on the DLL may have undesirable side effects. When DllRegisterServer is called, it makes appropriate registry entries pointing to the DLL location on the machine. For example, typing the following in a DOS prompt, for test purposes, can cause problems:

   copy mfc42.dll C:\Test
   run "D:\msdev\bin\REGSVR32.EXE C:\Test\mfc42.dll"
   delete mfc42.dll

The next time the system tries to look for Mfc42.dll, it looks up the registry, finds that the file is mapped to C:\Test\Mfc42.dll, and doesn't find it there. Running Regsvr32 on a file that is already installed on a machine does not cause problems.

Installing a DLL with a hook and a self extracting EXE is useful for the following reason: If a DLL that needs to be upgraded is already loaded in memory, the download will fail. This is a known problem, which has been fixed in Internet Explorer version 4.0. Internet Explorer 4.0 will suggest a reboot and load the new DLL during the reboot.

REFERENCES

For additional information, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q167158
   TITLE     : How To Package MFC Controls for Use Over the Internet

   ARTICLE-ID: Q167597
   TITLE     : Specifying FileVersion and #Version for Component Download

(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Robert Duke, Microsoft Corporation
Keywords          : AXSDKCompDownload kbhowto
Version           : Win:3.0,3.01,3.02,4.0
Platform          : WINDOWS
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: October 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.