0
我想寫可變參數模板函數來幫助簡化從MSI DLL調用到MSI的錯誤報告。這是我與可變參數函數的第一次相遇(我還沒有聽說過術語),所以我顯然是搞砸了,傷得很厲害看到我是如何墜毀我試圖編譯:嘗試爲MSIprocessMessage失敗函數崩潰的C++編譯器
UINT ReportMSIMessage(MSIHANDLE hInstall, INSTALLMESSAGE eMessageType, PMSIHANDLE& hRec, int index)
{
return MsiProcessMessage(hInstall, eMessageType, hRec);
}
template <typename... Args> UINT ReportMSIMessage(MSIHANDLE hInstall, INSTALLMESSAGE eMessageType, PMSIHANDLE& hRec, int index, TCHAR message, Args... rest)
{
LRESULT lResult = MsiRecordSetString(hRec, index, message);
if (ERROR_SUCCESS != lResult)
return lResult;
return ReportMSIMessage(hInstall, eMessageType, hRec, index + 1, rest...);
}
template <typename... Args> UINT ReportMSIMessage(MSIHANDLE hInstall, INSTALLMESSAGE eMessageType, PMSIHANDLE& hRec, int index, int value, Args... rest)
{
LRESULT lResult = MsiRecordSetInteger(hRec, index, value);
if (ERROR_SUCCESS != lResult)
return lResult;
return ReportMSIMessage(hInstall, eMessageType, hRec, index + 1, rest...);
}
template <typename... Args> UINT ReportMSIMessage(MSIHANDLE hInstall, INSTALLMESSAGE eMessageType, Args... rest)
{
const int argCount = sizeof...(Args);
if (eMessageType == INSTALLMESSAGE_INFO)
{
PMSIHANDLE hLogRec = MsiCreateRecord(argCount-1);
return ReportMSIMessage(hInstall, eMessageType, hLogRec, 0, rest...);
}
else
{
PMSIHANDLE hLogRec = MsiCreateRecord(argCount);
return ReportMSIMessage(hInstall, eMessageType, hLogRec, 1, rest...);
}
}
當我編譯,編譯器掛起了好一陣,最後報告:
1> Note: non-fatal system error releasing memory (487)
1>SetupFunc.cpp(1460): fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'msc1.cpp', line 1325)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
再就是線的數百或數千行這樣的:
see reference to function template instantiation 'UINT ReportMSIMessage<PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,const char*,TCHAR*>(MSIHANDLE,INSTALLMESSAGE,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,PMSIHANDLE,int,const char *,TCHAR *)' being compiled
(這僅僅是最短的許多線)
FWIW,我不是一個真正的C++開發人員......但對於MSI C++ CA,您應該查看Windows Installer XML。它有一個C++項目模板,可以設置一切,幷包含一對可重複使用的庫。請參閱http://www.joyofsetup.com/2008/07/15/verbose-logging-from-wcautil/ –
另請注意WiX v3.10的發行說明:http://www.joyofsetup.com/2015/09/07/wix-toolset-v3-10-released /「DUtil錯誤檢查宏可變參數,因此開發人員不必再事先考慮他們在消息中需要多少個參數」 –