WIX C++自定义操作

Adr*_*ciu 5 c++ custom-action wix name-decoration

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

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

添加到安装程序:

   <CustomAction Id="CustomActionId" FileKey="CustomDll" DllEntry="MyCustomAction"/>
   <InstallExecuteSequence>
       <Custom Action="CustomActionId" Before="InstallFinalize" />
   </InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)

问题是,无论我做什么,句柄hInstaller都无效.我已将动作设置为commit,deferred,在InstallExecute序列中更改了位置,hInstaller始终无效.

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

Cha*_*ent 7

您需要导出被调用的函数,以便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;
    }
Run Code Online (Sandbox Code Playgroud)