summaryrefslogtreecommitdiff
path: root/zen/com_error.h
diff options
context:
space:
mode:
Diffstat (limited to 'zen/com_error.h')
-rw-r--r--zen/com_error.h31
1 files changed, 19 insertions, 12 deletions
diff --git a/zen/com_error.h b/zen/com_error.h
index e6f5b492..0e0448a7 100644
--- a/zen/com_error.h
+++ b/zen/com_error.h
@@ -26,10 +26,11 @@ private:
std::wstring msg_;
};
-#define ZEN_CHECK_COM(func) ZEN_CHECK_COM_ERROR(func, #func) //throw ComError
-/*Convenience Macro checking for COM errors:
+//Convenience Macros checking for COM errors:
-Example: ZEN_CHECK_COM(backupComp->InitializeForBackup());
+#define ZEN_COM_CHECK(func) ZEN_COM_CHECK_IMPL(func, #func) //throw ComError
+/*
+Example: ZEN_COM_CHECK(backupComp->InitializeForBackup());
Equivalent to:
{
@@ -39,6 +40,15 @@ Equivalent to:
}
*/
+#define ZEN_COM_ASSERT(obj) ZEN_COM_ASSERT_IMPL(obj, #obj) //throw ComError
+/*
+Example: ZEN_COM_ASSERT(obj);
+
+Equivalent to:
+ if (!obj)
+ throw ComError(L"Assertion failed: \"obj\".", E_FAIL);
+*/
+
@@ -218,16 +228,13 @@ std::wstring generateErrorMsg(const std::wstring& input, HRESULT hr)
}
-#define ZEN_CHECK_COM_ERROR(func, txt) \
- { \
- HRESULT hrInternal = func; \
- if (FAILED(hrInternal)) \
- throw ComError(L"Error calling \"" ## ZEN_CONCAT_SUB(L, txt) ## L"\".", hrInternal); \
+#define ZEN_COM_CHECK_IMPL(func, txt) \
+ { \
+ HRESULT hrInternal = func; \
+ if (FAILED(hrInternal)) \
+ throw zen::ComError(std::wstring(L"Error calling \"") + L ## txt + L"\".", hrInternal); \
}
-#ifndef ZEN_CONCAT //redeclare those macros: avoid dependency to scope_guard.h
-#define ZEN_CONCAT_SUB(X, Y) X ## Y
-#define ZEN_CONCAT(X, Y) ZEN_CONCAT_SUB(X, Y)
-#endif
+#define ZEN_COM_ASSERT_IMPL(obj, txt) if (!(obj)) throw zen::ComError(std::wstring(L"Assertion failed: \"") + L ## txt + L"\".", E_FAIL);
}
#endif //COM_ERROR_HEADER
bgstack15