6

I have a basic WIX custom action:

        UINT __stdcall MyCustomAction(MSIHANDLE hInstaller)
        {   
            DWORD dwSize=0;
            MsiGetProperty(hInstaller, TEXT("MyProperty"), TEXT(""), &dwSize);
            return ERROR_SUCCESS;
        }

Added to the installer:

   <CustomAction Id="CustomActionId" FileKey="CustomDll" DllEntry="MyCustomAction"/>
   <InstallExecuteSequence>
       <Custom Action="CustomActionId" Before="InstallFinalize" />
   </InstallExecuteSequence>

The problem is that, no matter what i do, the handle hInstaller is not valid. I've set the action to commit, deferred, changed the place in InstallExecute sequence, hInstaller is always not valid.

Any help would be appreciated. Thanks.

agf
  • 148,965
  • 36
  • 267
  • 227
Adrian Fâciu
  • 11,776
  • 3
  • 50
  • 66

2 Answers2

8

You need to export the called function so MSI can call it using undecorated C style name

Replace your code with this

    extern "C" _declspec(dllexport) UINT __stdcall MyCustomAction(MSIHANDLE hInstall);

    extern "C" UINT __stdcall MyCustomAction(MSIHANDLE hInstall)
    {   
        DWORD dwSize=0;
        MsiGetProperty(hInstaller, TEXT("MyProperty"), TEXT(""), &dwSize);
        return ERROR_SUCCESS;
    }
Charles Gargent
  • 1,767
  • 2
  • 13
  • 19
3

As mentioned here, the only way to overcome the mangling of a __stdcall is to use:

#pragma comment(linker, "/EXPORT:SomeFunction=_SomeFunction@@@23mangledstuff#@@@@")

This creates a second entry in the DLL export table.

Community
  • 1
  • 1
Pierre
  • 3,470
  • 1
  • 32
  • 33
  • 3
    Another way to insure the non-mangled function name is included in the DLL exports, is to EXPORT it in a DEF file, and add it to the Linker Properties (Linker -> Input -> Module Definition File). – Pierre Jun 22 '13 at 10:49