From 6d95ce16493fbf819749dbd7ad9e8ffa61859cdb Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Fri, 6 Jun 2014 13:53:58 +0300 Subject: [PATCH] winrt: Add convenience macros for returning from HRESULT calls Almost every native call in WinRT uses COM HRESULTS. Provide some convenience macros for returning after failure. Task-number: QTBUG-39407 Change-Id: Ia99b0acd771d53c52732f270e46dd6937538e131 Reviewed-by: Oliver Wolff --- src/corelib/kernel/qfunctions_winrt.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qfunctions_winrt.h b/src/corelib/kernel/qfunctions_winrt.h index fa2b2e12ff..12488b6deb 100644 --- a/src/corelib/kernel/qfunctions_winrt.h +++ b/src/corelib/kernel/qfunctions_winrt.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -118,5 +118,20 @@ generate_inline_return_func2(_putenv_s, errno_t, const char *, const char *) generate_inline_return_func0(tzset, void) generate_inline_return_func0(_tzset, void) +// Convenience macros for handling HRESULT values +#define RETURN_IF_FAILED(msg, ret) \ + if (FAILED(hr)) { \ + qErrnoWarning(hr, msg); \ + ret; \ + } + +#define RETURN_HR_IF_FAILED(msg) RETURN_IF_FAILED(msg, return hr) +#define RETURN_OK_IF_FAILED(msg) RETURN_IF_FAILED(msg, return S_OK) +#define RETURN_FALSE_IF_FAILED(msg) RETURN_IF_FAILED(msg, return false) +#define RETURN_VOID_IF_FAILED(msg) RETURN_IF_FAILED(msg, return) + +#define Q_ASSERT_SUCCEEDED(hr) \ + Q_ASSERT_X(SUCCEEDED(hr), Q_FUNC_INFO, qPrintable(qt_error_string(hr))); + #endif // Q_OS_WINRT #endif // QFUNCTIONS_WINRT_H