说,我有以下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标记,以便在我的自定义操作返回错误时能够显示用户消息?
答案 0 :(得分:3)
我用它来创建消息框来处理我的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;
答案 1 :(得分:1)
我能够将该代码转换为VB.NET并在自定义操作中使用它来显示错误的弹出窗口
.Net代码看起来差异很大
Private Shared Sub DisplayMSIError(session As Session, msg As String)
Dim r As New WindowsInstaller.Record(0)
r.SetString(0, msg)
session.Message(InstallMessage.Error, r)
End Sub
我也在MSDN上发现它使用vbscript http://msdn.microsoft.com/en-us/library/xc8bz3y5(v=vs.80).aspx
答案 2 :(得分:0)
对于C#用户...
string msg = "XXXXXX code is invalid";
Record r = new Microsoft.Deployment.WindowsInstaller.Record(0);
r.SetString(0, msg);
session.Message(InstallMessage.Error, r);
session.Log(msg);