dbaccess/source/ui/dlg/adodatalinks.cxx                |   47 ++--
 embeddedobj/source/msole/olecomponent.cxx              |   17 -
 embedserv/source/inprocserv/inprocembobj.cxx           |  161 ++++++++---------
 extensions/source/config/WinUserInfo/WinUserInfoBe.cxx |    7 
 fpicker/source/win32/VistaFilePickerImpl.cxx           |    4 
 include/systools/win32/comtools.hxx                    |   27 --
 sal/qa/systools/test_comtools.cxx                      |    4 
 sfx2/source/appl/shutdowniconw32.cxx                   |    2 
 sfx2/source/doc/docmacromode.cxx                       |    2 
 shell/source/win32/SysShExec.cxx                       |    2 
 shell/source/win32/jumplist/JumpList.cxx               |   15 -
 sw/qa/extras/odfimport/odfimport.cxx                   |    5 
 vcl/skia/win/gdiimpl.cxx                               |    4 
 vcl/win/app/fileregistration.cxx                       |    4 
 vcl/win/dtrans/FmtFilter.cxx                           |   23 --
 vcl/win/gdi/salfont.cxx                                |    4 
 16 files changed, 149 insertions(+), 179 deletions(-)

New commits:
commit 3a54d9870fa9f59c580c509a2f04dcf04db0116e
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sat Jan 24 15:26:31 2026 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sat Jan 24 13:36:50 2026 +0100

    Simplify use of COMReference a bit
    
    1. Avoid explicitly specifying COM_QUERY in calls to QueryInterface
       (it is implied from the name).
    2. Drop redundant ctor and set() that duplicate QueryInterface.
    3. Allow ThrowIfFailed without a message.
    
    Change-Id: I75b545e534efb7e57da131dfd40a2a49d204efac
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198033
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins

diff --git a/dbaccess/source/ui/dlg/adodatalinks.cxx 
b/dbaccess/source/ui/dlg/adodatalinks.cxx
index 82af63688cc1..84b1fbffe4f0 100644
--- a/dbaccess/source/ui/dlg/adodatalinks.cxx
+++ b/dbaccess/source/ui/dlg/adodatalinks.cxx
@@ -45,22 +45,21 @@ OUString PromptNew(sal_IntPtr hWnd)
         sal::systools::CoInitializeGuard aGuard(COINIT_APARTMENTTHREADED);
 
         // Instantiate DataLinks object.
-        sal::systools::COMReference<IDataSourceLocator> dlPrompt;
-        dlPrompt.CoCreateInstance(CLSID_DataLinks,       //clsid -- Data Links 
UI
-                                  nullptr,               //pUnkOuter
-                                  CLSCTX_INPROC_SERVER); //dwClsContext
+        sal::systools::COMReference<IDataSourceLocator> dlPrompt(
+            CLSID_DataLinks,       //clsid -- Data Links UI
+            nullptr,               //pUnkOuter
+            CLSCTX_INPROC_SERVER); //dwClsContext
 
-        sal::systools::ThrowIfFailed(dlPrompt->put_hWnd(hWnd), "put_hWnd 
failed");
+        sal::systools::ThrowIfFailed(dlPrompt->put_hWnd(hWnd));
 
         // Prompt for connection information.
         sal::systools::COMReference<IDispatch> piDispatch;
-        sal::systools::ThrowIfFailed(dlPrompt->PromptNew(&piDispatch), 
"PromptNew failed");
-        sal::systools::COMReference<ADOConnection> piTmpConnection(piDispatch,
-                                                                   
sal::systools::COM_QUERY_THROW);
+        sal::systools::ThrowIfFailed(dlPrompt->PromptNew(&piDispatch));
+        auto piTmpConnection(
+            
piDispatch.QueryInterface<ADOConnection>(sal::systools::COM_QUERY_THROW()));
 
         sal::systools::BStr _result;
-        
sal::systools::ThrowIfFailed(piTmpConnection->get_ConnectionString(&_result),
-                                     "get_ConnectionString failed");
+        
sal::systools::ThrowIfFailed(piTmpConnection->get_ConnectionString(&_result));
 
         return OUString(_result);
     }
@@ -77,28 +76,26 @@ OUString PromptEdit(sal_IntPtr hWnd, OUString const & 
connstr)
         // Initialize COM
         sal::systools::CoInitializeGuard aGuard(COINIT_APARTMENTTHREADED);
 
-        sal::systools::COMReference<ADOConnection> piTmpConnection;
-        piTmpConnection.CoCreateInstance(CLSID_CADOConnection, nullptr, 
CLSCTX_INPROC_SERVER);
+        sal::systools::COMReference<ADOConnection> 
piTmpConnection(CLSID_CADOConnection, nullptr,
+                                                                   
CLSCTX_INPROC_SERVER);
 
         sal::systools::ThrowIfFailed(
-            
piTmpConnection->put_ConnectionString(sal::systools::BStr(connstr)),
-            "put_ConnectionString failed");
+            
piTmpConnection->put_ConnectionString(sal::systools::BStr(connstr)));
 
         // Instantiate DataLinks object.
-        sal::systools::COMReference<IDataSourceLocator> dlPrompt;
-        dlPrompt.CoCreateInstance(CLSID_DataLinks,       //clsid -- Data Links 
UI
-                                  nullptr,               //pUnkOuter
-                                  CLSCTX_INPROC_SERVER); //dwClsContext
+        sal::systools::COMReference<IDataSourceLocator> dlPrompt(
+            CLSID_DataLinks,       //clsid -- Data Links UI
+            nullptr,               //pUnkOuter
+            CLSCTX_INPROC_SERVER); //dwClsContext
 
-        sal::systools::ThrowIfFailed(dlPrompt->put_hWnd(hWnd), "put_hWnd 
failed");
+        sal::systools::ThrowIfFailed(dlPrompt->put_hWnd(hWnd));
 
         try
         {
             // Prompt for connection information.
             IDispatch* piDispatch = piTmpConnection.get();
             VARIANT_BOOL pbSuccess;
-            sal::systools::ThrowIfFailed(dlPrompt->PromptEdit(&piDispatch, 
&pbSuccess),
-                                         "PromptEdit failed");
+            sal::systools::ThrowIfFailed(dlPrompt->PromptEdit(&piDispatch, 
&pbSuccess));
             if (!pbSuccess) //if user press cancel then sal_False == pbSuccess
                 return connstr;
         }
@@ -106,13 +103,13 @@ OUString PromptEdit(sal_IntPtr hWnd, OUString const & 
connstr)
         {
             // Prompt for new connection information.
             sal::systools::COMReference<IDispatch> piDispatch;
-            sal::systools::ThrowIfFailed(dlPrompt->PromptNew(&piDispatch), 
"PromptNew failed");
-            piTmpConnection.set(piDispatch, sal::systools::COM_QUERY_THROW);
+            sal::systools::ThrowIfFailed(dlPrompt->PromptNew(&piDispatch));
+            piTmpConnection
+                = 
piDispatch.QueryInterface<ADOConnection>(sal::systools::COM_QUERY_THROW());
         }
 
         sal::systools::BStr _result;
-        
sal::systools::ThrowIfFailed(piTmpConnection->get_ConnectionString(&_result),
-                                     "get_ConnectionString failed");
+        
sal::systools::ThrowIfFailed(piTmpConnection->get_ConnectionString(&_result));
 
         return OUString(_result);
     }
diff --git a/embeddedobj/source/msole/olecomponent.cxx 
b/embeddedobj/source/msole/olecomponent.cxx
index c5a94ac65cfc..3870632dd01a 100644
--- a/embeddedobj/source/msole/olecomponent.cxx
+++ b/embeddedobj/source/msole/olecomponent.cxx
@@ -128,7 +128,7 @@ public:
     auto getStorage() const { return getInterface<IStorage>(m_nStorage); }
     auto getObj() const { return m_nOleObject ? 
getInterface<IUnknown>(m_nOleObject) : m_pObj; }
     template <typename T>
-    auto get() const { return 
getObj().QueryInterface<T>(sal::systools::COM_QUERY); }
+    auto get() const { return getObj().QueryInterface<T>(); }
 
     void registerStorage(IStorage* pStorage) { registerInterface(pStorage, 
m_nStorage); }
     void registerObj() { registerInterface(m_pObj.get(), m_nOleObject); }
@@ -617,16 +617,16 @@ void OleComponent::InitializeObject_Impl()
     // the linked object will be detected here
     OSL_ENSURE( m_pUnoOleObject, "Unexpected object absence!" );
     if ( m_pUnoOleObject )
-        m_pUnoOleObject->SetObjectIsLink_Impl( 
m_pNativeImpl->m_pObj.QueryInterface<IOleLink>(sal::systools::COM_QUERY).is() );
+        m_pUnoOleObject->SetObjectIsLink_Impl( 
m_pNativeImpl->m_pObj.QueryInterface<IOleLink>().is() );
 
-    auto 
pViewObject2(m_pNativeImpl->m_pObj.QueryInterface<IViewObject2>(sal::systools::COM_QUERY));
+    auto pViewObject2(m_pNativeImpl->m_pObj.QueryInterface<IViewObject2>());
     if (!pViewObject2)
         throw uno::RuntimeException(
              u"Failed to query IViewObject2 interface from native 
implementation object."_ustr
         ); // TODO
 
     // remove all the caches
-    if ( sal::systools::COMReference< IOleCache > pIOleCache{ 
m_pNativeImpl->m_pObj, sal::systools::COM_QUERY } )
+    if (auto pIOleCache = m_pNativeImpl->m_pObj.QueryInterface<IOleCache>())
     {
         IEnumSTATDATA* pEnumSD = nullptr;
         HRESULT hr2 = pIOleCache->EnumCache( &pEnumSD );
@@ -646,7 +646,7 @@ void OleComponent::InitializeObject_Impl()
         hr2 = pIOleCache->Cache( &aFormat, ADVFCACHE_ONSAVE, &nConn );
     }
 
-    auto 
pOleObject(m_pNativeImpl->m_pObj.QueryInterface<IOleObject>(sal::systools::COM_QUERY));
+    auto pOleObject(m_pNativeImpl->m_pObj.QueryInterface<IOleObject>());
     if (!pOleObject)
         throw uno::RuntimeException(
              u"Failed to query IOleObject interface from native implementation 
object."_ustr
@@ -886,7 +886,7 @@ void OleComponent::InitEmbeddedCopyOfLink( 
rtl::Reference<OleComponent> const &
 
     SolarMutexReleaser releaser;
 
-    auto 
pDataObject(pOleLinkComponentObj.QueryInterface<IDataObject>(sal::systools::COM_QUERY));
+    auto pDataObject(pOleLinkComponentObj.QueryInterface<IDataObject>());
     if ( pDataObject && SUCCEEDED( OleQueryCreateFromData( pDataObject ) ) )
     {
         if (!pStorage)
@@ -905,7 +905,7 @@ void OleComponent::InitEmbeddedCopyOfLink( 
rtl::Reference<OleComponent> const &
 
     if ( !m_pNativeImpl->m_pObj )
     {
-        auto 
pOleLink(pOleLinkComponentObj.QueryInterface<IOleLink>(sal::systools::COM_QUERY));
+        auto pOleLink(pOleLinkComponentObj.QueryInterface<IOleLink>());
         if ( !pOleLink )
             throw io::IOException(); // TODO: the object doesn't support 
IOleLink
 
@@ -981,8 +981,7 @@ void OleComponent::RunObject()
             OUString error = comphelper::WindowsErrorStringFromHRESULT(hr);
             if ( hr == REGDB_E_CLASSNOTREG )
             {
-                if (auto pOleObj
-                    = 
m_pNativeImpl->m_pObj.QueryInterface<IOleObject>(sal::systools::COM_QUERY))
+                if (auto pOleObj = 
m_pNativeImpl->m_pObj.QueryInterface<IOleObject>())
                 {
                     LPOLESTR lpUserType = nullptr;
                     if (SUCCEEDED(pOleObj->GetUserType(USERCLASSTYPE_FULL, 
&lpUserType)))
diff --git a/embedserv/source/inprocserv/inprocembobj.cxx 
b/embedserv/source/inprocserv/inprocembobj.cxx
index b7bf89b6670a..89fe741be683 100644
--- a/embedserv/source/inprocserv/inprocembobj.cxx
+++ b/embedserv/source/inprocserv/inprocembobj.cxx
@@ -103,8 +103,7 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
             {
                 // deregister all the listeners
 
-                sal::systools::COMReference< IOleObject > 
pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
-                if ( pOleObject )
+                if (auto pOleObject = 
m_pDefHandler.QueryInterface<IOleObject>())
                 {
                     for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
                         if ( m_pOleAdvises[nInd] )
@@ -117,8 +116,7 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
                     pOleObject->SetClientSite( nullptr );
                 }
 
-                sal::systools::COMReference< IDataObject > 
pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
-                if ( pIDataObject )
+                if (auto pIDataObject = 
m_pDefHandler.QueryInterface<IDataObject>())
                 {
                     for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
                         if ( m_pDataAdvises[nInd] )
@@ -129,15 +127,13 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
                         }
                 }
 
-                sal::systools::COMReference< IViewObject > 
pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
-                if ( pIViewObject )
+                if (auto pIViewObject = 
m_pDefHandler.QueryInterface<IViewObject>())
                 {
                     if ( m_pViewAdvise )
                         pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), 
m_pViewAdvise->GetViewAdviseFlag(), nullptr );
                 }
 
-                sal::systools::COMReference< IPersistStorage > 
pPersist(m_pDefHandler, sal::systools::COM_QUERY);
-                if ( pPersist )
+                if (auto pPersist = 
m_pDefHandler.QueryInterface<IPersistStorage>())
                 {
                     // disconnect the old wrapper from the storage
                     pPersist->HandsOffStorage();
@@ -156,12 +152,12 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
     if ( !m_pDefHandler )
     {
         // create a new default inprocess handler
-        HRESULT hr = OleCreateDefaultHandler( m_guid, nullptr, IID_IUnknown, 
reinterpret_cast<void**>(&m_pDefHandler) );
+        HRESULT hr = OleCreateDefaultHandler(m_guid, nullptr, 
IID_PPV_ARGS(&m_pDefHandler));
         if ( SUCCEEDED( hr ) )
         {
             if ( m_nInitMode == INIT_FROM_STORAGE )
             {
-                sal::systools::COMReference< IPersistStorage > 
pPersist(m_pDefHandler, sal::systools::COM_QUERY);
+                auto pPersist(m_pDefHandler.QueryInterface<IPersistStorage>());
 
                 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance 
problem
                 if ( pPersist && m_pStorage )
@@ -169,7 +165,7 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
             }
             else if ( m_nInitMode == LOAD_FROM_STORAGE )
             {
-                sal::systools::COMReference< IPersistStorage > 
pPersist(m_pDefHandler, sal::systools::COM_QUERY);
+                auto pPersist(m_pDefHandler.QueryInterface<IPersistStorage>());
 
                 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance 
problem
                 if ( pPersist && m_pStorage )
@@ -177,7 +173,7 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
             }
             else if ( m_nInitMode == LOAD_FROM_FILE )
             {
-                sal::systools::COMReference< IPersistFile > 
pPersistFile(m_pDefHandler, sal::systools::COM_QUERY);
+                auto 
pPersistFile(m_pDefHandler.QueryInterface<IPersistFile>());
 
                 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance 
problem
                 if ( pPersistFile && m_pFileName )
@@ -193,8 +189,7 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
 
         // register all the listeners new
 
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
-        if ( pOleObject )
+        if (auto pOleObject = m_pDefHandler.QueryInterface<IOleObject>())
         {
             if ( m_pClientSite )
                 pOleObject->SetClientSite( m_pClientSite.get() );
@@ -208,8 +203,7 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
                 }
         }
 
-        sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, 
sal::systools::COM_QUERY);
-        if ( pIDataObject )
+        if (auto pIDataObject = m_pDefHandler.QueryInterface<IDataObject>())
         {
             for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
                 if ( m_pDataAdvises[nInd] )
@@ -220,8 +214,7 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
                 }
         }
 
-        sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, 
sal::systools::COM_QUERY);
-        if ( pIViewObject )
+        if (auto pIViewObject = m_pDefHandler.QueryInterface<IViewObject>())
         {
             if ( m_pViewAdvise )
                 pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), 
m_pViewAdvise->GetViewAdviseFlag(), m_pViewAdvise.get() );
@@ -396,7 +389,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::IsDirty()
 
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pPersist(m_pDefHandler.QueryInterface<IPersistStorage>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pPersist )
@@ -411,7 +404,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::InitNew( IStorage *p
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pPersist(m_pDefHandler.QueryInterface<IPersistStorage>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pPersist )
@@ -442,7 +435,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Load( IStorage *pStg
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pPersist(m_pDefHandler.QueryInterface<IPersistStorage>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pPersist )
@@ -476,7 +469,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Save( IStorage *pStg
 
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pPersist(m_pDefHandler.QueryInterface<IPersistStorage>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pPersist )
@@ -499,7 +492,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::SaveCompleted( IStor
 
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pPersist(m_pDefHandler.QueryInterface<IPersistStorage>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pPersist )
@@ -533,7 +526,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::HandsOffStorage()
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pPersist(m_pDefHandler.QueryInterface<IPersistStorage>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pPersist )
@@ -557,7 +550,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Load( LPCOLESTR pszF
 {
     if ( CheckDefHandler() && pszFileName )
     {
-        sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pPersist(m_pDefHandler.QueryInterface<IPersistFile>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pPersist )
@@ -586,7 +579,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Save( LPCOLESTR pszF
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pPersist(m_pDefHandler.QueryInterface<IPersistFile>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pPersist )
@@ -601,7 +594,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::SaveCompleted( LPCOL
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pPersist(m_pDefHandler.QueryInterface<IPersistFile>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pPersist )
@@ -629,7 +622,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetCurFile( LPOLESTR
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pPersist(m_pDefHandler.QueryInterface<IPersistFile>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pPersist )
@@ -658,7 +651,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::SetClientSite( IOleC
 
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -691,7 +684,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetClientSite( IOleC
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -707,7 +700,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::SetHostNames( LPCOLE
 
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -726,7 +719,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Close( DWORD dwSaveO
     if ( m_pDefHandler && CheckDefHandler() )
     {
         // no need to close if there is no default handler.
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -751,7 +744,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::SetMoniker( DWORD dw
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -766,7 +759,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetMoniker( DWORD dw
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -781,7 +774,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::InitFromData( IDataO
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -796,7 +789,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetClipboardData( DW
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -817,7 +810,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::DoVerb(
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -835,7 +828,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEV
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -851,7 +844,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Update()
 
     if ( m_pDefHandler && CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -866,7 +859,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::IsUpToDate()
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -890,7 +883,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetUserType( DWORD d
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -905,7 +898,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::SetExtent( DWORD dwD
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -920,7 +913,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetExtent( DWORD dwD
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -946,7 +939,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Advise( IAdviseSink
 
     if ( pAdvSink && CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -977,7 +970,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Unadvise( DWORD dwCo
     {
         if ( m_pDefHandler )
         {
-            sal::systools::COMReference< IOleObject > 
pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
+            auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
             ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
             if ( pOleObject )
@@ -1007,7 +1000,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetMiscStatus( DWORD
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -1022,7 +1015,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::SetColorScheme( LOGP
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pOleObject(m_pDefHandler.QueryInterface<IOleObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pOleObject )
@@ -1038,7 +1031,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetData( FORMATETC *
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDataObject(m_pDefHandler.QueryInterface<IDataObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDataObject )
@@ -1053,7 +1046,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetDataHere( FORMATE
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDataObject(m_pDefHandler.QueryInterface<IDataObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDataObject )
@@ -1068,7 +1061,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::QueryGetData( FORMAT
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDataObject(m_pDefHandler.QueryInterface<IDataObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDataObject )
@@ -1083,7 +1076,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetCanonicalFormatEt
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDataObject(m_pDefHandler.QueryInterface<IDataObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDataObject )
@@ -1098,7 +1091,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::SetData( FORMATETC *
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDataObject(m_pDefHandler.QueryInterface<IDataObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDataObject )
@@ -1113,7 +1106,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::EnumFormatEtc( DWORD
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDataObject(m_pDefHandler.QueryInterface<IDataObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDataObject )
@@ -1139,7 +1132,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::DAdvise( FORMATETC *
 
     if ( pAdvSink && CheckDefHandler() )
     {
-        sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDataObject(m_pDefHandler.QueryInterface<IDataObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDataObject )
@@ -1170,7 +1163,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::DUnadvise( DWORD dwC
     {
         if ( CheckDefHandler() )
         {
-            sal::systools::COMReference< IDataObject > 
pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
+            auto pIDataObject(m_pDefHandler.QueryInterface<IDataObject>());
 
             ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
             if ( pIDataObject )
@@ -1194,7 +1187,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::EnumDAdvise( IEnumST
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDataObject(m_pDefHandler.QueryInterface<IDataObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDataObject )
@@ -1210,7 +1203,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetRunningClass( LPC
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIRunObj(m_pDefHandler.QueryInterface<IRunnableObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIRunObj )
@@ -1225,7 +1218,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIRunObj(m_pDefHandler.QueryInterface<IRunnableObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIRunObj )
@@ -1239,7 +1232,7 @@ BOOL STDMETHODCALLTYPE 
InprocEmbedDocument_Impl::IsRunning()
 {
     if (CheckDefHandler())
     {
-        sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIRunObj(m_pDefHandler.QueryInterface<IRunnableObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIRunObj )
@@ -1253,7 +1246,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::LockRunning( BOOL fL
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIRunObj(m_pDefHandler.QueryInterface<IRunnableObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIRunObj )
@@ -1268,7 +1261,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::SetContainedObject(
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIRunObj(m_pDefHandler.QueryInterface<IRunnableObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIRunObj )
@@ -1285,7 +1278,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Draw( DWORD dwDrawAs
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIViewObject(m_pDefHandler.QueryInterface<IViewObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIViewObject )
@@ -1300,7 +1293,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetColorSet( DWORD d
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIViewObject(m_pDefHandler.QueryInterface<IViewObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIViewObject )
@@ -1315,7 +1308,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Freeze( DWORD dwDraw
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIViewObject(m_pDefHandler.QueryInterface<IViewObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIViewObject )
@@ -1330,7 +1323,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Unfreeze( DWORD dwFr
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIViewObject(m_pDefHandler.QueryInterface<IViewObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIViewObject )
@@ -1353,7 +1346,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::SetAdvise( DWORD asp
 
     if ( pAdvSink && CheckDefHandler() )
     {
-        sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIViewObject(m_pDefHandler.QueryInterface<IViewObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIViewObject )
@@ -1401,7 +1394,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetExtent( DWORD dwD
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IViewObject2 > 
pIViewObject2(m_pDefHandler, sal::systools::COM_QUERY);
+        auto pIViewObject2(m_pDefHandler.QueryInterface<IViewObject2>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIViewObject2 )
@@ -1418,7 +1411,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetWindow( HWND *phw
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleWindow > pIOleWindow(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIOleWindow(m_pDefHandler.QueryInterface<IOleWindow>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIOleWindow )
@@ -1433,7 +1426,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::ContextSensitiveHelp
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleWindow > pIOleWindow(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIOleWindow(m_pDefHandler.QueryInterface<IOleWindow>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIOleWindow )
@@ -1450,7 +1443,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::InPlaceDeactivate()
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleInPlaceObject > 
pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
+        auto 
pIOleInPlaceObject(m_pDefHandler.QueryInterface<IOleInPlaceObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIOleInPlaceObject )
@@ -1465,7 +1458,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::UIDeactivate()
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleInPlaceObject > 
pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
+        auto 
pIOleInPlaceObject(m_pDefHandler.QueryInterface<IOleInPlaceObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIOleInPlaceObject )
@@ -1480,7 +1473,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::SetObjectRects( LPCR
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleInPlaceObject > 
pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
+        auto 
pIOleInPlaceObject(m_pDefHandler.QueryInterface<IOleInPlaceObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIOleInPlaceObject )
@@ -1495,7 +1488,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::ReactivateAndUndo()
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleInPlaceObject > 
pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
+        auto 
pIOleInPlaceObject(m_pDefHandler.QueryInterface<IOleInPlaceObject>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIOleInPlaceObject )
@@ -1512,7 +1505,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetTypeInfoCount( UI
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDispatch(m_pDefHandler.QueryInterface<IDispatch>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDispatch )
@@ -1527,7 +1520,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetTypeInfo( UINT iT
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDispatch(m_pDefHandler.QueryInterface<IDispatch>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDispatch )
@@ -1542,7 +1535,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::GetIDsOfNames( REFII
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDispatch(m_pDefHandler.QueryInterface<IDispatch>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDispatch )
@@ -1557,7 +1550,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::Invoke( DISPID dispI
 {
     if ( CheckDefHandler() )
     {
-        sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, 
sal::systools::COM_QUERY);
+        auto pIDispatch(m_pDefHandler.QueryInterface<IDispatch>());
 
         ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
         if ( pIDispatch )
@@ -1597,7 +1590,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::InternalCacheWrapper
 {
     if ( m_rOwnDocument.CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleCache > 
pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
+        auto 
pIOleCache(m_rOwnDocument.GetDefHandler().QueryInterface<IOleCache>());
 
         ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid 
reentrance problem
         if ( pIOleCache )
@@ -1612,7 +1605,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::InternalCacheWrapper
 {
     if ( m_rOwnDocument.CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleCache > 
pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
+        auto 
pIOleCache(m_rOwnDocument.GetDefHandler().QueryInterface<IOleCache>());
 
         ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid 
reentrance problem
         if ( pIOleCache )
@@ -1627,7 +1620,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::InternalCacheWrapper
 {
     if ( m_rOwnDocument.CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleCache > 
pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
+        auto 
pIOleCache(m_rOwnDocument.GetDefHandler().QueryInterface<IOleCache>());
 
         ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid 
reentrance problem
         if ( pIOleCache )
@@ -1642,7 +1635,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::InternalCacheWrapper
 {
     if ( m_rOwnDocument.CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleCache > 
pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
+        auto 
pIOleCache(m_rOwnDocument.GetDefHandler().QueryInterface<IOleCache>());
 
         ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid 
reentrance problem
         if ( pIOleCache )
@@ -1657,7 +1650,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::InternalCacheWrapper
 {
     if ( m_rOwnDocument.CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleCache > 
pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
+        auto 
pIOleCache(m_rOwnDocument.GetDefHandler().QueryInterface<IOleCache>());
 
         ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid 
reentrance problem
         if ( pIOleCache )
@@ -1673,7 +1666,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::InternalCacheWrapper
 {
     if ( m_rOwnDocument.CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleCache2 > 
pIOleCache2(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
+        auto 
pIOleCache2(m_rOwnDocument.GetDefHandler().QueryInterface<IOleCache2>());
 
         ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid 
reentrance problem
         if ( pIOleCache2 )
@@ -1688,7 +1681,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP 
InprocEmbedDocument_Impl::InternalCacheWrapper
 {
     if ( m_rOwnDocument.CheckDefHandler() )
     {
-        sal::systools::COMReference< IOleCache2 > 
pIOleCache2(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
+        auto 
pIOleCache2(m_rOwnDocument.GetDefHandler().QueryInterface<IOleCache2>());
 
         ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid 
reentrance problem
         if ( pIOleCache2 )
diff --git a/extensions/source/config/WinUserInfo/WinUserInfoBe.cxx 
b/extensions/source/config/WinUserInfo/WinUserInfoBe.cxx
index b4a7b89f045a..9174622abef7 100644
--- a/extensions/source/config/WinUserInfo/WinUserInfoBe.cxx
+++ b/extensions/source/config/WinUserInfo/WinUserInfoBe.cxx
@@ -95,16 +95,15 @@ public:
                                                                  
CLSCTX_INPROC_SERVER);
 
             sal::systools::BStr sUserDN;
-            sal::systools::ThrowIfFailed(pADsys->get_UserName(&sUserDN), 
"get_UserName failed");
+            sal::systools::ThrowIfFailed(pADsys->get_UserName(&sUserDN));
             // If this user is an AD user, then without an active connection 
to the domain, all the
             // above will succeed, and m_sUserDN will be correctly 
initialized, but the following
             // call to ADsGetObject will fail, and we will attempt reading 
cached values.
             m_sUserDN = sUserDN;
             OUString sLdapUserDN = "LDAP://" + m_sUserDN;
             sal::systools::COMReference<IADsUser> pUser;
-            
sal::systools::ThrowIfFailed(ADsGetObject(o3tl::toW(sLdapUserDN.getStr()), 
IID_IADsUser,
-                                                      
reinterpret_cast<void**>(&pUser)),
-                                         "ADsGetObject failed");
+            sal::systools::ThrowIfFailed(
+                ADsGetObject(o3tl::toW(sLdapUserDN.getStr()), 
IID_PPV_ARGS(&pUser)));
             // Fetch all the required information right now, when we know to 
have access to AD
             // (later the connection may already be lost)
             m_aMap[_givenname] = Str(pUser, &IADsUser::get_FirstName);
diff --git a/fpicker/source/win32/VistaFilePickerImpl.cxx 
b/fpicker/source/win32/VistaFilePickerImpl.cxx
index 06df9a49aba3..61a4a3e86aba 100644
--- a/fpicker/source/win32/VistaFilePickerImpl.cxx
+++ b/fpicker/source/win32/VistaFilePickerImpl.cxx
@@ -147,7 +147,7 @@ public:
     sal::systools::COMReference<IShellItemArray> getResult(bool bInExecute) 
override
     {
         sal::systools::COMReference<IShellItemArray> iItems;
-        TFileOpenDialog iDialog(getComPtr(), sal::systools::COM_QUERY_THROW);
+        auto iDialog(getComPtr().QueryInterface<IFileOpenDialog>());
         bool bGetResult = false;
         if (!iDialog.is())
             bGetResult = true;
@@ -992,7 +992,7 @@ TFileDialog 
VistaFilePickerImpl::impl_getBaseDialogInterface()
 TFileDialogCustomize VistaFilePickerImpl::impl_getCustomizeInterface()
 {
     if (m_pDialog != nullptr)
-        return { m_pDialog->getComPtr(), sal::systools::COM_QUERY_THROW };
+        return m_pDialog->getComPtr().QueryInterface<IFileDialogCustomize>();
 
     return {};
 }
diff --git a/include/systools/win32/comtools.hxx 
b/include/systools/win32/comtools.hxx
index 27a7b9d55824..2ff0cd2bd94d 100644
--- a/include/systools/win32/comtools.hxx
+++ b/include/systools/win32/comtools.hxx
@@ -54,7 +54,7 @@ namespace sal::systools
     };
 
     /* Convert failed HRESULT to thrown ComError */
-    inline void ThrowIfFailed(HRESULT hr, std::string_view msg,
+    inline void ThrowIfFailed(HRESULT hr, std::string_view msg = {},
                               std::source_location loc = 
std::source_location::current())
     {
         if (FAILED(hr))
@@ -99,8 +99,8 @@ namespace sal::systools
         bool mbUninit;
     };
 
-    struct COM_QUERY_TAG {} constexpr COM_QUERY;
-    struct COM_QUERY_THROW_TAG : public COM_QUERY_TAG {} constexpr 
COM_QUERY_THROW;
+    enum class COM_QUERY;
+    enum class COM_QUERY_THROW;
 
     /* A simple COM smart pointer template */
     template <typename T>
@@ -125,13 +125,6 @@ namespace sal::systools
         {
         }
 
-        // Query from IUnknown*, using COM_QUERY or COM_QUERY_THROW tags
-        template <typename T2, typename TAG>
-        COMReference(const COMReference<T2>& p, TAG t)
-            : COMReference(p.template QueryInterface<T>(t))
-        {
-        }
-
         // Using CoCreateInstance
         COMReference(REFCLSID clsid, IUnknown* pOuter = nullptr, DWORD nCtx = 
CLSCTX_ALL)
             : com_ptr_(nullptr)
@@ -162,27 +155,21 @@ namespace sal::systools
 
         ~COMReference() { release(com_ptr_); }
 
-        template <typename T2, typename TAG>
-            requires std::is_base_of_v<COM_QUERY_TAG, TAG>
-        COMReference<T2> QueryInterface(TAG) const
+        template <typename T2, typename TAG = COM_QUERY>
+            requires (std::is_same_v<TAG, COM_QUERY> || std::is_same_v<TAG, 
COM_QUERY_THROW>)
+        COMReference<T2> QueryInterface(TAG = TAG()) const
         {
             T2* ip = nullptr;
             HRESULT hr = E_POINTER;
             if (com_ptr_)
                 hr = com_ptr_->QueryInterface(IID_PPV_ARGS(&ip));
 
-            if constexpr (std::is_same_v<TAG, COM_QUERY_THROW_TAG>)
+            if constexpr (std::is_same_v<TAG, COM_QUERY_THROW>)
                 ThrowIfFailed(hr, "QueryInterface failed");
 
             return { ip, false };
         }
 
-        template <typename T2, typename TAG>
-        COMReference<T>& set(const COMReference<T2>& p, TAG t)
-        {
-            return operator=(p.template QueryInterface<T>(t));
-        }
-
         HRESULT CoCreateInstance(REFCLSID clsid, IUnknown* pOuter = nullptr,
                                  DWORD nCtx = CLSCTX_ALL)
         {
diff --git a/sal/qa/systools/test_comtools.cxx 
b/sal/qa/systools/test_comtools.cxx
index 073bb79ec2d2..291670bde966 100644
--- a/sal/qa/systools/test_comtools.cxx
+++ b/sal/qa/systools/test_comtools.cxx
@@ -188,7 +188,7 @@ namespace test_comtools
             sal::systools::COMReference<IUnknown> r2;
             CPPUNIT_ASSERT_NO_THROW_MESSAGE(
                 "Exception should not have been thrown",
-                r2 = 
r1.QueryInterface<IUnknown>(sal::systools::COM_QUERY_THROW));
+                r2 = 
r1.QueryInterface<IUnknown>(sal::systools::COM_QUERY_THROW()));
             CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong reference count, 2 is 
expected", ULONG(2),
                                          
reinterpret_cast<COMObject*>(r2.get())->GetRefCount());
         }
@@ -197,7 +197,7 @@ namespace test_comtools
         {
             sal::systools::COMReference<IUnknown> r1 = comObjectSource();
             CPPUNIT_ASSERT_THROW_MESSAGE("Exception should have been thrown",
-                auto r2 = 
r1.QueryInterface<IPersistFile>(sal::systools::COM_QUERY_THROW),
+                auto r2 = 
r1.QueryInterface<IPersistFile>(sal::systools::COM_QUERY_THROW()),
                 sal::systools::ComError);
         }
 
diff --git a/sfx2/source/appl/shutdowniconw32.cxx 
b/sfx2/source/appl/shutdowniconw32.cxx
index 60a836b05dcb..c45403c2035e 100644
--- a/sfx2/source/appl/shutdowniconw32.cxx
+++ b/sfx2/source/appl/shutdowniconw32.cxx
@@ -711,7 +711,7 @@ static bool CreateShortcut( const OUString& rAbsObject, 
const OUString& rAbsObje
         if (!rParameter.isEmpty())
             psl->SetArguments( o3tl::toW(rParameter.getStr()) );
 
-        sal::systools::COMReference<IPersistFile> ppf(psl, 
sal::systools::COM_QUERY_THROW);
+        auto 
ppf(psl.QueryInterface<IPersistFile>(sal::systools::COM_QUERY_THROW()));
         return SUCCEEDED(ppf->Save(o3tl::toW(rAbsShortcut.getStr()), TRUE));
     }
     catch (const sal::systools::ComError&)
diff --git a/sfx2/source/doc/docmacromode.cxx b/sfx2/source/doc/docmacromode.cxx
index c87224301590..b9bcdfa0e1c1 100644
--- a/sfx2/source/doc/docmacromode.cxx
+++ b/sfx2/source/doc/docmacromode.cxx
@@ -284,7 +284,7 @@ namespace sfx2
         osl::FileBase::getSystemPathFromFileURL(sURL, sFilePath);
         sal::systools::COMReference<IZoneIdentifier> pZoneId;
         pZoneId.CoCreateInstance(CLSID_PersistentZoneIdentifier);
-        sal::systools::COMReference<IPersistFile> pPersist(pZoneId, 
sal::systools::COM_QUERY);
+        auto pPersist(pZoneId.QueryInterface<IPersistFile>());
         DWORD dwZone;
         if (!pPersist || 
!SUCCEEDED(pPersist->Load(o3tl::toW(sFilePath.getStr()), STGM_READ)) ||
             !SUCCEEDED(pZoneId->GetId(&dwZone)))
diff --git a/shell/source/win32/SysShExec.cxx b/shell/source/win32/SysShExec.cxx
index 5d039bf16b81..06e295a571d4 100644
--- a/shell/source/win32/SysShExec.cxx
+++ b/shell/source/win32/SysShExec.cxx
@@ -240,7 +240,7 @@ OUString checkFile(const OUString& pathname, const 
OUString& aCommand)
         try
         {
             sal::systools::COMReference<IShellLinkW> link(CLSID_ShellLink, 
nullptr, CLSCTX_INPROC_SERVER);
-            sal::systools::COMReference<IPersistFile> file(link, 
sal::systools::COM_QUERY_THROW);
+            auto 
file(link.QueryInterface<IPersistFile>(sal::systools::COM_QUERY_THROW()));
             sal::systools::ThrowIfFailed(file->Load(path, STGM_READ),
                                          "IPersistFile.Load failed");
             sal::systools::ThrowIfFailed(link->Resolve(nullptr, SLR_UPDATE | 
SLR_NO_UI),
diff --git a/shell/source/win32/jumplist/JumpList.cxx 
b/shell/source/win32/jumplist/JumpList.cxx
index d81aa1aa16e4..f428f404d998 100644
--- a/shell/source/win32/jumplist/JumpList.cxx
+++ b/shell/source/win32/jumplist/JumpList.cxx
@@ -101,11 +101,11 @@ bool lcl_isItemInArray(COMReference<IShellLinkW> 
pShellLinkItem,
             continue;
 
         PROPVARIANT propvar;
-        COMReference<IPropertyStore> pps(pShellLinkItem, COM_QUERY_THROW);
+        auto 
pps(pShellLinkItem.QueryInterface<IPropertyStore>(COM_QUERY_THROW()));
         ThrowIfFailed(pps->GetValue(PKEY_Title, &propvar), "GetValue failed.");
         OUString title(o3tl::toU(PropVariantToStringWithDefault(propvar, 
L"")));
 
-        COMReference<IPropertyStore> ppsCompare(pShellLinkItemCompare, 
COM_QUERY_THROW);
+        auto 
ppsCompare(pShellLinkItemCompare.QueryInterface<IPropertyStore>(COM_QUERY_THROW()));
         ThrowIfFailed(ppsCompare->GetValue(PKEY_Title, &propvar), "GetValue 
failed.");
         OUString 
titleCompare(o3tl::toU(PropVariantToStringWithDefault(propvar, L"")));
         PropVariantClear(&propvar);
@@ -188,7 +188,7 @@ void SAL_CALL JumpListImpl::appendCategory(const OUString& 
sCategory,
                                                          CLSCTX_INPROC_SERVER);
 
                 {
-                    COMReference<IPropertyStore> pps(pShellLinkItem, 
COM_QUERY_THROW);
+                    auto 
pps(pShellLinkItem.QueryInterface<IPropertyStore>(COM_QUERY_THROW()));
 
                     PROPVARIANT propvar;
                     ThrowIfFailed(
@@ -233,7 +233,7 @@ void SAL_CALL JumpListImpl::appendCategory(const OUString& 
sCategory,
             }
         }
 
-        COMReference<IObjectArray> pObjectArray(aCollection, COM_QUERY_THROW);
+        auto 
pObjectArray(aCollection.QueryInterface<IObjectArray>(COM_QUERY_THROW()));
         UINT nItems;
         ThrowIfFailed(pObjectArray->GetCount(&nItems), "GetCount failed.");
         if (nItems == 0)
@@ -286,7 +286,7 @@ void SAL_CALL JumpListImpl::addTasks(const 
Sequence<JumpListItem>& aJumpListItem
                                                          CLSCTX_INPROC_SERVER);
 
                 {
-                    COMReference<IPropertyStore> pps(pShellLinkItem, 
COM_QUERY_THROW);
+                    auto 
pps(pShellLinkItem.QueryInterface<IPropertyStore>(COM_QUERY_THROW()));
 
                     PROPVARIANT propvar;
                     ThrowIfFailed(
@@ -323,7 +323,7 @@ void SAL_CALL JumpListImpl::addTasks(const 
Sequence<JumpListItem>& aJumpListItem
             }
         }
 
-        COMReference<IObjectArray> pObjectArray(aCollection, COM_QUERY_THROW);
+        auto 
pObjectArray(aCollection.QueryInterface<IObjectArray>(COM_QUERY_THROW()));
         UINT nItems;
         ThrowIfFailed(pObjectArray->GetCount(&nItems), "GetCount failed.");
         if (nItems == 0)
@@ -467,7 +467,8 @@ Sequence<JumpListItem> SAL_CALL 
JumpListImpl::getRemovedItems(const OUString& sA
             {
                 if (SUCCEEDED(removed->GetAt(i, 
IID_PPV_ARGS(&pShellLinkItem))))
                 {
-                    COMReference<IPropertyStore> propertyStore(pShellLinkItem, 
COM_QUERY_THROW);
+                    auto propertyStore(
+                        
pShellLinkItem.QueryInterface<IPropertyStore>(COM_QUERY_THROW()));
                     PROPVARIANT propvar;
                     ThrowIfFailed(propertyStore->GetValue(PKEY_Title, 
&propvar),
                                   "GetValue failed.");
diff --git a/sw/qa/extras/odfimport/odfimport.cxx 
b/sw/qa/extras/odfimport/odfimport.cxx
index 05992ca09f55..b05a7ba8e142 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -1412,8 +1412,7 @@ void 
runWindowsFileZoneTests(css::uno::Reference<css::frame::XDesktop2> const &
     xChanges->commit();
 
     // Set Windows Security Zone for temp file
-    sal::systools::COMReference<IZoneIdentifier> pZoneId;
-    pZoneId.CoCreateInstance(CLSID_PersistentZoneIdentifier);
+    sal::systools::COMReference<IZoneIdentifier> 
pZoneId(CLSID_PersistentZoneIdentifier);
 
     // ignore setting of Zone 0, since at least for Windows Server
     // setups, that always leads to E_ACCESSDENIED - presumably since
@@ -1424,7 +1423,7 @@ void 
runWindowsFileZoneTests(css::uno::Reference<css::frame::XDesktop2> const &
     if( zoneId != 0 )
     {
         CPPUNIT_ASSERT(SUCCEEDED(pZoneId->SetId(zoneId)));
-        sal::systools::COMReference<IPersistFile> pPersist(pZoneId, 
sal::systools::COM_QUERY_THROW);
+        auto 
pPersist(pZoneId.QueryInterface<IPersistFile>(sal::systools::COM_QUERY_THROW()));
         OUString sTempFileWinPath;
         osl::FileBase::getSystemPathFromFileURL(sFileName, sTempFileWinPath);
         CPPUNIT_ASSERT(
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
index 3bcf5bf66926..f085f915ef7e 100644
--- a/vcl/skia/win/gdiimpl.cxx
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -55,8 +55,8 @@ getDWritePrivateFontCollection(IDWriteFontFace* fontFace)
     sal::systools::COMReference<IDWriteFontFile> fontFile;
     sal::systools::ThrowIfFailed(fontFace->GetFiles(&numberOfFiles, 
&fontFile), SAL_WHERE);
 
-    static sal::systools::COMReference<IDWriteFactory3> dwriteFactory3(
-        WinSalGraphics::getDWriteFactory(), sal::systools::COM_QUERY_THROW);
+    static auto 
dwriteFactory3(WinSalGraphics::getDWriteFactory().QueryInterface<IDWriteFactory3>(
+        sal::systools::COM_QUERY_THROW()));
 
     static sal::systools::COMReference<IDWriteFontSetBuilder> 
dwriteFontSetBuilder = [] {
         sal::systools::COMReference<IDWriteFontSetBuilder> builder;
diff --git a/vcl/win/app/fileregistration.cxx b/vcl/win/app/fileregistration.cxx
index 31a3d996ed72..19e0c08de979 100644
--- a/vcl/win/app/fileregistration.cxx
+++ b/vcl/win/app/fileregistration.cxx
@@ -140,8 +140,8 @@ void CheckFileExtRegistration(weld::Window* pDialogParent)
     sal::systools::COMReference<IApplicationAssociationRegistration> pAAR;
     try
     {
-        pAAR.CoCreateInstance(CLSID_ApplicationAssociationRegistration, 
nullptr,
-                              CLSCTX_INPROC_SERVER);
+        
sal::systools::ThrowIfFailed(pAAR.CoCreateInstance(CLSID_ApplicationAssociationRegistration,
+                                                           nullptr, 
CLSCTX_INPROC_SERVER));
     }
     catch (...)
     {
diff --git a/vcl/win/dtrans/FmtFilter.cxx b/vcl/win/dtrans/FmtFilter.cxx
index d62389235994..189344b32a34 100644
--- a/vcl/win/dtrans/FmtFilter.cxx
+++ b/vcl/win/dtrans/FmtFilter.cxx
@@ -311,25 +311,20 @@ static std::wstring getShellLinkTarget(const 
std::wstring& aLnkFile)
 
     try
     {
-        sal::systools::COMReference<IShellLinkW> pIShellLink;
-        pIShellLink.CoCreateInstance(CLSID_ShellLink, nullptr, 
CLSCTX_INPROC_SERVER);
+        sal::systools::COMReference<IShellLinkW> pIShellLink(CLSID_ShellLink, 
nullptr,
+                                                             
CLSCTX_INPROC_SERVER);
 
-        sal::systools::COMReference<IPersistFile> pIPersistFile(pIShellLink,
-                                                                
sal::systools::COM_QUERY_THROW);
+        auto pIPersistFile(
+            
pIShellLink.QueryInterface<IPersistFile>(sal::systools::COM_QUERY_THROW()));
 
-        HRESULT hr = pIPersistFile->Load(aLnkFile.c_str(), STGM_READ);
-        if (FAILED(hr))
-            return target;
-
-        hr = pIShellLink->Resolve(nullptr, SLR_UPDATE | SLR_NO_UI);
-        if (FAILED(hr))
-            return target;
+        sal::systools::ThrowIfFailed(pIPersistFile->Load(aLnkFile.c_str(), 
STGM_READ), SAL_WHERE);
+        sal::systools::ThrowIfFailed(pIShellLink->Resolve(nullptr, SLR_UPDATE 
| SLR_NO_UI),
+                                     SAL_WHERE);
 
         wchar_t pathW[EXTENDED_MAX_PATH];
         WIN32_FIND_DATAW wfd;
-        hr = pIShellLink->GetPath(pathW, std::size(pathW), &wfd, SLGP_RAWPATH);
-        if (FAILED(hr))
-            return target;
+        sal::systools::ThrowIfFailed(
+            pIShellLink->GetPath(pathW, std::size(pathW), &wfd, SLGP_RAWPATH), 
SAL_WHERE);
 
         target = pathW;
     }
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 0414a0826f62..da60f742020c 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -541,8 +541,8 @@ WinFontFace::GetVariations(const LogicalFontInstance& 
rFont) const
     if (!mxVariations)
     {
         mxVariations.emplace();
-        sal::systools::COMReference<IDWriteFontFace5> xDWFontFace5(
-            static_cast<const WinFontInstance&>(rFont).GetDWFontFace(), 
sal::systools::COM_QUERY);
+        auto xDWFontFace5(static_cast<const 
WinFontInstance&>(rFont).GetDWFontFace()
+                              .QueryInterface<IDWriteFontFace5>());
         if (xDWFontFace5 && xDWFontFace5->HasVariations())
         {
             std::vector<DWRITE_FONT_AXIS_VALUE> 
aAxisValues(xDWFontFace5->GetFontAxisValueCount());

Reply via email to