Sunday, January 20, 2008

Windows Installer Dll - Part 1

Audience: Install Developers, Beginner, Windows Installer (MSI) Knowledge

This is Part 1 of a three part series that demonstrates how to use C++ in a Windows Installer Custom Action.

Creating a dll to be called in a custom action is easy. I use Visual Studio 2005 (why? – because that's what the company I work at uses, and I like it). Obviously, there are other compilers out there that will get you the same results but, for our purpose we will demonstrate the VC++ way. You’ll be up and running in minutes.



1 - Start a new project.

  • Project Type: MFC DLL
  • DLL Type: Regular DLL with MFC statically linked
  • Name: CustomActions
I find this the quickest and easiest method, the wizard creates everything you need. You could choose other types (like Win32 project) however, MFC DLL is my preference.

I always recommend static linking for Windows Installer Dlls – Typically the Dll will be streamed from the .msi to the %temp% folder, and called from there. Statically linking helps ensure everything you need is contained in one dll.



2 - Update Project Settigns, and Link to Msi.lib

Open the project properties for CustomActions, and link to Msi.lib
linker settings

Open stdafx.h, add the following includes.

#include <MsiQuery.h>       //Windows Installer API
#include <Msi.h>



3 - Write your Custom Action(s), Export the Function

Open CustomActions.cpp, and add your code. Each Custom Action requires the following prototype.

/*     MyFunction     **************************************

Args: [in] MSIHANDLE hMsi
       - handle to running install (passed by the Windows Installer)

Desc:     Example
************************************************************/
UINT __stdcall MyFunction(MSIHANDLE hMsi)
{

    return ERROR_SUCCESS;
}


Open CustomActions.def and export the function name.

; CustomActions.def : Declares the module parameters for the DLL.

LIBRARY     "CustomActions"

EXPORTS
    ; Explicit exports can go here
     MyFunction



4 - Build the dll

That’s it the dll is ready to go...

The next step is adding the .dll to your setup project, which is covered in Part 2.




Saturday, January 19, 2008

Windows Installer Dll - Introduction

Audience: Install Developers, Beginner, Windows Installer (MSI) Knowledge

This is the introduction to a three part series that demonstrates how to use C++ in a Windows Installer Custom Action.

Windows Installer Actions:

Every task the Windows Installer performs is called an action. Actions are equivalent to what common programming languages refer to as functions, methods or procedures.

There are over 70 Standard Windows Installer Actions. http://msdn2.microsoft.com/en-us/library/aa372022(VS.85).aspx

To extend the standard functionality, use a Custom Action.



Custom Actions:

Setup authors can write their own actions (Custom Actions), to extend the Windows Installer’s default functionality.

There are several types of Custom Actions. http://msdn2.microsoft.com/en-us/library/aa368066(VS.85).aspx

This article will deal specifically with using a .dll though a custom action. (Type 1 or Type 17).



Windows Installer Dll

Even if you are using InstallScript in a basic MSI project, behind the scenes a .dll is being called. I prefer to skip InstallScript all together, and go for C++.

Not that there is anything wrong with InstallScript. It has just been my experience that making your own .dll is much faster, more portable, and you have more options as to what can be done.

This article will show you how to get up and running. Part 1 >




Wednesday, January 16, 2008

Starting up!

This is the start of my Release Engineering and Install Developing blog.

Release Engineering commonly refers to the process of building, deploying and maintaining software through a product’s life cycle. This is going to be more of a ‘how to’ blog. If you don’t know what Release Engineering and Install Developing is, then blogs is likely not for you.

I’ll be posting code snippets, solutions to common challenges, tips, tricks and general articles here. The intent is to create a blog where ideas and solutions can be freely exchanged.

I have been developing installation packages on Mac and PC for about 8 years now. My main area of expertise are;

  • Windows Installer
  • InstallShield, Installer Wise
  • Scripting (InstallScript, JScript, VBScript, Pearl, Batch files, WSH)
  • Automation for Quality Assurance
  • C++ (MFC)
  • Html/CSS

I’ll be posting my first ‘real’ article soon.

Thanks for visiting.

Note: If you want to know more about what Release Engineering is, here’s a great explanation. One More Pointless Blog: Software Release Engineering