使用 Wix 在 MSI 中的自定义操作中出现错误时显示最终用户消息

c00*_*0fd 1 windows windows-installer wix

假设我有以下 WIX 标记,指示 MSI 安装程序从包含的 DLL 调用自定义操作:

<CustomAction Id="CA_SetProperties_Finalize" 
        Property="CA_OnInstallFinalize" 
           Value="[Installed],[REINSTALL],[UPGRADINGPRODUCTCODE],[REMOVE]" />

<CustomAction Id='CA_OnInstallFinalize' 
       BinaryKey='CADll' 
        DllEntry='msiOnInstallFinalize' 
         Execute='deferred' Impersonate='no' />

<InstallExecuteSequence>
  <Custom Action='CA_SetProperties_Finalize' 
          Before='InstallFinalize'></Custom>
  <Custom Action='CA_OnInstallFinalize' 
           After='CA_SetProperties_Finalize'></Custom>
</InstallExecuteSequence>

<Binary Id='CADll' SourceFile='Sources\ca-installer.dll' />
Run Code Online (Sandbox Code Playgroud)

DLL 本身具有以下用于自定义操作的 C++ 代码:

<CustomAction Id="CA_SetProperties_Finalize" 
        Property="CA_OnInstallFinalize" 
           Value="[Installed],[REINSTALL],[UPGRADINGPRODUCTCODE],[REMOVE]" />

<CustomAction Id='CA_OnInstallFinalize' 
       BinaryKey='CADll' 
        DllEntry='msiOnInstallFinalize' 
         Execute='deferred' Impersonate='no' />

<InstallExecuteSequence>
  <Custom Action='CA_SetProperties_Finalize' 
          Before='InstallFinalize'></Custom>
  <Custom Action='CA_OnInstallFinalize' 
           After='CA_SetProperties_Finalize'></Custom>
</InstallExecuteSequence>

<Binary Id='CADll' SourceFile='Sources\ca-installer.dll' />
Run Code Online (Sandbox Code Playgroud)

发生的情况是,当我的doWork方法失败时,安装不应继续,因此我返回ERROR_INSTALL_FAILURE。问题是,在这种情况下,安装程序会直接退出,安装 GUI 窗口也会消失。

所以我很好奇,是否有任何方法可以更改 Wix 标记,以便在我的自定义操作返回错误时能够显示用户消息?

Nat*_*arr 5

我用它来创建消息框来处理 dll 中的错误:

PMSIHANDLE hRecord = MsiCreateRecord(0);
MsiRecordSetString(hRecord, 0, TEXT("Enter the text for the error!"));
MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_ERROR + MB_OK), hRecord);
return ERROR_INSTALL_USEREXIT;
Run Code Online (Sandbox Code Playgroud)