From 95d029b5b7fac931149f1fafdd2b12ad09fe3146 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 22 Jun 2020 17:16:40 +1000 Subject: Update to latest dutil. --- src/wcautil/inc/wcautil.h | 21 +++++++++++++++++---- src/wcautil/packages.config | 2 +- src/wcautil/wcalog.cpp | 24 +++++++++++++++++++++--- src/wcautil/wcautil.cpp | 27 +++++++++++++++++++++++++++ src/wcautil/wcautil.vcxproj | 4 ++-- 5 files changed, 68 insertions(+), 10 deletions(-) diff --git a/src/wcautil/inc/wcautil.h b/src/wcautil/inc/wcautil.h index 8139a7ca..982173f4 100644 --- a/src/wcautil/inc/wcautil.h +++ b/src/wcautil/inc/wcautil.h @@ -6,14 +6,22 @@ extern "C" { #endif +#include "dutilsources.h" + #define WIXAPI __stdcall -#define ExitTrace WcaLogError +#ifndef DUTIL_SOURCE_DEFAULT +#define DUTIL_SOURCE_DEFAULT DUTIL_SOURCE_EXTERNAL +#endif #include "dutil.h" -#define MessageExitOnLastError(x, e, s, ...) { x = ::GetLastError(); x = HRESULT_FROM_WIN32(x); if (FAILED(x)) { ExitTrace(x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, MB_OK, -1, __VA_ARGS__); goto LExit; } } -#define MessageExitOnFailure(x, e, s, ...) if (FAILED(x)) { ExitTrace(x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, INSTALLMESSAGE_ERROR | MB_OK, -1, __VA_ARGS__); goto LExit; } -#define MessageExitOnNullWithLastError(p, x, e, s, ...) if (NULL == p) { x = ::GetLastError(); x = HRESULT_FROM_WIN32(x); if (!FAILED(x)) { x = E_FAIL; } ExitTrace(x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, MB_OK, -1, __VA_ARGS__); goto LExit; } +#define MessageExitOnLastErrorSource(d, x, e, s, ...) { x = ::GetLastError(); x = HRESULT_FROM_WIN32(x); if (FAILED(x)) { ExitTraceSource(d, x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, MB_OK, -1, __VA_ARGS__); goto LExit; } } +#define MessageExitOnFailureSource(d, x, e, s, ...) if (FAILED(x)) { ExitTraceSource(d, x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, INSTALLMESSAGE_ERROR | MB_OK, -1, __VA_ARGS__); goto LExit; } +#define MessageExitOnNullWithLastErrorSource(d, p, x, e, s, ...) if (NULL == p) { x = ::GetLastError(); x = HRESULT_FROM_WIN32(x); if (!FAILED(x)) { x = E_FAIL; } ExitTraceSource(d, x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, MB_OK, -1, __VA_ARGS__); goto LExit; } + +#define MessageExitOnLastError(x, e, s, ...) MessageExitOnLastErrorSource(DUTIL_SOURCE_DEFAULT, x, e, s, __VA_ARGS__) +#define MessageExitOnFailure(x, e, s, ...) MessageExitOnFailureSource(DUTIL_SOURCE_DEFAULT, x, e, s, __VA_ARGS__) +#define MessageExitOnNullWithLastError(p, x, e, s, ...) MessageExitOnNullWithLastErrorSource(DUTIL_SOURCE_DEFAULT, p, x, e, s, __VA_ARGS__) // Generic action enum. typedef enum WCA_ACTION @@ -101,6 +109,11 @@ void __cdecl WcaLogError( __in LPCSTR szMessage, ... ); +void WIXAPI WcaLogErrorArgs( + __in HRESULT hr, + __in LPCSTR szMessage, + __in va_list args + ); UINT WIXAPI WcaProcessMessage( __in INSTALLMESSAGE eMessageType, diff --git a/src/wcautil/packages.config b/src/wcautil/packages.config index adda87b9..924b5e93 100644 --- a/src/wcautil/packages.config +++ b/src/wcautil/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/src/wcautil/wcalog.cpp b/src/wcautil/wcalog.cpp index fa969bff..faa7f8fd 100644 --- a/src/wcautil/wcalog.cpp +++ b/src/wcautil/wcalog.cpp @@ -228,7 +228,7 @@ extern "C" BOOL WIXAPI WcaDisplayAssert( /******************************************************************** - WcaLogError() - called before ExitOnXXX() macro exists the function + WcaLogError() - called before ExitOnXXX() macro exits the function NOTE: writes the hresult and error string to the MSI log ********************************************************************/ @@ -238,14 +238,32 @@ extern "C" void WcaLogError( ... ) { - char szBuffer[LOG_BUFFER]; va_list dots; va_start(dots, szMessage); - StringCchVPrintfA(szBuffer, countof(szBuffer), szMessage, dots); + WcaLogErrorArgs(hr, szMessage, dots); va_end(dots); +} + + +/******************************************************************** + WcaLogErrorArgs() - called before ExitOnXXX() macro exits the function + + NOTE: writes the hresult and error string to the MSI log +********************************************************************/ +extern "C" void WcaLogErrorArgs( + __in HRESULT hr, + __in LPCSTR szMessage, + __in va_list args + ) +{ + char szBuffer[LOG_BUFFER]; + + StringCchVPrintfA(szBuffer, countof(szBuffer), szMessage, args); // log the message if using Wca common layer if (WcaIsInitialized()) + { WcaLog(LOGMSG_STANDARD, "Error 0x%x: %s", hr, szBuffer); + } } diff --git a/src/wcautil/wcautil.cpp b/src/wcautil/wcautil.cpp index ce5ef151..11867d10 100644 --- a/src/wcautil/wcautil.cpp +++ b/src/wcautil/wcautil.cpp @@ -12,6 +12,15 @@ static MSIHANDLE s_hDatabase; static char s_szCustomActionLogName[32]; static UINT s_iRetVal; +static void CALLBACK WcaTraceError( + __in_z LPCSTR szFile, + __in int iLine, + __in REPORT_LEVEL rl, + __in UINT source, + __in HRESULT hrError, + __in_z __format_string LPCSTR szFormat, + __in va_list args + ); /******************************************************************** WcaGlobalInitialize() - initializes the Wca library, should be @@ -24,6 +33,7 @@ extern "C" void WIXAPI WcaGlobalInitialize( ) { g_hInstCADLL = hInst; + DutilInitialize(&WcaTraceError); MemInitialize(); AssertSetModule(g_hInstCADLL); @@ -49,6 +59,7 @@ extern "C" void WIXAPI WcaGlobalFinalize() } #endif MemUninitialize(); + DutilUninitialize(); g_hInstCADLL = NULL; } @@ -214,3 +225,19 @@ extern "C" BOOL WIXAPI WcaCancelDetected() { return ERROR_INSTALL_USEREXIT == s_iRetVal; } + +static void CALLBACK WcaTraceError( + __in_z LPCSTR /*szFile*/, + __in int /*iLine*/, + __in REPORT_LEVEL /*rl*/, + __in UINT source, + __in HRESULT hrError, + __in_z __format_string LPCSTR szFormat, + __in va_list args + ) +{ + if (DUTIL_SOURCE_DEFAULT == source) + { + WcaLogErrorArgs(hrError, szFormat, args); + } +} diff --git a/src/wcautil/wcautil.vcxproj b/src/wcautil/wcautil.vcxproj index 9d1dd28a..2c4f9062 100644 --- a/src/wcautil/wcautil.vcxproj +++ b/src/wcautil/wcautil.vcxproj @@ -1,7 +1,7 @@ - + Debug @@ -97,6 +97,6 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file -- cgit v1.2.3-55-g6feb