6

我有一个基本的 WIX 自定义操作:

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

添加到安装程序:

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

问题是,无论我做什么,句柄 hInstaller 都无效。我已将操作设置为提交、延迟、更改 InstallExecute 序列中的位置,hInstaller 始终无效。

任何帮助,将不胜感激。谢谢。

4

2 回答 2

8

您需要导出调用的函数,以便 MSI 可以使用未修饰的 C 样式名称调用它

用这个替换你的代码

    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;
    }
于 2010-03-16T14:48:07.323 回答
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.

于 2013-06-17T04:24:12.130 回答