diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-12-20 18:58:32 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-12-21 09:22:44 +0100 |
commit | cb2d87c97b8e67e78a3cb42267df88aa5fb39569 (patch) | |
tree | a6a3618e5c82181f33f7174d7c75572d3b734c9d /include/systools | |
parent | e5594e656d7d7958015cfe0bdbcd42ecd5a9c9c3 (diff) |
Use sal::systools::COMReference in connectivity/ado
Change-Id: Ic3c59f70cf0e1ed0020bf4f11d7dee14c69f2119
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127189
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include/systools')
-rw-r--r-- | include/systools/win32/comtools.hxx | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/systools/win32/comtools.hxx b/include/systools/win32/comtools.hxx index 3139cc94b305..2e19f1f9e677 100644 --- a/include/systools/win32/comtools.hxx +++ b/include/systools/win32/comtools.hxx @@ -146,6 +146,25 @@ namespace sal::systools return *this; } + HRESULT TryCoGetClassObject(REFCLSID clsid, DWORD nCtx = CLSCTX_ALL) + { + T* i; + HRESULT hr = ::CoGetClassObject(clsid, nCtx, nullptr, __uuidof(T), + reinterpret_cast<void**>(&i)); + if (SUCCEEDED(hr)) + release(std::exchange(com_ptr_, i)); + return hr; + } + + COMReference<T>& CoGetClassObject(REFCLSID clsid, DWORD nCtx = CLSCTX_ALL) + { + HRESULT hr = TryCoGetClassObject(clsid, nCtx); + if (FAILED(hr)) + throw ComError("CoGetClassObject failed!", hr); + + return *this; + } + T* operator->() const { return com_ptr_; } T& operator*() const { return *com_ptr_; } |