假设,我有以下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' />
DLL本身有如下自定义操作的C++代码:
#pragma comment(linker, "/EXPORT:msiOnInstallFinalize=_msiOnInstallFinalize@4")
extern "C" UINT __stdcall msiOnInstallFinalize(MSIHANDLE hInstall)
{
//Do the work
if(doWork(hInstall) == FALSE)
{
//Error, cannot continue!
return ERROR_INSTALL_FAILURE;
}
return ERROR_SUCCESS;
}
当我的
doWork
方法失败时,安装不应该继续,所以我返回ERROR_INSTALL_FAILURE
。问题是,在这种情况下,安装程序只需退出,安装gui窗口就会消失。所以我很好奇,有没有什么方法可以更改wix标记,以便在自定义操作返回错误时显示用户消息?
最佳答案
我使用此创建消息框来处理来自我的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;
关于windows - 如果使用Wix的MSI中的自定义操作出错,则显示最终用户消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17779237/