2015-09-04 88 views
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 

(這僅僅是最短的許多線)

+0

FWIW,我不是一個真正的C++開發人員......但對於MSI C++ CA,您應該查看Windows Installer XML。它有一個C++項目模板,可以設置一切,幷包含一對可重複使用的庫。請參閱http://www.joyofsetup.com/2008/07/15/verbose-logging-from-wcautil/ –

+0

另請注意WiX v3.10的發行說明:http://www.joyofsetup.com/2015/09/07/wix-toolset-v3-10-released /「DUtil錯誤檢查宏可變參數,因此開發人員不必再事先考慮他們在消息中需要多少個參數」 –

回答

0

其中一個問題是TCHAR參數應該是TCHAR *而不是。這可能會干擾編譯器選擇正確的模板實例,重載或任何你稱之爲的能力,因爲我正在用TCHAR *參數調用模板函數。另一個問題可能是靠近列表末尾的參數數據類型的相似性。但我需要添加一個int *參數來接收來自MsiProcessMessage的返回值。有了這兩個更改,編譯器和代碼運行得更好。

UINT ReportMSIMessage(MSIHANDLE hInstall, INSTALLMESSAGE eMessageType, PMSIHANDLE& hRec, int index, int *iResponse) 
{ 
    int response = MsiProcessMessage(hInstall, eMessageType, hRec); 
    if (iResponse != NULL) 
     *iResponse = response; 
    if (response == -1) 
     return ERROR_BAD_ARGUMENTS; 
    return ERROR_SUCCESS; 
} 
template <typename... Args> UINT ReportMSIMessage(MSIHANDLE hInstall, INSTALLMESSAGE eMessageType, PMSIHANDLE& hRec, int index, int *iResponse, const TCHAR *message, Args... rest) 
{ 
    LRESULT lResult = MsiRecordSetString(hRec, index, message); 
    if (ERROR_SUCCESS != lResult) 
     return lResult; 
    return ReportMSIMessage(hInstall, eMessageType, hRec, index + 1, iResponse, rest...); 
} 
template <typename... Args> UINT ReportMSIMessage(MSIHANDLE hInstall, INSTALLMESSAGE eMessageType, PMSIHANDLE& hRec, int index, int *iResponse, int value, Args... rest) 
{ 
    LRESULT lResult = MsiRecordSetInteger(hRec, index, value); 
    if (ERROR_SUCCESS != lResult) 
     return lResult; 
    return ReportMSIMessage(hInstall, eMessageType, hRec, index + 1, iResponse, rest...); 
} 
template <typename... Args> UINT ReportMSIMessage(MSIHANDLE hInstall, INSTALLMESSAGE eMessageType, int *iResponse, Args... rest) 
{ 
    const int argCount = sizeof...(Args); 
    if (eMessageType == INSTALLMESSAGE_INFO) 
    { 
     PMSIHANDLE hLogRec = MsiCreateRecord(argCount-1); 
     return ReportMSIMessage(hInstall, eMessageType, hLogRec, 0, iResponse, rest...); 
    } 
    else 
    { 
     PMSIHANDLE hLogRec = MsiCreateRecord(argCount); 
     return ReportMSIMessage(hInstall, eMessageType, hLogRec, 1, iResponse, rest...); 
    } 
} 

一個變化,有助於縮小問題正在發生變化,從ReportMSIMessage函數名到ReportMSIMessageRec,其中的參數之一是PMSIHANDLE。這阻止了編譯器可能選擇足夠長的遞歸選項來告訴我爲什麼其他模板不能作爲選項工作。