summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-01-13 08:41:41 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-01-13 08:06:04 +0100
commit809d1e206fa9ac87ee9e04006285edfc3907667c (patch)
tree48b0bc48b69a4e619f912882f1f7260173dd5ffc
parent38eaa0c825ec461a296f4ea5f7bdc90f3a6408e9 (diff)
Simplify COMReference a bit
Use ThrowIfFailed and small refactor Change-Id: I0bcd57c26cd169380364cdaaaa76e764b9662d07 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128362 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--include/systools/win32/comtools.hxx35
1 files changed, 13 insertions, 22 deletions
diff --git a/include/systools/win32/comtools.hxx b/include/systools/win32/comtools.hxx
index 8829beb860e8..0e614e0e7ea3 100644
--- a/include/systools/win32/comtools.hxx
+++ b/include/systools/win32/comtools.hxx
@@ -84,7 +84,7 @@ namespace sal::systools
~CoInitializeGuard()
{
if (mbUninit)
- CoUninitialize();
+ ::CoUninitialize();
}
private:
@@ -153,16 +153,15 @@ namespace sal::systools
template <typename T2, typename TAG, std::enable_if_t<is_COM_query_tag<TAG>, int> = 0>
COMReference<T2> QueryInterface(TAG) const
{
- void* ip = nullptr;
+ T2* ip = nullptr;
HRESULT hr = E_POINTER;
if (com_ptr_)
- hr = com_ptr_->QueryInterface(__uuidof(T2), &ip);
+ hr = com_ptr_->QueryInterface(&ip);
if constexpr (std::is_same_v<TAG, COM_QUERY_THROW_TAG>)
- if (FAILED(hr))
- throw ComError("QueryInterface failed: Interface not supported!", hr);
+ ThrowIfFailed(hr, "QueryInterface failed");
- return { static_cast<T2*>(ip), false };
+ return { ip, false };
}
template <typename T2, typename TAG>
@@ -174,40 +173,32 @@ namespace sal::systools
HRESULT TryCoCreateInstance(REFCLSID clsid, IUnknown* pOuter = nullptr,
DWORD nCtx = CLSCTX_ALL)
{
- T* ip;
- HRESULT hr = ::CoCreateInstance(clsid, pOuter, nCtx, __uuidof(T),
- reinterpret_cast<void**>(&ip));
+ void* ip;
+ HRESULT hr = ::CoCreateInstance(clsid, pOuter, nCtx, __uuidof(T), &ip);
if (SUCCEEDED(hr))
- release(std::exchange(com_ptr_, ip));
+ release(std::exchange(com_ptr_, static_cast<T*>(ip)));
return hr;
}
COMReference<T>& CoCreateInstance(REFCLSID clsid, IUnknown* pOuter = nullptr,
DWORD nCtx = CLSCTX_ALL)
{
- HRESULT hr = TryCoCreateInstance(clsid, pOuter, nCtx);
- if (FAILED(hr))
- throw ComError("CoCreateInstance failed!", hr);
-
+ ThrowIfFailed(TryCoCreateInstance(clsid, pOuter, nCtx), "CoCreateInstance failed");
return *this;
}
HRESULT TryCoGetClassObject(REFCLSID clsid, DWORD nCtx = CLSCTX_ALL)
{
- T* i;
- HRESULT hr = ::CoGetClassObject(clsid, nCtx, nullptr, __uuidof(T),
- reinterpret_cast<void**>(&i));
+ void* ip;
+ HRESULT hr = ::CoGetClassObject(clsid, nCtx, nullptr, __uuidof(T), &ip);
if (SUCCEEDED(hr))
- release(std::exchange(com_ptr_, i));
+ release(std::exchange(com_ptr_, static_cast<T*>(ip)));
return hr;
}
COMReference<T>& CoGetClassObject(REFCLSID clsid, DWORD nCtx = CLSCTX_ALL)
{
- HRESULT hr = TryCoGetClassObject(clsid, nCtx);
- if (FAILED(hr))
- throw ComError("CoGetClassObject failed!", hr);
-
+ ThrowIfFailed(TryCoGetClassObject(clsid, nCtx), "CoGetClassObject failed");
return *this;
}