非常令人沮丧的是,Windows 安装程序不支持 DoAction 中的 MsiProcessMessage()。幸运的是,WiX 工具集中的 wcautil.lib 有一些辅助方法,可以使其不太难复制。它看起来很像这样:
int nDiagnosticChannels = 0;
PMSIHANDLE hErrorTable;
PMSIHANDLE hErrorMessage;
LPWSTR sczError = NULL;
LPWSTR sczErrorFormatted = NULL;
hr = WcaGetIntProperty(L"DIAGNOSTICCHANNELS",&nDiagnosticChannels);
ExitOnFailure(hr, "Failed to read DIAGNOSTICCHANNELS property.");
if (nDiagnosticChannels > 10000)
{
// "12345" is your custom error number.
hr = WcaOpenExecuteView("SELECT `Message` FROM `Error` WHERE `Error`=12345", &hErrorTable);
ExitOnFailure(hr, "Failed to query error table.");
hr = WcaFetchSingleRecord(hErrorTable, hErrorMessage);
ExitOnFailure(hr, "Failed to get message from error table.");
hr = WcaGetRecordString(hErrorMessage, 1, &sczError);
ExitOnFailure(hr, "Failed to get error message");
hr = WcaGetFormattedString(sczError, &sczErrorFormatted);
ExitOnFailure(hr, "Failed to format error message");
::MessageBox(NULL, sczErrorFormatted, szTitle, MB_OK|MB_ICONEXCLAMATION);
}
LExit:
ReleaseStr(sczError);
ReleaseStr(sczErrorFormatted);
return hr;
如果那里有更多的辅助函数来减少一些函数调用,那就太好了,但它会起作用。