diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-03-22 10:05:39 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-03-22 09:01:58 +0100 |
commit | 561cb62a5ac81053e89ec9bf1eed739801570c2d (patch) | |
tree | 15dd209a037283ff066dad01119f6c03bef563b8 /include/systools | |
parent | 6c16dc217ef5cbe25166df7a3728ade12a148880 (diff) |
Simplify CoCreateInstance / CoGetClassObject with COMReference
Change-Id: Ieb1035410c3c6c4b40ea779e829a940460d19b5a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131922
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include/systools')
-rw-r--r-- | include/systools/win32/comtools.hxx | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/include/systools/win32/comtools.hxx b/include/systools/win32/comtools.hxx index ebaed567fcf3..b141842882aa 100644 --- a/include/systools/win32/comtools.hxx +++ b/include/systools/win32/comtools.hxx @@ -127,6 +127,13 @@ namespace sal::systools { } + // Using CoCreateInstance + COMReference(REFCLSID clsid, IUnknown* pOuter = nullptr, DWORD nCtx = CLSCTX_ALL) + : com_ptr_(nullptr) + { + ThrowIfFailed(CoCreateInstance(clsid, pOuter, nCtx), "CoCreateInstance failed"); + } + COMReference<T>& operator=(const COMReference<T>& other) { return operator=(other.com_ptr_); @@ -170,8 +177,8 @@ namespace sal::systools return operator=(p.template QueryInterface<T>(t)); } - HRESULT TryCoCreateInstance(REFCLSID clsid, IUnknown* pOuter = nullptr, - DWORD nCtx = CLSCTX_ALL) + HRESULT CoCreateInstance(REFCLSID clsid, IUnknown* pOuter = nullptr, + DWORD nCtx = CLSCTX_ALL) { T* ip; HRESULT hr = ::CoCreateInstance(clsid, pOuter, nCtx, IID_PPV_ARGS(&ip)); @@ -180,14 +187,7 @@ namespace sal::systools return hr; } - COMReference<T>& CoCreateInstance(REFCLSID clsid, IUnknown* pOuter = nullptr, - DWORD nCtx = CLSCTX_ALL) - { - ThrowIfFailed(TryCoCreateInstance(clsid, pOuter, nCtx), "CoCreateInstance failed"); - return *this; - } - - HRESULT TryCoGetClassObject(REFCLSID clsid, DWORD nCtx = CLSCTX_ALL) + HRESULT CoGetClassObject(REFCLSID clsid, DWORD nCtx = CLSCTX_ALL) { T* ip; HRESULT hr = ::CoGetClassObject(clsid, nCtx, nullptr, IID_PPV_ARGS(&ip)); @@ -196,12 +196,6 @@ namespace sal::systools return hr; } - COMReference<T>& CoGetClassObject(REFCLSID clsid, DWORD nCtx = CLSCTX_ALL) - { - ThrowIfFailed(TryCoGetClassObject(clsid, nCtx), "CoGetClassObject failed"); - return *this; - } - T* operator->() const { return com_ptr_; } T& operator*() const { return *com_ptr_; } |