Thursday, January 26, 2012

Debug custom action dll

You have a pretty CustomAction element in your Wix configuration. For some reason you keep getting a 1723 error when the installer attempts to run your custom action. At this point, you think, "Well.. this sucks... I wish I could debug (step through) the DLL and see where the problem is."

So here's how this post will help you

PRE-CONDITIONS:
1. You are writing a C/ C++ Custom Action DLL which is stored as a Binary in the installer.
2. You have already created a .DEF file which exports the DLL entry point. (Sanity test)
3. Comment out any code that uses the MSIHANDLE parameter.

The best way is to create a stand alone .exe file which attempts to run the custom action dll. Here's what that code looks like:

#include "stdafx.h"
#include <msi.h>

typedef UINT (__stdcall * PCUSTOMACTION)(MSIHANDLE handle);


int _tmain(int argc, _TCHAR* argv[])
{
MSIHANDLE handle = 0;
HMODULE library = LoadLibrary(L"CustomAction.dll");
if (library != NULL)
{
PCUSTOMACTION pCustomAction = (PCUSTOMACTION)GetProcAddress(library, "DllEntryPoint");
if (pCustomAction != NULL)
{
pCustomAction(handle);
}
}
return 0;
}


Run it with your favorite debugger attached, and voila!

No comments:

Post a Comment