connectivity/source/drivers/ado/AColumn.cxx                            |   16 
 connectivity/source/drivers/ado/AColumns.cxx                           |    4 
 connectivity/source/drivers/ado/AConnection.cxx                        |   81 
+--
 connectivity/source/drivers/ado/ADatabaseMetaData.cxx                  |   86 
+--
 connectivity/source/drivers/ado/ADatabaseMetaDataImpl.cxx              |   70 
--
 connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx |    5 
 connectivity/source/drivers/ado/ADriver.cxx                            |   17 
 connectivity/source/drivers/ado/AGroup.cxx                             |   16 
 connectivity/source/drivers/ado/AIndex.cxx                             |    2 
 connectivity/source/drivers/ado/AIndexes.cxx                           |    2 
 connectivity/source/drivers/ado/AKey.cxx                               |   12 
 connectivity/source/drivers/ado/AKeys.cxx                              |    4 
 connectivity/source/drivers/ado/APreparedStatement.cxx                 |   24 
 connectivity/source/drivers/ado/AResultSet.cxx                         |   12 
 connectivity/source/drivers/ado/AResultSetMetaData.cxx                 |    5 
 connectivity/source/drivers/ado/AStatement.cxx                         |    8 
 connectivity/source/drivers/ado/ATable.cxx                             |    6 
 connectivity/source/drivers/ado/ATables.cxx                            |    4 
 connectivity/source/drivers/ado/AUser.cxx                              |   10 
 connectivity/source/drivers/ado/AViews.cxx                             |    4 
 connectivity/source/drivers/ado/Awrapado.cxx                           |  248 
++--------
 connectivity/source/drivers/ado/adoimp.cxx                             |    5 
 connectivity/source/inc/ado/AConnection.hxx                            |    4 
 connectivity/source/inc/ado/ADatabaseMetaData.hxx                      |    2 
 connectivity/source/inc/ado/Aolewrap.hxx                               |  109 
+---
 connectivity/source/inc/ado/Awrapado.hxx                               |   23 
 connectivity/source/inc/ado/Awrapadox.hxx                              |    4 
 connectivity/source/inc/ado/WrapColumn.hxx                             |    2 
 connectivity/source/inc/ado/WrapIndex.hxx                              |    2 
 connectivity/source/inc/ado/WrapKey.hxx                                |    2 
 connectivity/source/inc/ado/WrapTable.hxx                              |    4 
 connectivity/source/inc/ado/WrapTypeDefs.hxx                           |   14 
 connectivity/source/inc/ado/adoimp.hxx                                 |    2 
 include/systools/win32/comtools.hxx                                    |   19 
 34 files changed, 272 insertions(+), 556 deletions(-)

New commits:
commit cb2d87c97b8e67e78a3cb42267df88aa5fb39569
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Dec 20 18:58:32 2021 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Dec 21 09:22:44 2021 +0100

    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.kagan...@collabora.com>

diff --git a/connectivity/source/drivers/ado/AColumn.cxx 
b/connectivity/source/drivers/ado/AColumn.cxx
index 98b4c899595a..e136e39f4e2b 100644
--- a/connectivity/source/drivers/ado/AColumn.cxx
+++ b/connectivity/source/drivers/ado/AColumn.cxx
@@ -40,19 +40,7 @@ using namespace com::sun::star::sdbc;
 
 void WpADOColumn::Create()
 {
-    _ADOColumn* pColumn = nullptr;
-    HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOCOLUMN_25,
-                          nullptr,
-                          CLSCTX_INPROC_SERVER,
-                          ADOS::IID_ADOCOLUMN_25,
-                          reinterpret_cast<void**>(&pColumn) );
-
-
-    if( !FAILED( hr ) )
-    {
-        operator=( pColumn );
-        pColumn->Release( );
-    }
+    pInterface.TryCoCreateInstance(ADOS::CLSID_ADOCOLUMN_25, nullptr, 
CLSCTX_INPROC_SERVER);
 }
 
 OAdoColumn::OAdoColumn(bool _bCase,OConnection* _pConnection,_ADOColumn* 
_pColumn)
@@ -61,7 +49,7 @@ OAdoColumn::OAdoColumn(bool _bCase,OConnection* 
_pConnection,_ADOColumn* _pColum
 {
     construct();
     OSL_ENSURE(_pColumn,"Column can not be null!");
-    m_aColumn = WpADOColumn(_pColumn);
+    m_aColumn.set(_pColumn);
     //  
m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog());
     fillPropertyValues();
 }
diff --git a/connectivity/source/drivers/ado/AColumns.cxx 
b/connectivity/source/drivers/ado/AColumns.cxx
index 6297871d5b62..229903502fa1 100644
--- a/connectivity/source/drivers/ado/AColumns.cxx
+++ b/connectivity/source/drivers/ado/AColumns.cxx
@@ -109,7 +109,7 @@ sdbcx::ObjectType OColumns::appendObject( const OUString&, 
const Reference< XPro
             aAddedColumn.put_RelatedColumn(aColumn.get_RelatedColumn());
         }
     }
-    
ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
+    
ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
 
     return new 
OAdoColumn(isCaseSensitive(),m_pConnection,pColumn->getColumnImpl());
 }
@@ -118,7 +118,7 @@ sdbcx::ObjectType OColumns::appendObject( const OUString&, 
const Reference< XPro
 void OColumns::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName)
 {
     if(!m_aCollection.Delete(_sElementName))
-        
ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
+        
ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
 }
 
 
diff --git a/connectivity/source/drivers/ado/AConnection.cxx 
b/connectivity/source/drivers/ado/AConnection.cxx
index 19276dfac73c..5b44d9e6f4fb 100644
--- a/connectivity/source/drivers/ado/AConnection.cxx
+++ b/connectivity/source/drivers/ado/AConnection.cxx
@@ -51,7 +51,6 @@ 
IMPLEMENT_SERVICE_INFO(OConnection,"com.sun.star.sdbcx.AConnection","com.sun.sta
 OConnection::OConnection(ODriver*   _pDriver)
                          : m_xCatalog(nullptr),
                          m_pDriver(_pDriver),
-                         m_pAdoConnection(nullptr),
                          m_pCatalog(nullptr),
                          m_nEngineType(0),
                          m_bClosed(false),
@@ -59,36 +58,19 @@ OConnection::OConnection(ODriver*   _pDriver)
 {
     osl_atomic_increment( &m_refCount );
 
-    IClassFactory2* pIUnknown   = nullptr;
-    HRESULT         hr;
-    hr = CoGetClassObject( ADOS::CLSID_ADOCONNECTION_21,
-                          CLSCTX_INPROC_SERVER,
-                          nullptr,
-                          IID_IClassFactory2,
-                          reinterpret_cast<void**>(&pIUnknown) );
-
-    if( !FAILED( hr ) )
+    sal::systools::COMReference<IClassFactory2> pIUnknown;
+    if (!FAILED(pIUnknown.TryCoGetClassObject(ADOS::CLSID_ADOCONNECTION_21, 
CLSCTX_INPROC_SERVER)))
     {
-        ADOConnection *pCon         = nullptr;
-        IUnknown *pOuter     = nullptr;
-        hr = pIUnknown->CreateInstanceLic(  pOuter,
+        HRESULT hr = pIUnknown->CreateInstanceLic(nullptr,
                                             nullptr,
                                             ADOS::IID_ADOCONNECTION_21,
                                             ADOS::GetKeyStr().asBSTR(),
-                                            reinterpret_cast<void**>(&pCon));
+                                            
reinterpret_cast<void**>(&m_aAdoConnection));
 
         if( !FAILED( hr ) )
         {
-            OSL_ENSURE( pCon, "OConnection::OConnection: invalid ADO object!" 
);
-
-            m_pAdoConnection = new WpADOConnection( pCon );
-            // CreateInstanceLic returned an object which was already acquired
-            pCon->Release( );
-
+            OSL_ENSURE(m_aAdoConnection, "OConnection::OConnection: invalid 
ADO object!");
         }
-
-        // Class Factory is no longer needed
-        pIUnknown->Release();
     }
 
     osl_atomic_decrement( &m_refCount );
@@ -124,16 +106,16 @@ void OConnection::construct(const OUString& url,const 
Sequence< PropertyValue >&
     }
     try
     {
-        if(m_pAdoConnection)
+        if(m_aAdoConnection)
         {
-            if(m_pAdoConnection->Open(aDSN,aUID,aPWD,adConnectUnspecified))
-                m_pAdoConnection->PutCommandTimeout(nTimeout);
+            if(m_aAdoConnection.Open(aDSN,aUID,aPWD,adConnectUnspecified))
+                m_aAdoConnection.PutCommandTimeout(nTimeout);
             else
-                ADOS::ThrowException(*m_pAdoConnection,*this);
-            if(m_pAdoConnection->get_State() != adStateOpen)
+                ADOS::ThrowException(m_aAdoConnection,*this);
+            if(m_aAdoConnection.get_State() != adStateOpen)
                 throwGenericSQLException( STR_NO_CONNECTION,*this );
 
-            WpADOProperties aProps = m_pAdoConnection->get_Properties();
+            WpADOProperties aProps = m_aAdoConnection.get_Properties();
             if(aProps.IsValid())
             {
                 OTools::putValue(aProps, std::u16string_view(u"Jet OLEDB:ODBC 
Parsing"), true);
@@ -196,13 +178,13 @@ OUString SAL_CALL OConnection::nativeSQL( const OUString& 
_sql )
 
 
     OUString sql = _sql;
-    WpADOProperties aProps = m_pAdoConnection->get_Properties();
+    WpADOProperties aProps = m_aAdoConnection.get_Properties();
     if(aProps.IsValid())
     {
         OTools::putValue(aProps, std::u16string_view(u"Jet OLEDB:ODBC 
Parsing"), true);
         WpADOCommand aCommand;
         aCommand.Create();
-        
aCommand.put_ActiveConnection(static_cast<IDispatch*>(*m_pAdoConnection));
+        
aCommand.put_ActiveConnection(static_cast<IDispatch*>(m_aAdoConnection));
         aCommand.put_CommandText(sql);
         sql = aCommand.get_CommandText();
     }
@@ -218,9 +200,9 @@ void SAL_CALL OConnection::setAutoCommit( sal_Bool 
autoCommit )
 
     m_bAutocommit = autoCommit;
     if(!autoCommit)
-        m_pAdoConnection->BeginTrans();
+        m_aAdoConnection.BeginTrans();
     else
-        m_pAdoConnection->RollbackTrans();
+        m_aAdoConnection.RollbackTrans();
 }
 
 sal_Bool SAL_CALL OConnection::getAutoCommit(  )
@@ -238,7 +220,7 @@ void SAL_CALL OConnection::commit(  )
     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
 
-    m_pAdoConnection->CommitTrans();
+    m_aAdoConnection.CommitTrans();
 }
 
 void SAL_CALL OConnection::rollback(  )
@@ -247,14 +229,14 @@ void SAL_CALL OConnection::rollback(  )
     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
 
-    m_pAdoConnection->RollbackTrans();
+    m_aAdoConnection.RollbackTrans();
 }
 
 sal_Bool SAL_CALL OConnection::isClosed(  )
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
-    return OConnection_BASE::rBHelper.bDisposed && 
!m_pAdoConnection->get_State();
+    return OConnection_BASE::rBHelper.bDisposed && 
!m_aAdoConnection.get_State();
 }
 
 Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData(  )
@@ -279,8 +261,8 @@ void SAL_CALL OConnection::setReadOnly( sal_Bool readOnly )
     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
 
-    m_pAdoConnection->put_Mode(readOnly ? adModeRead : adModeReadWrite);
-    ADOS::ThrowException(*m_pAdoConnection,*this);
+    m_aAdoConnection.put_Mode(readOnly ? adModeRead : adModeReadWrite);
+    ADOS::ThrowException(m_aAdoConnection,*this);
 }
 
 sal_Bool SAL_CALL OConnection::isReadOnly(  )
@@ -289,7 +271,7 @@ sal_Bool SAL_CALL OConnection::isReadOnly(  )
     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
 
-    return m_pAdoConnection->get_Mode() == adModeRead;
+    return m_aAdoConnection.get_Mode() == adModeRead;
 }
 
 void SAL_CALL OConnection::setCatalog( const OUString& catalog )
@@ -297,8 +279,8 @@ void SAL_CALL OConnection::setCatalog( const OUString& 
catalog )
     ::osl::MutexGuard aGuard( m_aMutex );
     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
-    m_pAdoConnection->PutDefaultDatabase(catalog);
-    ADOS::ThrowException(*m_pAdoConnection,*this);
+    m_aAdoConnection.PutDefaultDatabase(catalog);
+    ADOS::ThrowException(m_aAdoConnection,*this);
 }
 
 OUString SAL_CALL OConnection::getCatalog(  )
@@ -306,7 +288,7 @@ OUString SAL_CALL OConnection::getCatalog(  )
     ::osl::MutexGuard aGuard( m_aMutex );
     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
-    return m_pAdoConnection->GetDefaultDatabase();
+    return m_aAdoConnection.GetDefaultDatabase();
 }
 
 void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level )
@@ -337,8 +319,8 @@ void SAL_CALL OConnection::setTransactionIsolation( 
sal_Int32 level )
             OSL_FAIL("OConnection::setTransactionIsolation invalid level");
             return;
     }
-    m_pAdoConnection->put_IsolationLevel(eIso);
-    ADOS::ThrowException(*m_pAdoConnection,*this);
+    m_aAdoConnection.put_IsolationLevel(eIso);
+    ADOS::ThrowException(m_aAdoConnection,*this);
 }
 
 sal_Int32 SAL_CALL OConnection::getTransactionIsolation(  )
@@ -348,7 +330,7 @@ sal_Int32 SAL_CALL OConnection::getTransactionIsolation(  )
 
 
     sal_Int32 nRet = 0;
-    switch(m_pAdoConnection->get_IsolationLevel())
+    switch(m_aAdoConnection.get_IsolationLevel())
     {
         case adXactUnspecified:
             nRet = TransactionIsolation::NONE;
@@ -368,7 +350,7 @@ sal_Int32 SAL_CALL OConnection::getTransactionIsolation(  )
         default:
             OSL_FAIL("OConnection::setTransactionIsolation invalid level");
     }
-    ADOS::ThrowException(*m_pAdoConnection,*this);
+    ADOS::ThrowException(m_aAdoConnection,*this);
     return nRet;
 }
 
@@ -411,7 +393,7 @@ void OConnection::buildTypeInfo()
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
-    ADORecordset *pRecordset = m_pAdoConnection->getTypeInfo();
+    ADORecordset *pRecordset = m_aAdoConnection.getTypeInfo();
     if ( pRecordset )
     {
         pRecordset->AddRef();
@@ -476,15 +458,14 @@ void OConnection::disposing()
     m_xCatalog  = css::uno::WeakReference< css::sdbcx::XTablesSupplier>();
     m_pDriver   = nullptr;
 
-    m_pAdoConnection->Close();
+    m_aAdoConnection.Close();
 
     for (auto& rEntry : m_aTypeInfo)
         delete rEntry.second;
 
     m_aTypeInfo.clear();
 
-    delete m_pAdoConnection;
-    m_pAdoConnection = nullptr;
+    m_aAdoConnection.clear();
 }
 
 sal_Int64 SAL_CALL OConnection::getSomething( const css::uno::Sequence< 
sal_Int8 >& rId )
diff --git a/connectivity/source/drivers/ado/ADatabaseMetaData.cxx 
b/connectivity/source/drivers/ado/ADatabaseMetaData.cxx
index b3f319203834..b2a4f54b524e 100644
--- a/connectivity/source/drivers/ado/ADatabaseMetaData.cxx
+++ b/connectivity/source/drivers/ado/ADatabaseMetaData.cxx
@@ -42,15 +42,15 @@ using namespace com::sun::star::sdbc;
 
 ODatabaseMetaData::ODatabaseMetaData(OConnection* _pCon)
     : ::connectivity::ODatabaseMetaDataBase(_pCon,_pCon->getConnectionInfo())
-    ,m_pADOConnection(_pCon->getConnection())
+    ,m_rADOConnection(_pCon->getConnection())
     ,m_pConnection(_pCon)
 {
 }
 
 sal_Int32 ODatabaseMetaData::getInt32Property(const OUString& _aProperty)
 {
-    connectivity::ado::WpADOProperties 
aProps(m_pADOConnection->get_Properties());
-    //  ADOS::ThrowException(*m_pADOConnection,*this);
+    connectivity::ado::WpADOProperties 
aProps(m_rADOConnection.get_Properties());
+    //  ADOS::ThrowException(m_rADOConnection,*this);
     OSL_ENSURE(aProps.IsValid(),"There are no properties at the connection");
     ADO_PROP(_aProperty);
     sal_Int32 nValue(0);
@@ -62,8 +62,8 @@ sal_Int32 ODatabaseMetaData::getInt32Property(const OUString& 
_aProperty)
 
 bool ODatabaseMetaData::getBoolProperty(const OUString& _aProperty)
 {
-    connectivity::ado::WpADOProperties 
aProps(m_pADOConnection->get_Properties());
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    connectivity::ado::WpADOProperties 
aProps(m_rADOConnection.get_Properties());
+    ADOS::ThrowException(m_rADOConnection,*this);
     OSL_ENSURE(aProps.IsValid(),"There are no properties at the connection");
     ADO_PROP(_aProperty);
     return !aVar.isNull() && !aVar.isEmpty() && aVar.getBool();
@@ -71,8 +71,8 @@ bool ODatabaseMetaData::getBoolProperty(const OUString& 
_aProperty)
 
 OUString ODatabaseMetaData::getStringProperty(const OUString& _aProperty)
 {
-    connectivity::ado::WpADOProperties 
aProps(m_pADOConnection->get_Properties());
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    connectivity::ado::WpADOProperties 
aProps(m_rADOConnection.get_Properties());
+    ADOS::ThrowException(m_rADOConnection,*this);
     OSL_ENSURE(aProps.IsValid(),"There are no properties at the connection");
 
     ADO_PROP(_aProperty);
@@ -85,7 +85,7 @@ OUString ODatabaseMetaData::getStringProperty(const OUString& 
_aProperty)
 
 Reference< XResultSet > ODatabaseMetaData::impl_getTypeInfo_throw(  )
 {
-    ADORecordset *pRecordset = m_pADOConnection->getTypeInfo();
+    ADORecordset *pRecordset = m_rADOConnection.getTypeInfo();
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setTypeInfoMap(ADOS::isJetEngine(m_pConnection->getEngineType()));
@@ -98,8 +98,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getCatalogs(  )
     vtEmpty.setNoArg();
 
     ADORecordset *pRecordset = nullptr;
-    m_pADOConnection->OpenSchema(adSchemaCatalogs,vtEmpty,vtEmpty,&pRecordset);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    m_rADOConnection.OpenSchema(adSchemaCatalogs,vtEmpty,vtEmpty,&pRecordset);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setCatalogsMap();
@@ -118,8 +118,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getSchemas(  )
     vtEmpty.setNoArg();
 
     ADORecordset *pRecordset = nullptr;
-    m_pADOConnection->OpenSchema(adSchemaSchemata,vtEmpty,vtEmpty,&pRecordset);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    m_rADOConnection.OpenSchema(adSchemaSchemata,vtEmpty,vtEmpty,&pRecordset);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setSchemasMap();
@@ -130,8 +130,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getColumnPrivileges(
     const Any& catalog, const OUString& schema, const OUString& table,
     const OUString& columnNamePattern )
 {
-    ADORecordset *pRecordset = 
m_pADOConnection->getColumnPrivileges(catalog,schema,table,columnNamePattern);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    ADORecordset *pRecordset = 
m_rADOConnection.getColumnPrivileges(catalog,schema,table,columnNamePattern);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setColumnPrivilegesMap();
@@ -142,8 +142,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getColumns(
     const Any& catalog, const OUString& schemaPattern, const OUString& 
tableNamePattern,
     const OUString& columnNamePattern )
 {
-    ADORecordset *pRecordset = 
m_pADOConnection->getColumns(catalog,schemaPattern,tableNamePattern,columnNamePattern);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    ADORecordset *pRecordset = 
m_rADOConnection.getColumns(catalog,schemaPattern,tableNamePattern,columnNamePattern);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setColumnsMap();
@@ -155,8 +155,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getTables(
     const Any& catalog, const OUString& schemaPattern,
     const OUString& tableNamePattern, const Sequence< OUString >& types )
 {
-    ADORecordset *pRecordset = 
m_pADOConnection->getTables(catalog,schemaPattern,tableNamePattern,types);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    ADORecordset *pRecordset = 
m_rADOConnection.getTables(catalog,schemaPattern,tableNamePattern,types);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setTablesMap();
@@ -168,8 +168,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getProcedureColumns(
     const Any& catalog, const OUString& schemaPattern,
     const OUString& procedureNamePattern, const OUString& columnNamePattern )
 {
-    ADORecordset *pRecordset = 
m_pADOConnection->getProcedureColumns(catalog,schemaPattern,procedureNamePattern,columnNamePattern);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    ADORecordset *pRecordset = 
m_rADOConnection.getProcedureColumns(catalog,schemaPattern,procedureNamePattern,columnNamePattern);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setProcedureColumnsMap();
@@ -182,8 +182,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getProcedures(
     const OUString& procedureNamePattern )
 {
     // Create elements used in the array
-    ADORecordset *pRecordset = 
m_pADOConnection->getProcedures(catalog,schemaPattern,procedureNamePattern);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    ADORecordset *pRecordset = 
m_rADOConnection.getProcedures(catalog,schemaPattern,procedureNamePattern);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setProceduresMap();
@@ -254,8 +254,8 @@ sal_Int32 
ODatabaseMetaData::impl_getMaxTablesInSelect_throw(  )
 Reference< XResultSet > SAL_CALL ODatabaseMetaData::getExportedKeys(
     const Any& catalog, const OUString& schema, const OUString& table )
 {
-    ADORecordset *pRecordset = 
m_pADOConnection->getExportedKeys(catalog,schema,table);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    ADORecordset *pRecordset = 
m_rADOConnection.getExportedKeys(catalog,schema,table);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setCrossReferenceMap();
@@ -266,8 +266,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getExportedKeys(
 Reference< XResultSet > SAL_CALL ODatabaseMetaData::getImportedKeys(
     const Any& catalog, const OUString& schema, const OUString& table )
 {
-    ADORecordset *pRecordset = 
m_pADOConnection->getImportedKeys(catalog,schema,table);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    ADORecordset *pRecordset = 
m_rADOConnection.getImportedKeys(catalog,schema,table);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setCrossReferenceMap();
@@ -278,8 +278,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getImportedKeys(
 Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys(
     const Any& catalog, const OUString& schema, const OUString& table )
 {
-    ADORecordset *pRecordset = 
m_pADOConnection->getPrimaryKeys(catalog,schema,table);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    ADORecordset *pRecordset = 
m_rADOConnection.getPrimaryKeys(catalog,schema,table);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setPrimaryKeysMap();
@@ -291,8 +291,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getIndexInfo(
     const Any& catalog, const OUString& schema, const OUString& table,
     sal_Bool unique, sal_Bool approximate )
 {
-    ADORecordset *pRecordset = 
m_pADOConnection->getIndexInfo(catalog,schema,table,unique,approximate);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    ADORecordset *pRecordset = 
m_rADOConnection.getIndexInfo(catalog,schema,table,unique,approximate);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setIndexInfoMap();
@@ -308,8 +308,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getTablePrivileges(
     {   // the jet provider doesn't support this method
         // Create elements used in the array
 
-        ADORecordset *pRecordset = 
m_pADOConnection->getTablePrivileges(catalog,schemaPattern,tableNamePattern);
-        ADOS::ThrowException(*m_pADOConnection,*this);
+        ADORecordset *pRecordset = 
m_rADOConnection.getTablePrivileges(catalog,schemaPattern,tableNamePattern);
+        ADOS::ThrowException(m_rADOConnection,*this);
 
         rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
         pResult->setTablePrivilegesMap();
@@ -358,8 +358,8 @@ Reference< XResultSet > SAL_CALL 
ODatabaseMetaData::getCrossReference(
     const OUString& primaryTable, const Any& foreignCatalog,
     const OUString& foreignSchema, const OUString& foreignTable )
 {
-    ADORecordset *pRecordset = 
m_pADOConnection->getCrossReference(primaryCatalog,primarySchema,primaryTable,foreignCatalog,foreignSchema,foreignTable);
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    ADORecordset *pRecordset = 
m_rADOConnection.getCrossReference(primaryCatalog,primarySchema,primaryTable,foreignCatalog,foreignSchema,foreignTable);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
     rtl::Reference<ODatabaseMetaDataResultSet> pResult = new 
ODatabaseMetaDataResultSet(pRecordset);
     pResult->setCrossReferenceMap();
@@ -790,7 +790,7 @@ sal_Bool SAL_CALL 
ODatabaseMetaData::supportsANSI92IntermediateSQL(  )
 
 OUString SAL_CALL ODatabaseMetaData::getURL(  )
 {
-    return "sdbc:ado:"+ m_pADOConnection->GetConnectionString();
+    return "sdbc:ado:"+ m_rADOConnection.GetConnectionString();
 }
 
 OUString SAL_CALL ODatabaseMetaData::getUserName(  )
@@ -836,7 +836,7 @@ sal_Int32 SAL_CALL 
ODatabaseMetaData::getDriverMajorVersion(  )
 sal_Int32 SAL_CALL ODatabaseMetaData::getDefaultTransactionIsolation(  )
 {
     sal_Int32 nRet = TransactionIsolation::NONE;
-    switch(m_pADOConnection->get_IsolationLevel())
+    switch(m_rADOConnection.get_IsolationLevel())
     {
         case adXactReadCommitted:
             nRet = TransactionIsolation::READ_COMMITTED;
@@ -863,22 +863,20 @@ sal_Int32 SAL_CALL 
ODatabaseMetaData::getDriverMinorVersion(  )
 
 OUString SAL_CALL ODatabaseMetaData::getSQLKeywords(  )
 {
-    ADORecordset *pRecordset = nullptr;
+    WpADORecordset aRecordset;
     OLEVariant  vtEmpty;
     vtEmpty.setNoArg();
-    
m_pADOConnection->OpenSchema(adSchemaDBInfoKeywords,vtEmpty,vtEmpty,&pRecordset);
-    OSL_ENSURE(pRecordset,"getSQLKeywords: no resultset!");
-    ADOS::ThrowException(*m_pADOConnection,*this);
-    if ( pRecordset )
+    
m_rADOConnection.OpenSchema(adSchemaDBInfoKeywords,vtEmpty,vtEmpty,&aRecordset);
+    OSL_ENSURE(aRecordset,"getSQLKeywords: no resultset!");
+    ADOS::ThrowException(m_rADOConnection,*this);
+    if ( aRecordset )
     {
-        WpADORecordset aRecordset(pRecordset);
-
         aRecordset.MoveFirst();
         OLEVariant  aValue;
         OUString aRet;
         while(!aRecordset.IsAtEOF())
         {
-            WpOLEAppendCollection<ADOFields, ADOField, WpADOField>  
aFields(aRecordset.GetFields());
+            WpOLEAppendCollection<ADOFields, WpADOField>  
aFields(aRecordset.GetFields());
             WpADOField aField(aFields.GetItem(0));
             aField.get_Value(aValue);
             aRet += aValue.getString() + ",";
diff --git a/connectivity/source/drivers/ado/ADatabaseMetaDataImpl.cxx 
b/connectivity/source/drivers/ado/ADatabaseMetaDataImpl.cxx
index 8972a4f2dee1..42cf95a827ae 100644
--- a/connectivity/source/drivers/ado/ADatabaseMetaDataImpl.cxx
+++ b/connectivity/source/drivers/ado/ADatabaseMetaDataImpl.cxx
@@ -48,24 +48,22 @@ using namespace ::com::sun::star::uno;
 
 void ODatabaseMetaData::fillLiterals()
 {
-    ADORecordset *pRecordset = nullptr;
+    WpADORecordset aRecordset;
     OLEVariant  vtEmpty;
     vtEmpty.setNoArg();
-    
m_pADOConnection->OpenSchema(adSchemaDBInfoLiterals,vtEmpty,vtEmpty,&pRecordset);
+    
m_rADOConnection.OpenSchema(adSchemaDBInfoLiterals,vtEmpty,vtEmpty,&aRecordset);
 
-    ADOS::ThrowException(*m_pADOConnection,*this);
+    ADOS::ThrowException(m_rADOConnection,*this);
 
-    OSL_ENSURE(pRecordset,"fillLiterals: no resultset!");
-    if ( pRecordset )
+    OSL_ENSURE(aRecordset,"fillLiterals: no resultset!");
+    if ( aRecordset )
     {
-        WpADORecordset aRecordset(pRecordset);
-
         aRecordset.MoveFirst();
         OLEVariant  aValue;
         LiteralInfo aInfo;
         while(!aRecordset.IsAtEOF())
         {
-            WpOLEAppendCollection<ADOFields, ADOField, WpADOField>  
aFields(aRecordset.GetFields());
+            WpOLEAppendCollection<ADOFields, WpADOField>  
aFields(aRecordset.GetFields());
             WpADOField aField(aFields.GetItem(1));
             aInfo.pwszLiteralValue = aField.get_Value().getString();
             aField = aFields.GetItem(5);
@@ -387,19 +385,7 @@ RightsEnum OAdoGroup::Map2Right(sal_Int32 _eNum)
 
 void WpADOIndex::Create()
 {
-    _ADOIndex* pIndex = nullptr;
-    HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOINDEX_25,
-                          nullptr,
-                          CLSCTX_INPROC_SERVER,
-                          ADOS::IID_ADOINDEX_25,
-                          reinterpret_cast<void**>(&pIndex) );
-
-
-    if( !FAILED( hr ) )
-    {
-        operator=( pIndex );
-        pIndex->Release();
-    }
+    pInterface.TryCoCreateInstance(ADOS::CLSID_ADOINDEX_25, nullptr, 
CLSCTX_INPROC_SERVER);
 }
 
 void OAdoIndex::fillPropertyValues()
@@ -415,19 +401,7 @@ void OAdoIndex::fillPropertyValues()
 
 void WpADOKey::Create()
 {
-    _ADOKey* pKey = nullptr;
-    HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOKEY_25,
-                          nullptr,
-                          CLSCTX_INPROC_SERVER,
-                          ADOS::IID_ADOKEY_25,
-                          reinterpret_cast<void**>(&pKey) );
-
-
-    if( !FAILED( hr ) )
-    {
-        operator=( pKey );
-        pKey->Release();
-    }
+    pInterface.TryCoCreateInstance(ADOS::CLSID_ADOKEY_25, nullptr, 
CLSCTX_INPROC_SERVER);
 }
 
 void OAdoKey::fillPropertyValues()
@@ -524,19 +498,7 @@ KeyTypeEnum OAdoKey::Map2KeyRule(sal_Int32 _eNum)
 
 void WpADOTable::Create()
 {
-    _ADOTable* pTable = nullptr;
-    HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOTABLE_25,
-                          nullptr,
-                          CLSCTX_INPROC_SERVER,
-                          ADOS::IID_ADOTABLE_25,
-                          reinterpret_cast<void**>(&pTable) );
-
-
-    if( !FAILED( hr ) )
-    {
-        operator=( pTable );
-        pTable->Release();
-    }
+    pInterface.TryCoCreateInstance(ADOS::CLSID_ADOTABLE_25, nullptr, 
CLSCTX_INPROC_SERVER);
 }
 
 OUString WpADOCatalog::GetObjectOwner(std::u16string_view _rName, 
ObjectTypeEnum _eNum)
@@ -571,19 +533,7 @@ void OAdoTable::fillPropertyValues()
 
 void WpADOUser::Create()
 {
-    _ADOUser* pUser = nullptr;
-    HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOUSER_25,
-                          nullptr,
-                          CLSCTX_INPROC_SERVER,
-                          ADOS::IID_ADOUSER_25,
-                          reinterpret_cast<void**>(&pUser) );
-
-
-    if( !FAILED( hr ) )
-    {
-        operator=( pUser );
-        pUser->Release();
-    }
+    pInterface.TryCoCreateInstance(ADOS::CLSID_ADOUSER_25, nullptr, 
CLSCTX_INPROC_SERVER);
 }
 
 
diff --git 
a/connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx 
b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx
index 94dbfddb34f9..3fa13d06b84a 100644
--- a/connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx
+++ b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx
@@ -71,9 +71,8 @@ sal_Int32 SAL_CALL 
ODatabaseMetaDataResultSetMetaData::getColumnCount()
     if (m_vMapping.size())
         return m_mColumns.size();
 
-    ADOFields* pFields = nullptr;
-    m_pRecordSet->get_Fields(&pFields);
-    WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields);
+    WpOLEAppendCollection<ADOFields, WpADOField> aFields;
+    m_pRecordSet->get_Fields(&aFields);
     m_nColCount = aFields.GetItemCount();
     return m_nColCount;
 }
diff --git a/connectivity/source/drivers/ado/ADriver.cxx 
b/connectivity/source/drivers/ado/ADriver.cxx
index 3cdfeab26888..ad90d8d05556 100644
--- a/connectivity/source/drivers/ado/ADriver.cxx
+++ b/connectivity/source/drivers/ado/ADriver.cxx
@@ -187,7 +187,7 @@ Reference< XTablesSupplier > SAL_CALL 
ODriver::getDataDefinitionByConnection( co
         aCatalog.Create();
         if(aCatalog.IsValid())
         {
-            aCatalog.putref_ActiveConnection(*pConnection->getConnection());
+            aCatalog.putref_ActiveConnection(pConnection->getConnection());
             rtl::Reference<OCatalog> pCatalog = new 
OCatalog(aCatalog,pConnection);
             xTab = pCatalog;
             pConnection->setCatalog(xTab);
@@ -206,13 +206,11 @@ Reference< XTablesSupplier > SAL_CALL 
ODriver::getDataDefinitionByURL( const OUS
 
 void ADOS::ThrowException(ADOConnection* _pAdoCon,const Reference< XInterface 
>& _xInterface)
 {
-    ADOErrors *pErrors = nullptr;
+    sal::systools::COMReference<ADOErrors> pErrors;
     _pAdoCon->get_Errors(&pErrors);
     if(!pErrors)
         return; // no error found
 
-    pErrors->AddRef( );
-
     // read all noted errors and issue them
     sal_Int32 nLen;
     pErrors->get_Count(&nLen);
@@ -222,11 +220,10 @@ void ADOS::ThrowException(ADOConnection* _pAdoCon,const 
Reference< XInterface >&
         aException.ErrorCode = 1000;
         for (sal_Int32 i = nLen-1; i>=0; --i)
         {
-            ADOError *pError = nullptr;
-            pErrors->get_Item(OLEVariant(i),&pError);
-            WpADOError aErr(pError);
-            OSL_ENSURE(pError,"No error in collection found! BAD!");
-            if(pError)
+            WpADOError aErr;
+            pErrors->get_Item(OLEVariant(i),&aErr);
+            OSL_ENSURE(aErr,"No error in collection found! BAD!");
+            if(aErr)
             {
                 if(i==nLen-1)
                     aException = 
SQLException(aErr.GetDescription(),_xInterface,aErr.GetSQLState(),aErr.GetNumber(),Any());
@@ -240,10 +237,8 @@ void ADOS::ThrowException(ADOConnection* _pAdoCon,const 
Reference< XInterface >&
             }
         }
         pErrors->Clear();
-        pErrors->Release();
         throw aException;
     }
-    pErrors->Release();
 }
 
 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
diff --git a/connectivity/source/drivers/ado/AGroup.cxx 
b/connectivity/source/drivers/ado/AGroup.cxx
index f4ed2b12adbc..932cfc232de3 100644
--- a/connectivity/source/drivers/ado/AGroup.cxx
+++ b/connectivity/source/drivers/ado/AGroup.cxx
@@ -36,26 +36,14 @@ using namespace com::sun::star::sdbcx;
 
 void WpADOGroup::Create()
 {
-    ADOGroup* pGroup = nullptr;
-    HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOGROUP_25,
-                          nullptr,
-                          CLSCTX_INPROC_SERVER,
-                          ADOS::IID_ADOGROUP_25,
-                          reinterpret_cast<void**>(&pGroup) );
-
-
-    if( !FAILED( hr ) )
-    {
-        operator=( pGroup );
-        pGroup->Release();
-    }
+    pInterface.TryCoCreateInstance(ADOS::CLSID_ADOGROUP_25, nullptr, 
CLSCTX_INPROC_SERVER);
 }
 
 OAdoGroup::OAdoGroup(OCatalog* _pParent,bool _bCase,    ADOGroup* _pGroup) : 
OGroup_ADO(_bCase),m_pCatalog(_pParent)
 {
     construct();
     if(_pGroup)
-        m_aGroup = WpADOGroup(_pGroup);
+        m_aGroup.set(_pGroup);
     else
         m_aGroup.Create();
 
diff --git a/connectivity/source/drivers/ado/AIndex.cxx 
b/connectivity/source/drivers/ado/AIndex.cxx
index 6b58900893b8..af643a4368b0 100644
--- a/connectivity/source/drivers/ado/AIndex.cxx
+++ b/connectivity/source/drivers/ado/AIndex.cxx
@@ -39,7 +39,7 @@ OAdoIndex::OAdoIndex(bool _bCase,OConnection* 
_pConnection,ADOIndex* _pIndex)
     ,m_pConnection(_pConnection)
 {
     construct();
-    m_aIndex = WpADOIndex(_pIndex);
+    m_aIndex.set(_pIndex);
     fillPropertyValues();
 }
 
diff --git a/connectivity/source/drivers/ado/AIndexes.cxx 
b/connectivity/source/drivers/ado/AIndexes.cxx
index c2cdb76081d2..621ddec60d79 100644
--- a/connectivity/source/drivers/ado/AIndexes.cxx
+++ b/connectivity/source/drivers/ado/AIndexes.cxx
@@ -65,7 +65,7 @@ sdbcx::ObjectType OIndexes::appendObject( const OUString& 
_rForName, const Refer
     ADOIndexes* pIndexes = m_aCollection;
     if ( FAILED( pIndexes->Append( OLEVariant( _rForName ), OLEVariant( 
pIndex->getImpl() ) ) ) )
     {
-        
ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
+        
ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
         m_pConnection->throwGenericSQLException( 
STR_INVALID_INDEX_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
     }
 
diff --git a/connectivity/source/drivers/ado/AKey.cxx 
b/connectivity/source/drivers/ado/AKey.cxx
index 35e121c6bb7a..b74103d830d6 100644
--- a/connectivity/source/drivers/ado/AKey.cxx
+++ b/connectivity/source/drivers/ado/AKey.cxx
@@ -37,7 +37,7 @@ OAdoKey::OAdoKey(bool _bCase,OConnection* _pConnection, 
ADOKey* _pKey)
     ,m_pConnection(_pConnection)
 {
     construct();
-    m_aKey = WpADOKey(_pKey);
+    m_aKey.set(_pKey);
     fillPropertyValues();
 }
 
@@ -91,7 +91,7 @@ void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 
nHandle,const Any& rVal
                     OUString aVal;
                     rValue >>= aVal;
                     m_aKey.put_Name(aVal);
-                    
ADOS::ThrowException(*m_pConnection->getConnection(),*this);
+                    ADOS::ThrowException(m_pConnection->getConnection(),*this);
                 }
                 break;
             case PROPERTY_ID_TYPE:
@@ -99,7 +99,7 @@ void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 
nHandle,const Any& rVal
                     sal_Int32 nVal=0;
                     rValue >>= nVal;
                     m_aKey.put_Type(Map2KeyRule(nVal));
-                    
ADOS::ThrowException(*m_pConnection->getConnection(),*this);
+                    ADOS::ThrowException(m_pConnection->getConnection(),*this);
                 }
                 break;
             case PROPERTY_ID_REFERENCEDTABLE:
@@ -107,7 +107,7 @@ void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 
nHandle,const Any& rVal
                     OUString aVal;
                     rValue >>= aVal;
                     m_aKey.put_RelatedTable(aVal);
-                    
ADOS::ThrowException(*m_pConnection->getConnection(),*this);
+                    ADOS::ThrowException(m_pConnection->getConnection(),*this);
                 }
                 break;
             case PROPERTY_ID_UPDATERULE:
@@ -115,7 +115,7 @@ void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 
nHandle,const Any& rVal
                     sal_Int32 nVal=0;
                     rValue >>= nVal;
                     m_aKey.put_UpdateRule(Map2Rule(nVal));
-                    
ADOS::ThrowException(*m_pConnection->getConnection(),*this);
+                    ADOS::ThrowException(m_pConnection->getConnection(),*this);
                 }
                 break;
             case PROPERTY_ID_DELETERULE:
@@ -123,7 +123,7 @@ void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 
nHandle,const Any& rVal
                     sal_Int32 nVal=0;
                     rValue >>= nVal;
                     m_aKey.put_DeleteRule(Map2Rule(nVal));
-                    
ADOS::ThrowException(*m_pConnection->getConnection(),*this);
+                    ADOS::ThrowException(m_pConnection->getConnection(),*this);
                 }
                 break;
         }
diff --git a/connectivity/source/drivers/ado/AKeys.cxx 
b/connectivity/source/drivers/ado/AKeys.cxx
index a18d91709455..f0d938d397d6 100644
--- a/connectivity/source/drivers/ado/AKeys.cxx
+++ b/connectivity/source/drivers/ado/AKeys.cxx
@@ -78,7 +78,7 @@ sdbcx::ObjectType OKeys::appendObject( const OUString&, const 
Reference< XProper
                             adKeyPrimary, // must be every time adKeyPrimary
                             vOptional)) )
     {
-        
ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
+        
ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
         // just make sure that an SQLExceptionis thrown here
         m_pConnection->throwGenericSQLException( 
STR_INVALID_KEY_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
     }
@@ -90,7 +90,7 @@ sdbcx::ObjectType OKeys::appendObject( const OUString&, const 
Reference< XProper
 void OKeys::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName)
 {
     if(!m_aCollection.Delete(OLEVariant(_sElementName).getString()))
-        
ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
+        
ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
 }
 
 
diff --git a/connectivity/source/drivers/ado/APreparedStatement.cxx 
b/connectivity/source/drivers/ado/APreparedStatement.cxx
index 0db461ef12d3..cf2339fdc951 100644
--- a/connectivity/source/drivers/ado/APreparedStatement.cxx
+++ b/connectivity/source/drivers/ado/APreparedStatement.cxx
@@ -38,7 +38,7 @@
 
 #define CHECK_RETURN(x)                                                 \
     if(!x)                                                              \
-        ADOS::ThrowException(*m_pConnection->getConnection(),*this);
+        ADOS::ThrowException(m_pConnection->getConnection(),*this);
 
 #ifdef max
 #   undef max
@@ -151,7 +151,7 @@ sal_Bool SAL_CALL OPreparedStatement::execute(  )
     try {
         ADORecordset* pSet=nullptr;
         
CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdUnknown,&pSet))
-        m_RecordSet = WpADORecordset(pSet);
+        m_RecordSet.set(pSet);
     }
     catch (SQLWarning&)
     {
@@ -171,11 +171,11 @@ sal_Int32 SAL_CALL OPreparedStatement::executeUpdate(  )
     
CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdUnknown,&pSet))
     if ( VT_ERROR == m_RecordsAffected.getType() )
     {
-        ADOS::ThrowException(*m_pConnection->getConnection(),*this);
+        ADOS::ThrowException(m_pConnection->getConnection(),*this);
         // to be sure that we get the error really thrown
         throw SQLException();
     }
-    m_RecordSet = WpADORecordset(pSet);
+    m_RecordSet.set(pSet);
     return m_RecordsAffected.getInt32();
 }
 
@@ -199,10 +199,9 @@ void OPreparedStatement::setParameter(sal_Int32 
parameterIndex, const DataTypeEn
     }
     else
     {
-        ADOParameter* pParam = nullptr;
-        
m_pParameters->get_Item(OLEVariant(sal_Int32(parameterIndex-1)),&pParam);
-        WpADOParameter aParam(pParam);
-        if(pParam)
+        WpADOParameter aParam;
+        
m_pParameters->get_Item(OLEVariant(sal_Int32(parameterIndex-1)),&aParam);
+        if(aParam)
         {
             DataTypeEnum eType = aParam.GetADOType();
             if ( _eType != eType && _eType != adDBTimeStamp )
@@ -220,7 +219,7 @@ void OPreparedStatement::setParameter(sal_Int32 
parameterIndex, const DataTypeEn
                 CHECK_RETURN(aParam.PutValue(Val));
         }
     }
-    ADOS::ThrowException(*m_pConnection->getConnection(),*this);
+    ADOS::ThrowException(m_pConnection->getConnection(),*this);
 }
 
 void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const 
OUString& x )
@@ -412,10 +411,9 @@ void SAL_CALL OPreparedStatement::clearParameters(  )
         aVal.setEmpty();
         for(sal_Int32 i=0;i<nCount;++i)
         {
-            ADOParameter* pParam = nullptr;
-            m_pParameters->get_Item(OLEVariant(i),&pParam);
-            WpADOParameter aParam(pParam);
-            if(pParam)
+            WpADOParameter aParam;
+            m_pParameters->get_Item(OLEVariant(i),&aParam);
+            if(aParam)
             {
                 CHECK_RETURN(aParam.PutValue(aVal));
             }
diff --git a/connectivity/source/drivers/ado/AResultSet.cxx 
b/connectivity/source/drivers/ado/AResultSet.cxx
index abae9087823e..799d85c04924 100644
--- a/connectivity/source/drivers/ado/AResultSet.cxx
+++ b/connectivity/source/drivers/ado/AResultSet.cxx
@@ -44,7 +44,7 @@ using namespace ::comphelper;
 
 #define CHECK_RETURN(x)                                                 \
     if(!SUCCEEDED(x))                                                          
     \
-        ADOS::ThrowException(*m_pStmt->m_pConnection->getConnection(),*this);
+        ADOS::ThrowException(m_pStmt->m_pConnection->getConnection(),*this);
 
 using namespace connectivity::ado;
 using namespace com::sun::star::uno;
@@ -596,7 +596,7 @@ sal_Bool SAL_CALL OResultSet::next(  )
             ++m_nRowPos;
         }
         else
-            
ADOS::ThrowException(*m_pStmt->m_pConnection->getConnection(),*this);
+            
ADOS::ThrowException(m_pStmt->m_pConnection->getConnection(),*this);
     }
 
     return bRet;
@@ -882,11 +882,9 @@ sal_Bool SAL_CALL OResultSet::hasOrderedBookmarks(  )
     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
 
 
-    ADOProperties* pProps = nullptr;
-    m_pRecordSet->get_Properties(&pProps);
     WpADOProperties aProps;
-    aProps.setWithOutAddRef(pProps);
-    
ADOS::ThrowException(*static_cast<OConnection*>(m_pStmt->getConnection().get())->getConnection(),*this);
+    m_pRecordSet->get_Properties(&aProps);
+    
ADOS::ThrowException(static_cast<OConnection*>(m_pStmt->getConnection().get())->getConnection(),*this);
     OSL_ENSURE(aProps.IsValid(),"There are no properties at the connection");
 
     WpADOProperty aProp(aProps.GetItem(OUString("Bookmarks Ordered")));
@@ -894,7 +892,7 @@ sal_Bool SAL_CALL OResultSet::hasOrderedBookmarks(  )
     if(aProp.IsValid())
         aVar = aProp.GetValue();
     else
-        
ADOS::ThrowException(*static_cast<OConnection*>(m_pStmt->getConnection().get())->getConnection(),*this);
+        
ADOS::ThrowException(static_cast<OConnection*>(m_pStmt->getConnection().get())->getConnection(),*this);
 
     bool bValue(false);
     if(!aVar.isNull() && !aVar.isEmpty())
diff --git a/connectivity/source/drivers/ado/AResultSetMetaData.cxx 
b/connectivity/source/drivers/ado/AResultSetMetaData.cxx
index e64c1c45b6e9..d43ee5da9216 100644
--- a/connectivity/source/drivers/ado/AResultSetMetaData.cxx
+++ b/connectivity/source/drivers/ado/AResultSetMetaData.cxx
@@ -72,10 +72,9 @@ sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount(  )
     if ( !m_pRecordSet )
         return 0;
 
-    ADOFields* pFields  = nullptr;
+    WpOLEAppendCollection<ADOFields, WpADOField> pFields;
     m_pRecordSet->get_Fields(&pFields);
-    WpOLEAppendCollection<ADOFields, ADOField, WpADOField>  aFields(pFields);
-    m_nColCount = aFields.GetItemCount();
+    m_nColCount = pFields.GetItemCount();
     return m_nColCount;
 }
 
diff --git a/connectivity/source/drivers/ado/AStatement.cxx 
b/connectivity/source/drivers/ado/AStatement.cxx
index 9670d92292bd..9d8851a4089f 100644
--- a/connectivity/source/drivers/ado/AStatement.cxx
+++ b/connectivity/source/drivers/ado/AStatement.cxx
@@ -41,7 +41,7 @@ using namespace ::comphelper;
 
 #define CHECK_RETURN(x)                                                 \
     if(!x)                                                              \
-        ADOS::ThrowException(*m_pConnection->getConnection(),*this);
+        ADOS::ThrowException(m_pConnection->getConnection(),*this);
 
 
 using namespace connectivity::ado;
@@ -67,7 +67,7 @@ OStatement_Base::OStatement_Base(OConnection* _pConnection ) 
:  OStatement_BASE(
     if(m_Command.IsValid())
         m_Command.putref_ActiveConnection(m_pConnection->getConnection());
     else
-        ADOS::ThrowException(*m_pConnection->getConnection(),*this);
+        ADOS::ThrowException(m_pConnection->getConnection(),*this);
 
     m_RecordsAffected.setNoArg();
     m_Parameters.setNoArg();
@@ -95,7 +95,7 @@ void OStatement_Base::disposing()
     disposeResultSet();
 
     if ( m_Command.IsValid() )
-        m_Command.putref_ActiveConnection( nullptr );
+        m_Command.putref_ActiveConnection({});
     m_Command.clear();
 
     if ( m_RecordSet.IsValid() )
@@ -240,7 +240,7 @@ void OStatement_Base::setWarning (const SQLWarning &ex)
 void OStatement_Base::assignRecordSet( ADORecordset* _pRS )
 {
     WpADORecordset aOldRS( m_RecordSet );
-    m_RecordSet = WpADORecordset( _pRS );
+    m_RecordSet.set( _pRS );
 
     if ( aOldRS.IsValid() )
         aOldRS.PutRefDataSource( nullptr );
diff --git a/connectivity/source/drivers/ado/ATable.cxx 
b/connectivity/source/drivers/ado/ATable.cxx
index 1ade9a649b77..f048f3ec09ba 100644
--- a/connectivity/source/drivers/ado/ATable.cxx
+++ b/connectivity/source/drivers/ado/ATable.cxx
@@ -54,7 +54,7 @@ OAdoTable::OAdoTable(sdbcx::OCollection* _pTables,bool 
_bCase,OCatalog* _pCatalo
     ,m_pCatalog(_pCatalog)
 {
     construct();
-    m_aTable = WpADOTable(_pTable);
+    m_aTable.set(_pTable);
     //  m_aTable.putref_ParentCatalog(_pCatalog->getCatalog());
     fillPropertyValues();
 
@@ -148,7 +148,7 @@ void SAL_CALL OAdoTable::rename( const OUString& newName )
     checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed);
 
     m_aTable.put_Name(newName);
-    
ADOS::ThrowException(*(m_pCatalog->getConnection()->getConnection()),*this);
+    ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this);
 
     OTable_TYPEDEF::rename(newName);
 }
@@ -173,7 +173,7 @@ void SAL_CALL OAdoTable::alterColumnByName( const OUString& 
colName, const Refer
         bError = bError || !aColumns.Append(pColumn->getColumnImpl());
     }
     if(bError)
-        
ADOS::ThrowException(*(m_pCatalog->getConnection()->getConnection()),*this);
+        
ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this);
 
     m_xColumns->refresh();
     refreshColumns();
diff --git a/connectivity/source/drivers/ado/ATables.cxx 
b/connectivity/source/drivers/ado/ATables.cxx
index 61a057344ff1..3299181c5ef1 100644
--- a/connectivity/source/drivers/ado/ATables.cxx
+++ b/connectivity/source/drivers/ado/ATables.cxx
@@ -71,7 +71,7 @@ sdbcx::ObjectType OTables::appendObject( const OUString&, 
const Reference< XProp
 
     OSL_ENSURE(m_aCollection.IsValid(),"Collection isn't valid");
     if(!m_aCollection.Append(pTable->getImpl()))
-        
ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this));
+        
ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this));
     m_aCollection.Refresh();
 
     return new OAdoTable(this,isCaseSensitive(),m_pCatalog,pTable->getImpl());
@@ -82,7 +82,7 @@ void OTables::dropObject(sal_Int32 /*_nPos*/,const OUString& 
_sElementName)
 {
     OSL_ENSURE(m_aCollection.IsValid(),"Collection isn't valid");
     if ( !m_aCollection.Delete(_sElementName) )
-        
ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this));
+        
ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this));
 }
 
 void OTables::appendNew(const OUString& _rsNewTable)
diff --git a/connectivity/source/drivers/ado/AUser.cxx 
b/connectivity/source/drivers/ado/AUser.cxx
index 09585ed81e44..42f7240f8729 100644
--- a/connectivity/source/drivers/ado/AUser.cxx
+++ b/connectivity/source/drivers/ado/AUser.cxx
@@ -40,7 +40,7 @@ OAdoUser::OAdoUser(OCatalog* _pParent,bool _bCase, ADOUser* 
_pUser)
     construct();
 
     if(_pUser)
-        m_aUser = WpADOUser(_pUser);
+        m_aUser.set(_pUser);
     else
         m_aUser.Create();
 }
@@ -157,7 +157,7 @@ sal_Int32 SAL_CALL OAdoUser::getGrantablePrivileges( const 
OUString& objName, sa
     RightsEnum eRights = m_aUser.GetPermissions(objName, 
ADOS::mapObjectType2Ado(objType));
     if((eRights & adRightWithGrant) == adRightWithGrant)
         nRights = ADOS::mapAdoRights2Sdbc(eRights);
-    ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
+    ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this);
     return nRights;
 }
 
@@ -166,7 +166,7 @@ void SAL_CALL OAdoUser::grantPrivileges( const OUString& 
objName, sal_Int32 objT
     ::osl::MutexGuard aGuard(m_aMutex);
     checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
     
m_aUser.SetPermissions(objName,ADOS::mapObjectType2Ado(objType),adAccessGrant,RightsEnum(ADOS::mapRights2Ado(objPrivileges)));
-    ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
+    ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this);
 }
 
 void SAL_CALL OAdoUser::revokePrivileges( const OUString& objName, sal_Int32 
objType, sal_Int32 objPrivileges )
@@ -174,7 +174,7 @@ void SAL_CALL OAdoUser::revokePrivileges( const OUString& 
objName, sal_Int32 obj
     ::osl::MutexGuard aGuard(m_aMutex);
     checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
     
m_aUser.SetPermissions(objName,ADOS::mapObjectType2Ado(objType),adAccessRevoke,RightsEnum(ADOS::mapRights2Ado(objPrivileges)));
-    ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
+    ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this);
 }
 
 // XUser
@@ -183,7 +183,7 @@ void SAL_CALL OAdoUser::changePassword( const OUString& 
objPassword, const OUStr
     ::osl::MutexGuard aGuard(m_aMutex);
     checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
     m_aUser.ChangePassword(objPassword,newPassword);
-    ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
+    ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this);
 }
 
 
diff --git a/connectivity/source/drivers/ado/AViews.cxx 
b/connectivity/source/drivers/ado/AViews.cxx
index 22fe40142d25..4764833c8829 100644
--- a/connectivity/source/drivers/ado/AViews.cxx
+++ b/connectivity/source/drivers/ado/AViews.cxx
@@ -75,7 +75,7 @@ sdbcx::ObjectType OViews::appendObject( const OUString& 
_rForName, const Referen
     
aCommand.put_CommandText(getString(descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND))));
     ADOViews* pViews = m_aCollection;
     if(FAILED(pViews->Append(OLEString(sName).asBSTR(),aCommand)))
-        
ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this));
+        
ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this));
 
     OTables* pTables = 
static_cast<OTables*>(static_cast<OCatalog&>(m_rParent).getPrivateTables());
     if ( pTables )
@@ -88,7 +88,7 @@ sdbcx::ObjectType OViews::appendObject( const OUString& 
_rForName, const Referen
 void OViews::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName)
 {
     if(!m_aCollection.Delete(_sElementName))
-        
ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this));
+        
ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this));
 }
 
 
diff --git a/connectivity/source/drivers/ado/Awrapado.cxx 
b/connectivity/source/drivers/ado/Awrapado.cxx
index 6f4dd5ce1c20..2a9f66656956 100644
--- a/connectivity/source/drivers/ado/Awrapado.cxx
+++ b/connectivity/source/drivers/ado/Awrapado.cxx
@@ -28,26 +28,15 @@ using namespace connectivity::ado;
 
 void WpADOCatalog::Create()
 {
-    _ADOCatalog* pCommand;
-    HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOCATALOG_25,
-                          nullptr,
-                          CLSCTX_INPROC_SERVER,
-                          ADOS::IID_ADOCATALOG_25,
-                          reinterpret_cast<void**>(&pCommand) );
-
-
-    if( !FAILED( hr ) )
-        setWithOutAddRef(pCommand);
+    pInterface.TryCoCreateInstance(ADOS::CLSID_ADOCATALOG_25, nullptr, 
CLSCTX_INPROC_SERVER);
 }
 
 
 WpADOProperties WpADOConnection::get_Properties() const
 {
-    ADOProperties* pProps=nullptr;
+    WpADOProperties pProps;
     pInterface->get_Properties(&pProps);
-    WpADOProperties aProps;
-    aProps.setWithOutAddRef(pProps);
-    return aProps;
+    return pProps;
 }
 
 OUString WpADOConnection::GetConnectionString() const
@@ -252,13 +241,10 @@ OUString WpADOConnection::get_Version() const
     return aBSTR.asOUString();
 }
 
-bool WpADOCommand::putref_ActiveConnection( WpADOConnection *pCon)
+bool WpADOCommand::putref_ActiveConnection(const WpADOConnection& rCon)
 {
     assert(pInterface);
-    if(pCon)
-        return 
SUCCEEDED(pInterface->putref_ActiveConnection(pCon->pInterface));
-    else
-        return SUCCEEDED(pInterface->putref_ActiveConnection(nullptr));
+    return SUCCEEDED(pInterface->putref_ActiveConnection(rCon));
 }
 
 void WpADOCommand::put_ActiveConnection(/* [in] */ const OLEVariant& vConn)
@@ -269,31 +255,19 @@ void WpADOCommand::put_ActiveConnection(/* [in] */ const 
OLEVariant& vConn)
 
 void WpADOCommand::Create()
 {
-    IClassFactory2* pInterface2 = nullptr;
-    HRESULT hr = CoGetClassObject( ADOS::CLSID_ADOCOMMAND_21,
-                          CLSCTX_INPROC_SERVER,
-                          nullptr,
-                          IID_IClassFactory2,
-                          reinterpret_cast<void**>(&pInterface2) );
-
-    if( !FAILED( hr ) )
+    sal::systools::COMReference<IClassFactory2> pInterface2;
+    if (!FAILED(pInterface2.TryCoGetClassObject(ADOS::CLSID_ADOCOMMAND_21, 
CLSCTX_INPROC_SERVER)))
     {
-        ADOCommand* pCommand=nullptr;
-        IUnknown* pOuter=nullptr;
+        sal::systools::COMReference<ADOCommand> pCommand;
 
-        hr = pInterface2->CreateInstanceLic(  pOuter,
+        HRESULT hr = pInterface2->CreateInstanceLic(nullptr,
                                             nullptr,
                                             ADOS::IID_ADOCOMMAND_21,
                                             ADOS::GetKeyStr().asBSTR(),
                                             
reinterpret_cast<void**>(&pCommand));
 
         if( !FAILED( hr ) )
-        {
-            operator=(pCommand);
-            pCommand->Release();
-        }
-
-        pInterface2->Release();
+            pInterface = std::move(pCommand);
     }
 }
 
@@ -454,12 +428,9 @@ sal_Int32 WpADOError::GetNativeError() const
 WpADOProperties WpADOField::get_Properties()
 {
     assert(pInterface);
-    ADOProperties* pProps = nullptr;
+    WpADOProperties pProps;
     pInterface->get_Properties(&pProps);
-    WpADOProperties aProps;
-
-    aProps.setWithOutAddRef(pProps);
-    return aProps;
+    return pProps;
 }
 
 sal_Int32 WpADOField::GetActualSize() const
@@ -677,30 +648,18 @@ bool WpADOProperty::PutAttributes(sal_Int32 _nDefSize)
 }
  void WpADORecordset::Create()
 {
-    IClassFactory2* pInterface2 = nullptr;
-    HRESULT hr = CoGetClassObject( ADOS::CLSID_ADORECORDSET_21,
-                          CLSCTX_INPROC_SERVER,
-                          nullptr,
-                          IID_IClassFactory2,
-                          reinterpret_cast<void**>(&pInterface2) );
-
-    if( !FAILED( hr ) )
+    sal::systools::COMReference<IClassFactory2> pInterface2;
+    if (!FAILED(pInterface2.TryCoGetClassObject(ADOS::CLSID_ADORECORDSET_21, 
CLSCTX_INPROC_SERVER)))
     {
-        ADORecordset *pRec = nullptr;
-        IUnknown *pOuter = nullptr;
-        hr = pInterface2->CreateInstanceLic(  pOuter,
+        sal::systools::COMReference<ADORecordset> pRec;
+        HRESULT hr = pInterface2->CreateInstanceLic(nullptr,
                                             nullptr,
                                             ADOS::IID_ADORECORDSET_21,
                                             ADOS::GetKeyStr().asBSTR(),
                                             reinterpret_cast<void**>(&pRec));
 
         if( !FAILED( hr ) )
-        {
-            operator=(pRec);
-            pRec->Release();
-        }
-
-        pInterface2->Release();
+            pInterface = std::move(pRec);
     }
 }
 
@@ -804,11 +763,9 @@ bool WpADORecordset::SetBookmark(const OLEVariant &pSafeAr)
 WpADOFields WpADORecordset::GetFields() const
 {
     assert(pInterface);
-    ADOFields* pFields=nullptr;
+    WpADOFields pFields;
     pInterface->get_Fields(&pFields);
-    WpADOFields aFields;
-    aFields.setWithOutAddRef(pFields);
-    return aFields;
+    return pFields;
 }
 
 
@@ -861,11 +818,9 @@ bool WpADORecordset::CancelUpdate()
 WpADOProperties WpADORecordset::get_Properties() const
 {
     assert(pInterface);
-    ADOProperties* pProps=nullptr;
+    WpADOProperties pProps;
     pInterface->get_Properties(&pProps);
-    WpADOProperties aProps;
-    aProps.setWithOutAddRef(pProps);
-    return aProps;
+    return pProps;
 }
 
 bool WpADORecordset::NextRecordset(OLEVariant& RecordsAffected,ADORecordset** 
ppiRset)
@@ -1127,12 +1082,9 @@ bool WpADOColumn::put_Attributes(const 
ColumnAttributesEnum& _eNum)
 WpADOProperties WpADOColumn::get_Properties() const
 {
     assert(pInterface);
-    ADOProperties* pProps = nullptr;
+    WpADOProperties pProps;
     pInterface->get_Properties(&pProps);
-    WpADOProperties aProps;
-
-    aProps.setWithOutAddRef(pProps);
-    return aProps;
+    return pProps;
 }
 
 OUString WpADOKey::get_Name() const
@@ -1210,11 +1162,9 @@ void WpADOKey::put_UpdateRule(const RuleEnum& _eNum)
 WpADOColumns WpADOKey::get_Columns() const
 {
     assert(pInterface);
-    ADOColumns* pCols = nullptr;
+    WpADOColumns pCols;
     pInterface->get_Columns(&pCols);
-    WpADOColumns aCols;
-    aCols.setWithOutAddRef(pCols);
-    return aCols;
+    return pCols;
 }
 
 OUString WpADOIndex::get_Name() const
@@ -1277,11 +1227,9 @@ void WpADOIndex::put_PrimaryKey(bool _b)
 WpADOColumns WpADOIndex::get_Columns() const
 {
     assert(pInterface);
-    ADOColumns* pCols = nullptr;
+    WpADOColumns pCols;
     pInterface->get_Columns(&pCols);
-    WpADOColumns aCols;
-    aCols.setWithOutAddRef(pCols);
-    return aCols;
+    return pCols;
 }
 
 void WpADOCatalog::putref_ActiveConnection(IDispatch* pCon)
@@ -1293,41 +1241,33 @@ void WpADOCatalog::putref_ActiveConnection(IDispatch* 
pCon)
 WpADOTables WpADOCatalog::get_Tables()
 {
     assert(pInterface);
-    ADOTables* pRet = nullptr;
+    WpADOTables pRet;
     pInterface->get_Tables(&pRet);
-    WpADOTables aRet;
-    aRet.setWithOutAddRef(pRet);
-    return aRet;
+    return pRet;
 }
 
 WpADOViews WpADOCatalog::get_Views()
 {
     assert(pInterface);
-    ADOViews* pRet = nullptr;
+    WpADOViews pRet;
     pInterface->get_Views(&pRet);
-    WpADOViews aRet;
-    aRet.setWithOutAddRef(pRet);
-    return aRet;
+    return pRet;
 }
 
 WpADOGroups WpADOCatalog::get_Groups()
 {
     assert(pInterface);
-    ADOGroups* pRet = nullptr;
+    WpADOGroups pRet;
     pInterface->get_Groups(&pRet);
-    WpADOGroups aRet;
-    aRet.setWithOutAddRef(pRet);
-    return aRet;
+    return pRet;
 }
 
 WpADOUsers WpADOCatalog::get_Users()
 {
     assert(pInterface);
-    ADOUsers* pRet = nullptr;
+    WpADOUsers pRet;
     pInterface->get_Users(&pRet);
-    WpADOUsers aRet;
-    aRet.setWithOutAddRef(pRet);
-    return aRet;
+    return pRet;
 }
 
 ADOProcedures* WpADOCatalog::get_Procedures()
@@ -1364,51 +1304,41 @@ OUString WpADOTable::get_Type() const
 WpADOColumns WpADOTable::get_Columns() const
 {
     assert(pInterface);
-    ADOColumns* pCols = nullptr;
+    WpADOColumns pCols;
     pInterface->get_Columns(&pCols);
-    WpADOColumns aCols;
-    aCols.setWithOutAddRef(pCols);
-    return aCols;
+    return pCols;
 }
 
 WpADOIndexes WpADOTable::get_Indexes() const
 {
     assert(pInterface);
-    ADOIndexes* pCols = nullptr;
-    pInterface->get_Indexes(&pCols);
-    WpADOIndexes aRet;
-    aRet.setWithOutAddRef(pCols);
-    return aRet;
+    WpADOIndexes pRet;
+    pInterface->get_Indexes(&pRet);
+    return pRet;
 }
 
 WpADOKeys WpADOTable::get_Keys() const
 {
     assert(pInterface);
-    ADOKeys* pCols = nullptr;
-    pInterface->get_Keys(&pCols);
-    WpADOKeys aRet;
-    aRet.setWithOutAddRef(pCols);
-    return aRet;
+    WpADOKeys pRet;
+    pInterface->get_Keys(&pRet);
+    return pRet;
 }
 
 WpADOCatalog WpADOTable::get_ParentCatalog() const
 {
     assert(pInterface);
-    ADOCatalog* pCat = nullptr;
+    WpADOCatalog pCat;
     pInterface->get_ParentCatalog(&pCat);
-    WpADOCatalog aRet;
-    aRet.setWithOutAddRef(pCat);
-    return aRet;
+    return pCat;
 }
 
 WpADOProperties WpADOTable::get_Properties() const
 {
     assert(pInterface);
-    ADOProperties* pProps = nullptr;
+    WpADOProperties pProps;
     pInterface->get_Properties(&pProps);
-    WpADOProperties aProps;
-    aProps.setWithOutAddRef(pProps);
-    return aProps;
+    return pProps;
 }
 
 OUString WpADOView::get_Name() const
@@ -1468,11 +1398,9 @@ bool WpADOGroup::SetPermissions(
 
 WpADOUsers WpADOGroup::get_Users( )
 {
-    ADOUsers* pRet = nullptr;
+    WpADOUsers pRet;
     pInterface->get_Users( &pRet);
-    WpADOUsers aRet;
-    aRet.setWithOutAddRef(pRet);
-    return aRet;
+    return pRet;
 }
 
 OUString WpADOUser::get_Name() const
@@ -1498,11 +1426,9 @@ bool WpADOUser::ChangePassword(std::u16string_view 
_rPwd,std::u16string_view _rN
 
 WpADOGroups WpADOUser::get_Groups()
 {
-    ADOGroups* pRet = nullptr;
+    WpADOGroups pRet;
     pInterface->get_Groups(&pRet);
-    WpADOGroups aRet;
-    aRet.setWithOutAddRef(pRet);
-    return aRet;
+    return pRet;
 }
 
 RightsEnum WpADOUser::GetPermissions(
@@ -1527,73 +1453,6 @@ bool WpADOUser::SetPermissions(
     return 
SUCCEEDED(pInterface->SetPermissions(Name,ObjectType,Action,Rights,adInheritNone,ObjectTypeId));
 }
 
-WpBase::WpBase() : pIUnknown(nullptr)
-{
-}
-WpBase::WpBase(IDispatch* pInt)
-    :pIUnknown(pInt)
-{
-    if (pIUnknown)
-    {
-        pIUnknown->AddRef();
-    }
-}
-
-WpBase::WpBase(const WpBase& aWrapper)
-    :pIUnknown(aWrapper.pIUnknown)
-{
-    if (pIUnknown)
-        pIUnknown->AddRef();
-}
-
-//inline
-WpBase& WpBase::operator=(const WpBase& rhs)
-{
-    operator=(rhs.pIUnknown);
-    return *this;
-};
-
-WpBase& WpBase::operator=(IDispatch* rhs)
-{
-    if (pIUnknown != rhs)
-    {
-        if (pIUnknown)
-            pIUnknown->Release();
-        pIUnknown = rhs;
-        if (pIUnknown)
-            pIUnknown->AddRef();
-    }
-    return *this;
-}
-
-WpBase::~WpBase()
-{
-    if (pIUnknown)
-    {
-        pIUnknown->Release();
-        pIUnknown = nullptr;
-    }
-}
-
-void WpBase::clear()
-{
-    if (pIUnknown)
-    {
-        pIUnknown->Release();
-        pIUnknown = nullptr;
-    }
-}
-
-
-bool WpBase::IsValid() const
-{
-    return pIUnknown != nullptr;
-}
-WpBase::operator IDispatch*()
-{
-    return pIUnknown;
-}
-
 ADORecordset* WpADOConnection::getExportedKeys( const css::uno::Any& catalog, 
const OUString& schema, std::u16string_view table )
 {
     // Create elements used in the array
@@ -2128,11 +1987,6 @@ void WpADOTable::putref_ParentCatalog(/* [in] */ 
_ADOCatalog __RPC_FAR *ppvObjec
     SAL_WARN_IF(!bRet, "connectivity.ado", "Could not set ParentCatalog!");
 }
 
-void WpBase::setIDispatch(IDispatch* _pIUnknown)
-{
-    pIUnknown = _pIUnknown;
-}
-
 void OTools::putValue(const WpADOProperties& _rProps,const OLEVariant 
&_aPosition,const OLEVariant &_aValVar)
 {
     SAL_WARN_IF(!_rProps.IsValid(), "connectivity.ado", "Properties are not 
valid!");
diff --git a/connectivity/source/drivers/ado/adoimp.cxx 
b/connectivity/source/drivers/ado/adoimp.cxx
index 0b4936e734f2..bd01f36fc684 100644
--- a/connectivity/source/drivers/ado/adoimp.cxx
+++ b/connectivity/source/drivers/ado/adoimp.cxx
@@ -310,9 +310,8 @@ WpADOField ADOS::getField(ADORecordset* 
_pRecordSet,sal_Int32 _nColumnIndex)
     if ( !_pRecordSet )
         return WpADOField();
 
-    ADOFields* pFields  = nullptr;
-    _pRecordSet->get_Fields(&pFields);
-    WpOLEAppendCollection<ADOFields, ADOField, WpADOField>  aFields(pFields);
+    WpOLEAppendCollection<ADOFields, WpADOField> aFields;
+    _pRecordSet->get_Fields(&aFields);
     if(_nColumnIndex <= 0 || _nColumnIndex > aFields.GetItemCount())
         ::dbtools::throwInvalidIndexException(nullptr);
     WpADOField aField(aFields.GetItem(_nColumnIndex-1));
diff --git a/connectivity/source/inc/ado/AConnection.hxx 
b/connectivity/source/inc/ado/AConnection.hxx
index 0a2b08875598..3e7581ec6d03 100644
--- a/connectivity/source/inc/ado/AConnection.hxx
+++ b/connectivity/source/inc/ado/AConnection.hxx
@@ -56,7 +56,7 @@ namespace connectivity::ado
             css::uno::WeakReference< css::sdbcx::XTablesSupplier>      
m_xCatalog;
             ODriver*                    m_pDriver;
         private:
-            WpADOConnection*            m_pAdoConnection;
+            WpADOConnection             m_aAdoConnection;
             OCatalog*                   m_pCatalog;
             sal_Int32                   m_nEngineType;
             bool                        m_bClosed;
@@ -106,7 +106,7 @@ namespace connectivity::ado
             virtual css::uno::Any SAL_CALL getWarnings(  ) override;
             virtual void SAL_CALL clearWarnings(  ) override;
 
-            WpADOConnection* getConnection() { return m_pAdoConnection; }
+            WpADOConnection& getConnection() { return m_aAdoConnection; }
             void setCatalog(const css::uno::WeakReference< 
css::sdbcx::XTablesSupplier>& _xCat) { m_xCatalog = _xCat; }
             void setCatalog(OCatalog* _pCatalog) { m_pCatalog = _pCatalog; }
 
diff --git a/connectivity/source/inc/ado/ADatabaseMetaData.hxx 
b/connectivity/source/inc/ado/ADatabaseMetaData.hxx
index 65dfad6d21d1..1661ca44181c 100644
--- a/connectivity/source/inc/ado/ADatabaseMetaData.hxx
+++ b/connectivity/source/inc/ado/ADatabaseMetaData.hxx
@@ -40,7 +40,7 @@ namespace connectivity::ado
             };
 
             std::map<sal_uInt32,LiteralInfo>  m_aLiteralInfo;
-            WpADOConnection*                    m_pADOConnection;
+            WpADOConnection&                    m_rADOConnection;
             OConnection*                        m_pConnection;
 
             void fillLiterals();
diff --git a/connectivity/source/inc/ado/Aolewrap.hxx 
b/connectivity/source/inc/ado/Aolewrap.hxx
index 767c50372254..9d402fcf21b1 100644
--- a/connectivity/source/inc/ado/Aolewrap.hxx
+++ b/connectivity/source/inc/ado/Aolewrap.hxx
@@ -20,6 +20,8 @@
 
 #include <osl/diagnose.h>
 #include <osl/thread.h>
+#include <systools/win32/comtools.hxx>
+
 #include <map>
 #include <vector>
 
@@ -31,101 +33,59 @@ namespace rtl
 }
 namespace connectivity::ado
 {
-        class WpBase
-        {
-        protected:
-            IDispatch* pIUnknown;
-
-            void setIDispatch(IDispatch* _pIUnknown);
-        public:
-            WpBase();
-            WpBase(IDispatch* pInt);
-            //inline
-            WpBase& operator=(const WpBase& rhs);
-            WpBase& operator=(IDispatch* rhs);
-            WpBase(const WpBase& aWrapper);
-            virtual ~WpBase();
-            void clear();
-
-
-            bool IsValid() const;
-            operator IDispatch*();
-
-        };
-
         // Template class WpOLEBase<class T>
         // ==================================
         //
         // Objects of this class contain a pointer to an interface of the type 
T.
-        // The ctors and operator= make sure, that AddRef() and Release() are 
being
-        // called adhering to COM conventions.
-        // An object can also hold no pointer (null pointer), calling 
IsValid() then
-        // returns false.
-        //
-        // In order to do efficient pass-by-value, this class (as all derived 
classes)
-        // is a thin wrapper class, avoiding virtual methods and inlining.
 
-        template<class T> class WpOLEBase : public WpBase
+        template<class T> class WpOLEBase
         {
         protected:
-            T* pInterface;
+            sal::systools::COMReference<T> pInterface;
 
         public:
-            WpOLEBase(T* pInt = nullptr) : WpBase(pInt),pInterface(pInt){}
+            WpOLEBase(T* pInt = nullptr) : pInterface(pInt){}
 
+            WpOLEBase(const WpOLEBase<T>& aWrapper)
+                : pInterface( aWrapper.pInterface )
+            {
+            }
 
             //inline
             WpOLEBase<T>& operator=(const WpOLEBase<T>& rhs)
             {
-                WpBase::operator=(rhs);
                 pInterface = rhs.pInterface;
                 return *this;
             };
 
-            WpOLEBase<T>& operator=(T* rhs)
-            {
-                WpBase::operator=(rhs);
-                pInterface = rhs.pInterface;
-                return *this;
-            }
-
-            WpOLEBase(const WpOLEBase<T>& aWrapper)
-                : WpBase( aWrapper )
-                , pInterface( aWrapper.pInterface )
-            {
-            }
-
-            operator T*() const { return pInterface; }
-            void setWithOutAddRef(T* _pInterface)
-            {
-                pInterface = _pInterface;
-                WpBase::setIDispatch(_pInterface);
-            }
+            operator T*() const { return pInterface.get(); }
+            T** operator&() { return &pInterface; }
+            bool IsValid() const { return pInterface.is(); }
+            void set(T* p) { pInterface = p; }
+            void clear() { pInterface.clear(); }
         };
 
 
-        // Template class WpOLECollection<class Ts, class T, class WrapT>
+        // Template class WpOLECollection<class Ts, class WrapT>
         // ===============================================================
         //
         // This class (derived from WpOLEBase<Ts>), abstracts away the 
properties
         // common to DAO collections:
         //
         // They are accessed via an interface Ts (e.g. DAOFields) and can 
return
-        // Items of the Type T (actually: with the interface T, e.g. DAOField)
-        // via get_Item (here GetItem).
+        // Items of the type wrapped by WrapT (actually: with the interface, 
e.g.
+        // DAOField) via get_Item (here GetItem).
         //
-        // This wrapper class does not expose an interface T, however,
-        // it exposes an object of the class WrapT. This must allow a 
construction
-        // by T, preferably it is derived from WpOLEBase<T>.
+        // This wrapper class exposes an object of the class WrapT.
 
-        template<class Ts, class T, class WrapT> class WpOLECollection : 
public WpOLEBase<Ts>
+        template<class Ts, class WrapT> class WpOLECollection : public 
WpOLEBase<Ts>
         {
         public:
             using WpOLEBase<Ts>::pInterface;
             using WpOLEBase<Ts>::IsValid;
             // Ctors, operator=
             // They only call the superclass
-            WpOLECollection(Ts* pInt=nullptr):WpOLEBase<Ts>(pInt){}
+            WpOLECollection() = default;
             WpOLECollection(const WpOLECollection& rhs) : WpOLEBase<Ts>(rhs) {}
             WpOLECollection& operator=(const WpOLECollection& rhs)
                 {WpOLEBase<Ts>::operator=(rhs); return *this;};
@@ -142,35 +102,28 @@ namespace connectivity::ado
             WrapT GetItem(sal_Int32 index) const
             {
                 OSL_ENSURE(index >= 0 && index<GetItemCount(),"Wrong index for 
field!");
-                T* pT = NULL;
-                WrapT aRet(NULL);
-                if(SUCCEEDED(pInterface->get_Item(OLEVariant(index), &pT)))
-                    aRet.setWithOutAddRef(pT);
+                WrapT aRet;
+                pInterface->get_Item(OLEVariant(index), &aRet);
                 return aRet;
             }
 
             WrapT GetItem(const OLEVariant& index) const
             {
-                T* pT = NULL;
-                WrapT aRet(NULL);
-                if(SUCCEEDED(pInterface->get_Item(index, &pT)))
-                    aRet.setWithOutAddRef(pT);
+                WrapT aRet;
+                pInterface->get_Item(index, &aRet);
                 return aRet;
             }
 
             WrapT GetItem(const OUString& sStr) const
             {
-                WrapT aRet(NULL);
-                T* pT = NULL;
-                if (FAILED(pInterface->get_Item(OLEVariant(sStr), &pT)))
+                WrapT aRet;
+                if (FAILED(pInterface->get_Item(OLEVariant(sStr), &aRet)))
                 {
 #if OSL_DEBUG_LEVEL > 0
                     OString sTemp("Unknown Item: " + 
OString(sStr.getStr(),sStr.getLength(),osl_getThreadTextEncoding()));
                     OSL_FAIL(sTemp.getStr());
 #endif
                 }
-                else
-                    aRet.setWithOutAddRef(pT);
                 return aRet;
             }
             void fillElementNames(::std::vector< OUString>& _rVector)
@@ -190,23 +143,23 @@ namespace connectivity::ado
             }
         };
 
-        template<class Ts, class T, class WrapT> class WpOLEAppendCollection:
-                public WpOLECollection<Ts,T,WrapT>
+        template<class Ts, class WrapT> class WpOLEAppendCollection:
+                public WpOLECollection<Ts,WrapT>
         {
 
         public:
             // Ctors, operator=
             // They only call the superclass
             using WpOLEBase<Ts>::pInterface;
-            WpOLEAppendCollection(Ts* 
pInt=nullptr):WpOLECollection<Ts,T,WrapT>(pInt){}
-            WpOLEAppendCollection(const WpOLEAppendCollection& rhs) : 
WpOLECollection<Ts, T, WrapT>(rhs) {}
+            WpOLEAppendCollection() = default;
+            WpOLEAppendCollection(const WpOLEAppendCollection& rhs) : 
WpOLECollection<Ts, WrapT>(rhs) {}
             WpOLEAppendCollection& operator=(const WpOLEAppendCollection& rhs)
                 {WpOLEBase<Ts>::operator=(rhs); return *this;};
 
 
             bool Append(const WrapT& aWrapT)
             {
-                return 
SUCCEEDED(pInterface->Append(OLEVariant(static_cast<T*>(aWrapT))));
+                return SUCCEEDED(pInterface->Append(OLEVariant(aWrapT)));
             };
 
             bool Delete(const OUString& sName)
diff --git a/connectivity/source/inc/ado/Awrapado.hxx 
b/connectivity/source/inc/ado/Awrapado.hxx
index efb2be2aa3bd..8bc8cffb2ecd 100644
--- a/connectivity/source/inc/ado/Awrapado.hxx
+++ b/connectivity/source/inc/ado/Awrapado.hxx
@@ -42,16 +42,15 @@ namespace connectivity::ado
         class WpADOError;
         class WpADOProperty;
 
-        typedef WpOLEAppendCollection<  ADOFields,      ADOField,       
WpADOField>         WpADOFields;
-        typedef WpOLECollection<        ADOProperties,  ADOProperty,    
WpADOProperty>      WpADOProperties;
+        typedef WpOLEAppendCollection<  ADOFields,      WpADOField>         
WpADOFields;
+        typedef WpOLECollection<        ADOProperties,  WpADOProperty>      
WpADOProperties;
 
 
         class WpADOConnection : public WpOLEBase<ADOConnection>
         {
-            friend class WpADOCommand;
         public:
 
-            WpADOConnection(ADOConnection* pInt)    :   
WpOLEBase<ADOConnection>(pInt){}
+            WpADOConnection() = default;
 
             WpADOConnection(const WpADOConnection& rhs) : 
WpOLEBase<ADOConnection>(rhs) {}
 
@@ -140,11 +139,9 @@ namespace connectivity::ado
         class WpADOCommand : public WpOLEBase<ADOCommand>
         {
         public:
-            WpADOCommand(){}
+            WpADOCommand() = default;
             // Ctors, operator=
             // They only call the superclass
-            WpADOCommand(ADOCommand* pInt)  :   WpOLEBase<ADOCommand>(pInt){}
-
             WpADOCommand(const WpADOCommand& rhs) : WpOLEBase<ADOCommand>(rhs) 
{}
 
              WpADOCommand& operator=(const WpADOCommand& rhs)
@@ -152,7 +149,7 @@ namespace connectivity::ado
                 WpOLEBase<ADOCommand>::operator=(rhs); return *this;}
 
 
-            bool putref_ActiveConnection( WpADOConnection *pCon);
+            bool putref_ActiveConnection(const WpADOConnection& rCon);
 
             void put_ActiveConnection(/* [in] */ const OLEVariant& vConn);
              void Create();
@@ -181,7 +178,7 @@ namespace connectivity::ado
 
             // Ctors, operator=
             // They only call the superclass
-            WpADOError(ADOError* pInt):WpOLEBase<ADOError>(pInt){}
+            WpADOError() = default;
 
             WpADOError(const WpADOError& rhs) : WpOLEBase<ADOError>(rhs) {}
 
@@ -204,7 +201,7 @@ namespace connectivity::ado
 
             // Ctors, operator=
             // They only call the superclass
-            WpADOField(ADOField* pInt=nullptr):WpOLEBase<ADOField>(pInt){}
+            WpADOField() = default;
             WpADOField(const WpADOField& rhs) : WpOLEBase<ADOField>(rhs) {}
 
              WpADOField& operator=(const WpADOField& rhs)
@@ -250,7 +247,7 @@ namespace connectivity::ado
         public:
             // Ctors, operator=
             // They only call the superclass
-            WpADOProperty(ADOProperty* 
pInt=nullptr):WpOLEBase<ADOProperty>(pInt){}
+            WpADOProperty() = default;
             WpADOProperty(const WpADOProperty& rhs) : 
WpOLEBase<ADOProperty>(rhs) {}
              WpADOProperty& operator=(const WpADOProperty& rhs)
                 {WpOLEBase<ADOProperty>::operator=(rhs); return *this;}
@@ -272,7 +269,7 @@ namespace connectivity::ado
         public:
             // Ctors, operator=
             // They only call the superclass
-            WpADORecordset(ADORecordset* 
pInt=nullptr):WpOLEBase<ADORecordset>(pInt){}
+            WpADORecordset() = default;
             WpADORecordset(const WpADORecordset& rhs) : 
WpOLEBase<ADORecordset>() {operator=(rhs);}
              WpADORecordset& operator=(const WpADORecordset& rhs)
             {
@@ -332,7 +329,7 @@ namespace connectivity::ado
         public:
             // Ctors, operator=
             // They only call the superclass
-            WpADOParameter(ADOParameter* pInt):WpOLEBase<ADOParameter>(pInt){}
+            WpADOParameter() = default;
             WpADOParameter(const WpADOParameter& 
rhs):WpOLEBase<ADOParameter>(rhs){}
              WpADOParameter& operator=(const WpADOParameter& rhs)
                 {WpOLEBase<ADOParameter>::operator=(rhs); return *this;}
diff --git a/connectivity/source/inc/ado/Awrapadox.hxx 
b/connectivity/source/inc/ado/Awrapadox.hxx
index 6bda5b4878d8..ba91422a1d09 100644
--- a/connectivity/source/inc/ado/Awrapadox.hxx
+++ b/connectivity/source/inc/ado/Awrapadox.hxx
@@ -89,7 +89,7 @@ namespace connectivity::ado
         class WpADOGroup : public WpOLEBase<ADOGroup>
         {
         public:
-            WpADOGroup(ADOGroup* pInt=nullptr) :   WpOLEBase<ADOGroup>(pInt){}
+            WpADOGroup() = default;
             WpADOGroup(const WpADOGroup& rhs) : WpOLEBase<ADOGroup>(rhs) {}
 
             WpADOGroup& operator=(const WpADOGroup& rhs)
@@ -113,7 +113,7 @@ namespace connectivity::ado
         class WpADOUser : public WpOLEBase<_ADOUser>
         {
         public:
-            WpADOUser(_ADOUser* pInt=nullptr)  :   WpOLEBase<_ADOUser>(pInt){}
+            WpADOUser() = default;
             WpADOUser(const WpADOUser& rhs) : WpOLEBase<_ADOUser>(rhs) {}
 
             WpADOUser& operator=(const WpADOUser& rhs)
diff --git a/connectivity/source/inc/ado/WrapColumn.hxx 
b/connectivity/source/inc/ado/WrapColumn.hxx
index fa4aa7f5edba..f1b73585fba9 100644
--- a/connectivity/source/inc/ado/WrapColumn.hxx
+++ b/connectivity/source/inc/ado/WrapColumn.hxx
@@ -31,7 +31,7 @@ namespace connectivity::ado
         class WpADOColumn : public WpOLEBase<_ADOColumn>
         {
         public:
-            WpADOColumn(_ADOColumn* pInt=nullptr)  :   
WpOLEBase<_ADOColumn>(pInt){}
+            WpADOColumn() = default;
             WpADOColumn(const WpADOColumn& rhs) : WpOLEBase<_ADOColumn>(rhs) {}
 
             void Create();
diff --git a/connectivity/source/inc/ado/WrapIndex.hxx 
b/connectivity/source/inc/ado/WrapIndex.hxx
index 04b965449fb1..4444bb340ae5 100644
--- a/connectivity/source/inc/ado/WrapIndex.hxx
+++ b/connectivity/source/inc/ado/WrapIndex.hxx
@@ -29,7 +29,7 @@ namespace connectivity::ado
         class WpADOIndex : public WpOLEBase<_ADOIndex>
         {
         public:
-            WpADOIndex(_ADOIndex* pInt=nullptr)    :   
WpOLEBase<_ADOIndex>(pInt){}
+            WpADOIndex() = default;
             WpADOIndex(const WpADOIndex& rhs) : WpOLEBase<_ADOIndex>(rhs) {}
 
             WpADOIndex& operator=(const WpADOIndex& rhs)
diff --git a/connectivity/source/inc/ado/WrapKey.hxx 
b/connectivity/source/inc/ado/WrapKey.hxx
index 6b4ed08101e1..1f984445b8ae 100644
--- a/connectivity/source/inc/ado/WrapKey.hxx
+++ b/connectivity/source/inc/ado/WrapKey.hxx
@@ -29,7 +29,7 @@ namespace connectivity::ado
         class WpADOKey : public WpOLEBase<ADOKey>
         {
         public:
-            WpADOKey(ADOKey* pInt=nullptr) :   WpOLEBase<ADOKey>(pInt){}
+            WpADOKey() = default;
             WpADOKey(const WpADOKey& rhs) : WpOLEBase<ADOKey>(rhs) {}
 
             WpADOKey& operator=(const WpADOKey& rhs)
diff --git a/connectivity/source/inc/ado/WrapTable.hxx 
b/connectivity/source/inc/ado/WrapTable.hxx
index 38820944c264..dc06dbc03a8e 100644
--- a/connectivity/source/inc/ado/WrapTable.hxx
+++ b/connectivity/source/inc/ado/WrapTable.hxx
@@ -31,7 +31,7 @@ namespace connectivity::ado
         class WpADOTable : public WpOLEBase<_ADOTable>
         {
         public:
-            WpADOTable(_ADOTable* pInt=nullptr)    :   
WpOLEBase<_ADOTable>(pInt){}
+            WpADOTable() = default;
             WpADOTable(const WpADOTable& rhs) : WpOLEBase<_ADOTable>(rhs) {}
 
             WpADOTable& operator=(const WpADOTable& rhs)
@@ -51,7 +51,7 @@ namespace connectivity::ado
         };
 
 
-        typedef WpOLEAppendCollection<ADOTables,    _ADOTable,  WpADOTable>    
 WpADOTables;
+        typedef WpOLEAppendCollection<ADOTables, WpADOTable>     WpADOTables;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/inc/ado/WrapTypeDefs.hxx 
b/connectivity/source/inc/ado/WrapTypeDefs.hxx
index 3f4e82d85269..91bea8453480 100644
--- a/connectivity/source/inc/ado/WrapTypeDefs.hxx
+++ b/connectivity/source/inc/ado/WrapTypeDefs.hxx
@@ -29,13 +29,13 @@ namespace connectivity::ado
         class WpADOView;
         class WpADOUser;
 
-        typedef WpOLEAppendCollection<ADOTables,    _ADOTable,  WpADOTable>    
 WpADOTables;
-        typedef WpOLEAppendCollection<ADOKeys,      ADOKey,     WpADOKey>      
 WpADOKeys;
-        typedef WpOLEAppendCollection<ADOIndexes,   _ADOIndex,  WpADOIndex>    
 WpADOIndexes;
-        typedef WpOLEAppendCollection<ADOColumns,   _ADOColumn, WpADOColumn>   
 WpADOColumns;
-        typedef WpOLEAppendCollection<ADOGroups,    ADOGroup,   WpADOGroup>    
 WpADOGroups;
-        typedef WpOLEAppendCollection<ADOViews,     ADOView,    WpADOView>     
 WpADOViews;
-        typedef WpOLEAppendCollection<ADOUsers,     _ADOUser,   WpADOUser>     
 WpADOUsers;
+        typedef WpOLEAppendCollection<ADOTables,    WpADOTable>     
WpADOTables;
+        typedef WpOLEAppendCollection<ADOKeys,      WpADOKey>       WpADOKeys;
+        typedef WpOLEAppendCollection<ADOIndexes,   WpADOIndex>     
WpADOIndexes;
+        typedef WpOLEAppendCollection<ADOColumns,   WpADOColumn>    
WpADOColumns;
+        typedef WpOLEAppendCollection<ADOGroups,    WpADOGroup>     
WpADOGroups;
+        typedef WpOLEAppendCollection<ADOViews,     WpADOView>      WpADOViews;
+        typedef WpOLEAppendCollection<ADOUsers,     WpADOUser>      WpADOUsers;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/inc/ado/adoimp.hxx 
b/connectivity/source/inc/ado/adoimp.hxx
index 3b5d9f4d64e1..58e268d9c68a 100644
--- a/connectivity/source/inc/ado/adoimp.hxx
+++ b/connectivity/source/inc/ado/adoimp.hxx
@@ -95,7 +95,7 @@ namespace connectivity::ado
         if(aProp.IsValid())                                         \
             aVar = aProp.GetValue();                                \
         else                                                        \
-            ADOS::ThrowException(*m_pADOConnection,*this);
+            ADOS::ThrowException(m_rADOConnection,*this);
 
 
 
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_; }

Reply via email to