DLL/TLB Library Setup

Previous | Contents | Next

- Appendix B: DLL/TLB Library Setup

- Introduction
- Library Installation

- Introduction
- Parameters
- Options
- Notes
- Example

- Library Uninstallation

- Introduction
- Parameters
- Options
- Example

- Visual Basic 6 Run-Time Files

# Appendix B: DLL/TLB Library Setup

## B.1 Introduction

The Library header file can be used to setup dynamic link libraries (DLL) and type libraries (TLB). If necessary, the following actions will be performed:

- File copying
- File copying on reboot
- Version checks
- Registration and unregistration
- Registration and unregistration on reboot
- Shared DLL counting
- Windows File Protection checks

The macros are stored in the header file Library.nsh, which should be included in scripts using this system:

    !include Library.nsh

Note that the library macros are limited on non-Windows platforms. DLL version information is required when compiling on non-Windows platforms.

## B.2 Library Installation

### B.2.1 Introduction

The InstallLib macro allows you to install a library. It sets the error flag if something went wrong during library setup.

To ask the user for a reboot, if required, use the Modern UI with a Finish page or use IfRebootFlag and make your own page or message box.

### B.2.2 Parameters

    libtype shared install localfile destfile tempbasedir

libtype

The type of the library

DLL - Dynamic link library (DLL)
REGDLL - DLL that has to be registered
REGEXE - EXE COM server that has to be registered using /regserver
TLB - Type library or DLL that contains a type library
REGDLLTLB - DLL that has to be registered and contains a type library

shared

Specify whether the library is shared with other applications

NOTSHARED - The library is not shared
$VARNAME - Variable that is empty when the application is installed for the first time, which is when the shared library count will be increased.

install

Specify the installation method

REBOOT_PROTECTED

- Upgrade the library on reboot when in use (required for system files).
- Upgrade the library if the file is not protected by Windows File Protection.

NOREBOOT_PROTECTED

- Warns the user when the library is in use. The user will have to close applications using the library.
- Upgrade the library if the file is not protected by Windows File Protection.

REBOOT_NOTPROTECTED

- Upgrade the library on reboot when in use (required for system files).
- Upgrade the library without checking for Windows File Protection.

NOREBOOT_NOTPROTECTED

- Warns the user when the library is in use. The user will have to close applications using the library.
- Upgrade the library without checking for Windows File Protection.

localfile

Location of the library on the compiler system

destfile

Location to store the library on the user's system

tempbasedir

Directory on the user's system to store a temporary file when the system has to be rebooted.

For Windows 9x/ME support, this directory should be on the same volume as the destination file (destfile). The Windows temp directory could be located on any volume, so you cannot use this directory.

### B.2.3 Options

Define any of the following before inserting a InstallLib macro to modify its behavior as specified.

#### B.2.3.1 LIBRARY_X64

- Installs a DLL built for Windows x64.
- Warning: This resets SetRegView and file system redirection.

#### B.2.3.2 LIBRARY_SHELL_EXTENSION

- Define this before inserting InstallLib macro to call SHChangeNotify with SHCNE_ASSOCCHANGED after registration.
- Use this to refresh the shell when installing a shell extension or when changing file associations.

#### B.2.3.3 LIBRARY_COM

- Define this before inserting InstallLib macro to call CoFreeUnusedLibraries after registration.
- Use this for unloading all unnecessary libraries from memory when installing COM libraries.

#### B.2.3.4 LIBRARY_IGNORE_VERSION

- Define this before inserting InstallLib macro to ignore version information in the file and always install it, even if it already exists.
- Use this when an older or specific version is required.
- Not recommended for DLLs installed to $SYSDIR.

#### B.2.3.5 LIBRARY_INSTALL_EQUAL_VERSION

- Define this before inserting InstallLib macro to overwrite the file even if the version is the same as the existing file.

### B.2.4 Notes

- If you need to support Windows 9x/ME, you can only use short filenames (8.3).
- Warning: Always use redistributable files when deploying DLLs, never copy files from your system directory!

### B.2.5 Example

#### B.2.5.1 Unshared DLL

     !insertmacro InstallLib REGDLL NOTSHARED REBOOT_NOTPROTECTED dllname.dll $SYSDIR\dllname.dll $SYSDIR

#### B.2.5.2 Shared DLL

     ;Add code here that sets $ALREADY_INSTALLED to a non-zero value if the application is
     ;already installed. For example:

     IfFileExists "$INSTDIR\MyApp.exe" 0 new_installation ;Replace MyApp.exe with your application filename
       StrCpy $ALREADY_INSTALLED 1
     new_installation:

     !insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_NOTPROTECTED dllname.dll $SYSDIR\dllname.dll $SYSDIR

## B.3 Library Uninstallation

### B.3.1 Introduction

The UnInstallLib macro allows you to uninstall a library. It sets the error flag if something went wrong during library removal.

### B.3.2 Parameters

    libtype shared uninstall file

libtype

The type of the library

DLL - Dynamic link library (DLL)
REGDLL - DLL that has to be unregistered
REGEXE - EXE COM server that has to be unregistered using /unregserver
TLB - Type library or DLL that contains a type library
REGDLLTLB - DLL that has to be unregistered and contains a type library

shared

Specify whether the library is shared with other applications

NOTSHARED - The library is not shared
SHARED - The library is shared and should be removed if the shared library count indicates that the file is not in use anymore..

uninstall

Specify the uninstallation method

NOREMOVE

- The library should not be removed. You should use this option for common or important system files such as the Visual Basic/C++/MFC runtimes.

REBOOT_PROTECTED

- Remove the library on reboot when in use (required for system files).
- Remove the library if the file is not protected by Windows File Protection.

NOREBOOT_PROTECTED

- Warns the user when the library is in use. The user will have to close applications using the library.
- Remove the library if the file is not protected by Windows File Protection.

REBOOT_NOTPROTECTED

- Remove the library on reboot when in use (required for system files).
- Remove the library without checking for Windows File Protection.

NOREBOOT_NOTPROTECTED

- Warns the user when the library is in use. The user will have to close applications using the library.
- Remove the library without checking for Windows File Protection.

file

Location of the library

### B.3.3 Options

Define any of the following before inserting a UnInstallLib macro to modify its behavior as specified.

#### B.3.3.1 LIBRARY_X64

- Uninstalls a DLL built for Windows x64.
- Warning: This resets SetRegView and file system redirection.

#### B.3.3.2 LIBRARY_SHELL_EXTENSION

- Define this before inserting UninstallLib macro to call SHChangeNotify with SHCNE_ASSOCCHANGED after unregistration. Use this to refresh the shell when uninstalling a shell extension or when changing file associations.

#### B.3.3.3 LIBRARY_COM

- Define this before inserting UninstallLib macro to call CoFreeUnusedLibraries after unregistration. Use this for unloading all unnecessary libraries from memory when uninstalling COM libraries.

### B.3.4 Example

     !insertmacro UnInstallLib REGDLL SHARED REBOOT_NOTPROTECTED $SYSDIR\dllname.dll

## B.4 Visual Basic 6 Run-Time Files

A new VB6RunTime.nsh header file is available for the setup of the VB6 run-time files. To obtain the latest run-time files, download vb6runtime.zip and extract this file.

     !include VB6RunTime.nsh

     Var AlreadyInstalled

     Section "-Install VB6 run-time files"

       ;Add code here that sets $AlreadyInstalled to a non-zero value if the application is already installed. For example:
       IfFileExists "$INSTDIR\MyApp.exe" 0 new_installation ;Replace MyApp.exe with your application filename
         StrCpy $AlreadyInstalled 1
       new_installation:

       !insertmacro VB6RunTimeInstall C:\vb6runtimes $AlreadyInstalled ;Replace C:\vb6runtimes with the location of the files

     SectionEnd

     Section "-un.Uninstall VB6 run-time files"

       !insertmacro VB6RunTimeUnInstall

     SectionEnd

Remarks:

- You may have to install additional files for such Visual Basic application to work, such as OCX files for user interface controls.
- Installation of the run-time files requires Administrator or Power User privileges. Use the Multi-User header file to verify whether these privileges are available.
- Add a Modern UI finish page or another check (see IfRebootFlag) to allow the user to restart the computer when necessary.

Previous | Contents | Next