basctl/source/basicide/unomodel.cxx              |    2 
 basic/source/basmgr/basicmanagerrepository.cxx   |    2 
 basic/source/basmgr/basmgr.cxx                   |   18 
 basic/source/uno/scriptcont.cxx                  |    2 
 editeng/source/misc/svxacorr.cxx                 |   34 -
 embeddedobj/source/inc/oleembobj.hxx             |   28 -
 embeddedobj/source/msole/olecomponent.cxx        |  529 +++++++++--------------
 embeddedobj/source/msole/olecomponent.hxx        |   12 
 embeddedobj/source/msole/oleembed.cxx            |   28 -
 embeddedobj/source/msole/olepersist.cxx          |   19 
 embeddedobj/source/msole/olevisual.cxx           |    7 
 filter/source/msfilter/msdffimp.cxx              |   30 -
 filter/source/msfilter/msoleexp.cxx              |    8 
 filter/source/msfilter/rtfutil.cxx               |    6 
 filter/source/msfilter/svdfppt.cxx               |   22 
 filter/source/msfilter/svxmsbas2.cxx             |    8 
 fpicker/source/win32/VistaFilePickerImpl.cxx     |    1 
 include/editeng/svxacorr.hxx                     |    5 
 include/filter/msfilter/msdffimp.hxx             |    6 
 include/filter/msfilter/svdfppt.hxx              |    4 
 include/filter/msfilter/svxmsbas.hxx             |    2 
 include/oox/ole/olehelper.hxx                    |    8 
 include/sfx2/event.hxx                           |    9 
 include/sfx2/objsh.hxx                           |   13 
 include/sot/object.hxx                           |    6 
 include/sot/storage.hxx                          |    6 
 include/svx/gallerybinaryengine.hxx              |    4 
 include/vcl/scheduler.hxx                        |    7 
 include/vcl/svapp.hxx                            |   12 
 oox/source/ole/olehelper.cxx                     |   18 
 oox/source/ole/vbaexport.cxx                     |   12 
 sc/inc/global.hxx                                |    4 
 sc/inc/rangelst.hxx                              |    1 
 sc/inc/tablink.hxx                               |    7 
 sc/source/core/data/global.cxx                   |    2 
 sc/source/filter/excel/excel.cxx                 |   32 -
 sc/source/filter/excel/excimp8.cxx               |    6 
 sc/source/filter/excel/expop2.cxx                |    4 
 sc/source/filter/excel/xepivot.cxx               |    4 
 sc/source/filter/excel/xeroot.cxx                |    2 
 sc/source/filter/excel/xestream.cxx              |    4 
 sc/source/filter/excel/xiescher.cxx              |    2 
 sc/source/filter/excel/xipivot.cxx               |    4 
 sc/source/filter/excel/xiroot.cxx                |    2 
 sc/source/filter/excel/xlroot.cxx                |   12 
 sc/source/filter/ftools/ftools.cxx               |   16 
 sc/source/filter/inc/XclImpChangeTrack.hxx       |    2 
 sc/source/filter/inc/ftools.hxx                  |   10 
 sc/source/filter/inc/xcl97esc.hxx                |    2 
 sc/source/filter/inc/xeroot.hxx                  |    2 
 sc/source/filter/inc/xiescher.hxx                |    2 
 sc/source/filter/inc/xiroot.hxx                  |    2 
 sc/source/filter/inc/xlroot.hxx                  |   16 
 sc/source/filter/xcl97/XclExpChangeTrack.cxx     |    4 
 sc/source/filter/xcl97/XclImpChangeTrack.cxx     |    2 
 sc/source/filter/xcl97/xcl97rec.cxx              |    2 
 sc/source/ui/app/drwtrans.cxx                    |   15 
 sc/source/ui/app/seltrans.cxx                    |    6 
 sc/source/ui/app/transobj.cxx                    |   19 
 sc/source/ui/docshell/arealink.cxx               |    5 
 sc/source/ui/docshell/docsh4.cxx                 |    3 
 sc/source/ui/docshell/externalrefmgr.cxx         |   15 
 sc/source/ui/docshell/tablink.cxx                |   18 
 sc/source/ui/inc/docsh.hxx                       |    2 
 sc/source/ui/inc/drwtrans.hxx                    |    2 
 sc/source/ui/inc/instbdlg.hxx                    |    5 
 sc/source/ui/inc/linkarea.hxx                    |    3 
 sc/source/ui/inc/transobj.hxx                    |    2 
 sc/source/ui/miscdlgs/instbdlg.cxx               |    5 
 sc/source/ui/miscdlgs/linkarea.cxx               |    9 
 sc/source/ui/unoobj/exceldetect.cxx              |    2 
 sc/source/ui/unoobj/unodoc.cxx                   |    2 
 sc/source/ui/view/drawvie4.cxx                   |    6 
 sc/source/ui/view/viewfun3.cxx                   |    4 
 sd/inc/drawdoc.hxx                               |    2 
 sd/inc/sdfilter.hxx                              |    4 
 sd/inc/sdmod.hxx                                 |    4 
 sd/source/filter/eppt/eppt.cxx                   |   20 
 sd/source/filter/eppt/eppt.hxx                   |   10 
 sd/source/filter/eppt/epptso.cxx                 |    4 
 sd/source/filter/ppt/pptin.cxx                   |    8 
 sd/source/filter/ppt/pptin.hxx                   |    4 
 sd/source/filter/ppt/propread.hxx                |    3 
 sd/source/filter/sdpptwrp.cxx                    |   24 -
 sd/source/ui/app/sdmod.cxx                       |    4 
 sd/source/ui/app/sdmod1.cxx                      |   10 
 sd/source/ui/dlg/morphdlg.cxx                    |    4 
 sd/source/ui/dlg/vectdlg.cxx                     |    4 
 sd/source/ui/inc/DrawDocShell.hxx                |    3 
 sd/source/ui/inc/sdtreelb.hxx                    |    2 
 sd/source/ui/unoidl/sddetect.cxx                 |    2 
 sd/source/ui/unoidl/unodoc.cxx                   |    4 
 sfx2/source/appl/appcfg.cxx                      |   10 
 sfx2/source/appl/appopen.cxx                     |    3 
 sfx2/source/appl/sfxpicklist.cxx                 |    6 
 sfx2/source/appl/xpackcreator.cxx                |    4 
 sfx2/source/control/bindings.cxx                 |    1 
 sfx2/source/doc/objcont.cxx                      |    1 
 sfx2/source/doc/objxtor.cxx                      |   38 -
 sfx2/source/doc/oleprops.cxx                     |    4 
 sfx2/source/inc/objshimp.hxx                     |    4 
 sot/qa/cppunit/test_sot.cxx                      |   20 
 sot/source/base/object.cxx                       |    6 
 sot/source/sdstor/storage.cxx                    |   22 
 starmath/qa/cppunit/test_cursor.cxx              |    2 
 starmath/qa/cppunit/test_node.cxx                |    2 
 starmath/qa/cppunit/test_nodetotextvisitors.cxx  |    2 
 starmath/qa/cppunit/test_parse.cxx               |    2 
 starmath/qa/cppunit/test_starmath.cxx            |    2 
 starmath/qa/extras/mmlexport-test.cxx            |    2 
 starmath/qa/extras/mmlimport-test.cxx            |    2 
 starmath/source/document.cxx                     |    2 
 starmath/source/eqnolefilehdr.cxx                |    2 
 starmath/source/mathtype.cxx                     |   10 
 starmath/source/smdetect.cxx                     |    2 
 starmath/source/unodoc.cxx                       |    2 
 starmath/source/unofilter.cxx                    |    2 
 svtools/source/misc/imagemgr.cxx                 |    2 
 svx/source/gallery2/gallerybinaryengine.cxx      |   22 
 sw/inc/doc.hxx                                   |    2 
 sw/inc/shellio.hxx                               |   10 
 sw/qa/core/filters-test.cxx                      |    2 
 sw/qa/core/macros-test.cxx                       |    2 
 sw/qa/core/uwriter.cxx                           |    2 
 sw/qa/extras/htmlexport/htmlexport.cxx           |    6 
 sw/source/core/doc/DocumentLayoutManager.cxx     |    4 
 sw/source/core/doc/docnew.cxx                    |    4 
 sw/source/core/inc/SwXMLTextBlocks.hxx           |    4 
 sw/source/core/ole/ndole.cxx                     |    8 
 sw/source/core/swg/SwXMLTextBlocks.cxx           |   14 
 sw/source/filter/basflt/iodetect.cxx             |    4 
 sw/source/filter/basflt/shellio.cxx              |    4 
 sw/source/filter/html/htmlplug.cxx               |    2 
 sw/source/filter/html/htmlreqifreader.cxx        |   16 
 sw/source/filter/writer/writer.cxx               |    2 
 sw/source/filter/ww8/wrtw8esh.cxx                |    6 
 sw/source/filter/ww8/wrtww8.cxx                  |   12 
 sw/source/filter/ww8/wrtww8.hxx                  |    6 
 sw/source/filter/ww8/wrtww8gr.cxx                |   16 
 sw/source/filter/ww8/ww8glsy.cxx                 |    2 
 sw/source/filter/ww8/ww8glsy.hxx                 |    8 
 sw/source/filter/ww8/ww8par.cxx                  |   36 -
 sw/source/filter/ww8/ww8par.hxx                  |   10 
 sw/source/filter/ww8/ww8par4.cxx                 |   20 
 sw/source/filter/ww8/ww8par5.cxx                 |    6 
 sw/source/ui/uno/swdetect.cxx                    |    4 
 sw/source/uibase/app/apphdl.cxx                  |    2 
 sw/source/uibase/app/docsh.cxx                   |    4 
 sw/source/uibase/app/docsh2.cxx                  |    3 
 sw/source/uibase/dochdl/swdtflvr.cxx             |    4 
 sw/source/uibase/inc/glosdoc.hxx                 |    4 
 sw/source/uibase/inc/unoatxt.hxx                 |    3 
 sw/source/uibase/misc/glshell.cxx                |    4 
 sw/source/uibase/uno/unodoc.cxx                  |    6 
 sw/source/uibase/uno/unotxvw.cxx                 |    4 
 vcl/inc/svdata.hxx                               |    5 
 vcl/source/app/scheduler.cxx                     |   70 ---
 vcl/source/app/svapp.cxx                         |    4 
 vcl/source/app/svmain.cxx                        |    3 
 vcl/win/dtrans/MtaOleClipb.cxx                   |   35 -
 vcl/win/dtrans/WinClipboard.cxx                  |   14 
 vcl/win/window/salframe.cxx                      |   10 
 writerperfect/source/common/WPXSvInputStream.cxx |   30 -
 163 files changed, 802 insertions(+), 1045 deletions(-)

New commits:
commit c844ed2784054c5e08883b05698fcc614d73d9ac
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Mar 27 17:50:57 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Mar 27 17:50:57 2024 +0500

    Revert "Check the correct member"
    
    This reverts commit 4169d62be965e2b3c3ddac63bd47030856557529.

diff --git a/embeddedobj/source/msole/olecomponent.cxx 
b/embeddedobj/source/msole/olecomponent.cxx
index 518de651d045..fcd659e369a3 100644
--- a/embeddedobj/source/msole/olecomponent.cxx
+++ b/embeddedobj/source/msole/olecomponent.cxx
@@ -1102,7 +1102,7 @@ awt::Size OleComponent::GetExtent( sal_Int64 nAspect )
 
 awt::Size OleComponent::GetCachedExtent( sal_Int64 nAspect )
 {
-    if (!m_pNativeImpl->m_pViewObject2)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
     DWORD nMSAspect = static_cast<DWORD>(nAspect); // first 32 bits are for MS 
aspects
commit 8167cc5603907d10948036c5a5a8529e3d5fcbaf
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Mar 27 17:50:57 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Mar 27 17:50:57 2024 +0500

    Revert "Drop some reinterpret_casts"
    
    This reverts commit 97be339b4f5441dc9458f665828bd2cf30760661.

diff --git a/embeddedobj/source/msole/olecomponent.cxx 
b/embeddedobj/source/msole/olecomponent.cxx
index fccad3dc9577..518de651d045 100644
--- a/embeddedobj/source/msole/olecomponent.cxx
+++ b/embeddedobj/source/msole/olecomponent.cxx
@@ -586,7 +586,7 @@ bool OleComponent::InitializeObject_Impl()
 
 namespace
 {
-    HRESULT OleLoadSeh(LPSTORAGE pIStorage, IUnknown** ppObj)
+    HRESULT OleLoadSeh(LPSTORAGE pIStorage, LPVOID* ppObj)
     {
         HRESULT hr = E_FAIL;
         // tdf#119039: there is a nasty bug in OleLoad, that may call an 
unpaired
@@ -600,7 +600,7 @@ namespace
             pIStorage->AddRef();
 
         __try {
-            hr = OleLoad(pIStorage, IID_IUnknown, nullptr, 
IID_PPV_ARGS_Helper(ppObj));
+            hr = OleLoad(pIStorage, IID_IUnknown, nullptr, ppObj);
         } __except( EXCEPTION_EXECUTE_HANDLER ) {
             hr = E_FAIL;
         }
@@ -625,7 +625,7 @@ void OleComponent::LoadEmbeddedObject( const OUString& 
aTempURL )
     if ( FAILED( hr ) || !m_pNativeImpl->m_pIStorage )
         throw io::IOException(); // TODO: transport error code?
 
-    hr = OleLoadSeh(m_pNativeImpl->m_pIStorage, &m_pNativeImpl->m_pObj);
+    hr = OleLoadSeh(m_pNativeImpl->m_pIStorage, 
reinterpret_cast<void**>(&m_pNativeImpl->m_pObj));
     if ( FAILED( hr ) || !m_pNativeImpl->m_pObj )
     {
         throw uno::RuntimeException();
@@ -856,7 +856,7 @@ void OleComponent::InitEmbeddedCopyOfLink( 
rtl::Reference<OleComponent> const &
                 {
                     hr = pObjectStorage->CopyTo( 0, nullptr, nullptr, 
m_pNativeImpl->m_pIStorage );
                     if ( SUCCEEDED( hr ) )
-                        hr = OleLoadSeh(m_pNativeImpl->m_pIStorage, 
&m_pNativeImpl->m_pObj);
+                        hr = OleLoadSeh(m_pNativeImpl->m_pIStorage, 
reinterpret_cast<void**>(&m_pNativeImpl->m_pObj));
                 }
             }
         }
commit 1852648e4e5365fc0c6cc2a1647863d8329e9987
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Mar 27 17:50:56 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Mar 27 17:50:56 2024 +0500

    Revert "Reimplement OleComponentNative_Impl to use IGlobalInterfaceTable"
    
    This reverts commit 6ea9f4fac8112267e78e210650b3c58a4c7a0e99.

diff --git a/embeddedobj/source/inc/oleembobj.hxx 
b/embeddedobj/source/inc/oleembobj.hxx
index 274ecfaf8847..a59a33551f06 100644
--- a/embeddedobj/source/inc/oleembobj.hxx
+++ b/embeddedobj/source/inc/oleembobj.hxx
@@ -453,18 +453,4 @@ public:
     css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() 
override;
 };
 
-class ClearedMutexArea
-{
-public:
-    ClearedMutexArea(osl::ResettableMutexGuard& guard)
-        : m_guard(guard)
-    {
-        m_guard.clear();
-    }
-    ~ClearedMutexArea() { m_guard.reset(); }
-
-private:
-    osl::ResettableMutexGuard& m_guard;
-};
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/embeddedobj/source/msole/olecomponent.cxx 
b/embeddedobj/source/msole/olecomponent.cxx
index da10b9d9d233..fccad3dc9577 100644
--- a/embeddedobj/source/msole/olecomponent.cxx
+++ b/embeddedobj/source/msole/olecomponent.cxx
@@ -42,7 +42,6 @@
 #include <o3tl/char16_t2wchar_t.hxx>
 #include <o3tl/unit_conversion.hxx>
 #include <systools/win32/comtools.hxx>
-#include <vcl/svapp.hxx>
 #include <vcl/threadex.hxx>
 
 #include "graphconvert.hxx"
@@ -60,81 +59,23 @@ using namespace ::comphelper;
 #define     MAX_ENUM_ELE     20
 #define     FORMATS_NUM      3
 
+typedef std::vector< FORMATETC* > FormatEtcList;
+
 FORMATETC const pFormatTemplates[FORMATS_NUM] = {
                     { CF_ENHMETAFILE, nullptr, 0, -1, TYMED_ENHMF },
                     { CF_METAFILEPICT, nullptr, 0, -1, TYMED_MFPICT },
                     { CF_BITMAP, nullptr, 0, -1, TYMED_GDI } };
 
 
-// We have at least one single-threaded apartment (STA) in the process (the 
VCL Main thread, which
-// is the GUI thread), and a multithreaded apartment (MTA) for most of other 
threads. OLE objects
-// may be created in either: in interactive mode, this typically happens in 
the STA; when serving
-// external requests, this may be either in STA (when explicit "OnMainThread" 
argument is passed to
-// loadComponentFromURL, and the instantiation of the object happens during 
the load), or in MTA
-// (the thread actually serving the incoming calls).
-//
-// The objects typically can only be used in the appartment where they were 
instantiated. This means
-// that e.g. a call to IOleObject::Close will fail, if it is performed in a 
different thread, when
-// it was started in the main thread. And vice versa, opening a document in a 
handler thread, then
-// trying to interact with the OLE object in GUI would fail.
-//
-// To handle this, several workarounds were implemented in the past; the 
mentioned "OnMainThread"
-// argument is one of these, allowing open document requests be processed not 
in the handler threads
-// that receired the request, but in the main thread which will then be used 
for interaction. Also
-// OleComponent::GetExtent was changed to check if the first call to 
IDataObject::GetData failed
-// with RPC_E_WRONG_THREAD, and then retry in the main thread.
-//
-// But ultimately every call to the OLE object needs such checks. E.g., 
failing to close the object
-// keeps the server running, effectively leaking resources, until it 
crashes/freezes after multiple
-// iterations.
-//
-// Currently, OleComponentNative_Impl is implemented using 
IGlobalInterfaceTable, which allows to
-// register an object in process-global instance of the table from the thread 
that instantiated the
-// object, and obtain a "cookie" (a number); and then use that cookie from any 
thread to access that
-// object. The global table will do its magic to provide either the original 
object (when it is
-// requested from the same apartment as used for its registration), or a 
"proxy", which will marshal
-// all calls to the proper thread, transparently for the caller. This 
implementation should obsolete
-// the previous workarounds (in theory).
-//
-// m_pGlobalTable is the reference to the global table.
-// The storage object gets registered in the global table immediately when 
it's created.
-// But the OLE object itself can't be registered immediately, before it is 
run: an attempt to call
-// RegisterInterfaceInGlobal with such a newly created OLE object fails with 
CO_E_OBJNOTCONNECTED.
-// Thus, the initial reference to the OLE object (which at this stage seems to 
be apartment-neutral)
-// is stored to m_pObj. Only when it is run, it is registered in the global 
table.
-//
-// Indeed, the implicit change of the thread is a blocking operation, which 
opens a wonderful new
-// opportunities for shiny deadlocks. Thus, precautions are needed to avoid 
them.
-//
-// When the OLE object is accessed by m_pObj (should be only in initialization 
code!), no measures
-// are taken to change locking. But when it is accessed by getObj() - which 
may return the proxy -
-// the calls are guarded by a SolarMutexReleaser, to allow the other thread do 
its job.
-//
-// There are at least two other mutexes in play here. One is in 
OleEmbeddedObject, that holds the
-// OleComponent. The calls to OleComponent's methods are also wrapped there 
into unlock/lock pairs
-// (see OleEmbeddedObject::changeState). The other is in OleComponent itself. 
For now, I see no
-// deadlocks caused by that mutex, so no unlock/lock is introduced for that. 
It may turn out to be
-// required eventually.
-class OleComponentNative_Impl
-{
-public:
+struct OleComponentNative_Impl {
     sal::systools::COMReference< IUnknown > m_pObj;
+    sal::systools::COMReference< IOleObject > m_pOleObject;
+    sal::systools::COMReference< IViewObject2 > m_pViewObject2;
+    sal::systools::COMReference< IStorage > m_pIStorage;
+    FormatEtcList m_aFormatsList;
     uno::Sequence< datatransfer::DataFlavor > m_aSupportedGraphFormats;
 
-    // The getters may return a proxy, that redirects the calls to another 
thread.
-    // Thus, calls to methods of returned objects must be inside solar mutex 
releaser.
-    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); }
-
-    void registerStorage(IStorage* pStorage) { registerInterface(pStorage, 
m_nStorage); }
-    void registerObj() { registerInterface(m_pObj.get(), m_nOleObject); }
-
-    bool IsStorageRegistered() const { return m_nStorage != 0; }
-
     OleComponentNative_Impl()
-        : m_pGlobalTable(CLSID_StdGlobalInterfaceTable, nullptr, 
CLSCTX_INPROC_SERVER)
     {
         // TODO: Extend format list
         m_aSupportedGraphFormats = {
@@ -166,14 +107,6 @@ public:
         };
     }
 
-    ~OleComponentNative_Impl()
-    {
-        if (m_nOleObject)
-            m_pGlobalTable->RevokeInterfaceFromGlobal(m_nOleObject);
-        if (m_nStorage)
-            m_pGlobalTable->RevokeInterfaceFromGlobal(m_nStorage);
-    }
-
     bool ConvertDataForFlavor( const STGMEDIUM& aMedium,
                                     const datatransfer::DataFlavor& aFlavor,
                                     uno::Any& aResult );
@@ -181,39 +114,8 @@ public:
     bool GraphicalFlavor( const datatransfer::DataFlavor& aFlavor );
 
     uno::Sequence< datatransfer::DataFlavor > GetFlavorsForAspects( sal_uInt32 
nSupportedAspects );
-
-    sal::systools::COMReference<IStorage> CreateNewStorage(const OUString& 
url);
-
-private:
-    sal::systools::COMReference<IGlobalInterfaceTable> m_pGlobalTable;
-    DWORD m_nStorage = 0;
-    DWORD m_nOleObject = 0;
-
-    template <typename T> sal::systools::COMReference<T> getInterface(DWORD 
cookie) const
-    {
-        sal::systools::COMReference<T> result;
-        HRESULT hr = m_pGlobalTable->GetInterfaceFromGlobal(cookie, 
IID_PPV_ARGS(&result));
-        SAL_WARN_IF(FAILED(hr), "embeddedobj.ole",
-                    "GetInterfaceFromGlobal failed: is cookie " << cookie << " 
not registered?");
-        return result;
-    }
-
-    template <typename T> void registerInterface(T* pInterface, DWORD& cookie)
-    {
-        assert(cookie == 0); // do not set again
-        HRESULT hr = m_pGlobalTable->RegisterInterfaceInGlobal(pInterface, 
__uuidof(T), &cookie);
-        SAL_WARN_IF(FAILED(hr), "embeddedobj.ole", "RegisterInterfaceInGlobal 
failed");
-    }
 };
 
-namespace
-{
-struct SafeSolarMutexReleaser
-{
-    SolarMutexGuard guard; // To make sure we actually hold it prior to release
-    SolarMutexReleaser releaser;
-};
-}
 
 static DWORD GetAspectFromFlavor( const datatransfer::DataFlavor& aFlavor )
 {
@@ -245,6 +147,23 @@ static OUString GetFlavorSuffixFromAspect( DWORD nAsp )
 }
 
 
+static HRESULT OpenIStorageFromURL_Impl( const OUString& aURL, IStorage** 
ppIStorage )
+{
+    OSL_ENSURE( ppIStorage, "The pointer must not be empty!" );
+
+    OUString aFilePath;
+    if ( !ppIStorage || ::osl::FileBase::getSystemPathFromFileURL( aURL, 
aFilePath ) != ::osl::FileBase::E_None )
+        throw uno::RuntimeException(); // TODO: something dangerous happened
+
+    return StgOpenStorage( o3tl::toW(aFilePath.getStr()),
+                             nullptr,
+                             STGM_READWRITE | STGM_TRANSACTED, // | 
STGM_DELETEONRELEASE,
+                             nullptr,
+                             0,
+                             ppIStorage );
+}
+
+
 bool OleComponentNative_Impl::ConvertDataForFlavor( const STGMEDIUM& aMedium,
                                                         const 
datatransfer::DataFlavor& aFlavor,
                                                         uno::Any& aResult )
@@ -401,10 +320,12 @@ OleComponent::OleComponent( const uno::Reference< 
uno::XComponentContext >& xCon
 : m_pInterfaceContainer( nullptr )
 , m_bDisposed( false )
 , m_bModified( false )
-, m_pNativeImpl( std::make_unique<OleComponentNative_Impl>() )
+, m_pNativeImpl( new OleComponentNative_Impl() )
 , m_pUnoOleObject( pUnoOleObject )
 , m_pOleWrapClientSite( nullptr )
 , m_pImplAdviseSink( nullptr )
+, m_nOLEMiscFlags( 0 )
+, m_nAdvConn( 0 )
 , m_xContext( xContext )
 , m_bOleInitialized( false )
 , m_bWorkaroundActive( false )
@@ -442,6 +363,14 @@ OleComponent::~OleComponent()
             Dispose();
         } catch( const uno::Exception& ) {}
     }
+
+    for (auto const& format : m_pNativeImpl->m_aFormatsList)
+    {
+        delete format;
+    }
+    m_pNativeImpl->m_aFormatsList.clear();
+
+    delete m_pNativeImpl;
 }
 
 void OleComponent::Dispose()
@@ -499,37 +428,30 @@ void OleComponent::disconnectEmbeddedObject()
 }
 
 
-OUString OleComponent::getTempURL() const
+void OleComponent::CreateNewIStorage_Impl()
 {
+    // TODO: in future a global memory could be used instead of file.
+
+    // write the stream to the temporary file
+    OUString aTempURL;
+
     OSL_ENSURE( m_pUnoOleObject, "Unexpected object absence!" );
     if ( m_pUnoOleObject )
-        return m_pUnoOleObject->CreateTempURLEmpty_Impl();
+        aTempURL = m_pUnoOleObject->CreateTempURLEmpty_Impl();
     else
-        return GetNewTempFileURL_Impl(m_xContext);
-}
-
-
-sal::systools::COMReference<IStorage> 
OleComponentNative_Impl::CreateNewStorage(const OUString& url)
-{
-    if (IsStorageRegistered())
-        throw io::IOException(); // TODO:the object is already initialized
-    // TODO: in future a global memory could be used instead of file.
+        aTempURL = GetNewTempFileURL_Impl( m_xContext );
 
-    // write the stream to the temporary file
-    if (url.isEmpty())
+    if ( !aTempURL.getLength() )
         throw uno::RuntimeException(); // TODO
 
     // open an IStorage based on the temporary file
     OUString aTempFilePath;
-    if (osl::FileBase::getSystemPathFromFileURL(url, aTempFilePath) != 
osl::FileBase::E_None)
+    if ( ::osl::FileBase::getSystemPathFromFileURL( aTempURL, aTempFilePath ) 
!= ::osl::FileBase::E_None )
         throw uno::RuntimeException(); // TODO: something dangerous happened
 
-    sal::systools::COMReference<IStorage> pStorage;
-    HRESULT hr = StgCreateDocfile( o3tl::toW(aTempFilePath.getStr()), 
STGM_CREATE | STGM_READWRITE | STGM_TRANSACTED | STGM_DELETEONRELEASE, 0, 
&pStorage );
-    if (FAILED(hr) || !pStorage)
+    HRESULT hr = StgCreateDocfile( o3tl::toW(aTempFilePath.getStr()), 
STGM_CREATE | STGM_READWRITE | STGM_TRANSACTED | STGM_DELETEONRELEASE, 0, 
&m_pNativeImpl->m_pIStorage );
+    if ( FAILED( hr ) || !m_pNativeImpl->m_pIStorage )
         throw io::IOException(); // TODO: transport error code?
-    registerStorage(pStorage);
-    return pStorage;
 }
 
 
@@ -559,19 +481,16 @@ uno::Sequence< datatransfer::DataFlavor > 
OleComponentNative_Impl::GetFlavorsFor
 
 void OleComponent::RetrieveObjectDataFlavors_Impl()
 {
-    if (!m_pNativeImpl->m_pObj)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
     if ( !m_aDataFlavors.getLength() )
     {
-        if (auto pDataObject = m_pNativeImpl->get<IDataObject>())
+        sal::systools::COMReference< IDataObject > 
pDataObject(m_pNativeImpl->m_pObj, sal::systools::COM_QUERY);
+        if ( pDataObject )
         {
-            HRESULT hr;
             sal::systools::COMReference< IEnumFORMATETC > pFormatEnum;
-            {
-                SafeSolarMutexReleaser releaser;
-                hr = pDataObject->EnumFormatEtc(DATADIR_GET, &pFormatEnum);
-            }
+            HRESULT hr = pDataObject->EnumFormatEtc( DATADIR_GET, &pFormatEnum 
);
             if ( SUCCEEDED( hr ) && pFormatEnum )
             {
                 FORMATETC pElem[ MAX_ENUM_ELE ];
@@ -611,20 +530,19 @@ void OleComponent::RetrieveObjectDataFlavors_Impl()
 }
 
 
-void OleComponent::InitializeObject_Impl()
+bool OleComponent::InitializeObject_Impl()
 // There will be no static objects!
 {
     if ( !m_pNativeImpl->m_pObj )
-        throw embed::WrongStateException();
+        return false;
 
     // 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() );
 
-    auto 
pViewObject2(m_pNativeImpl->m_pObj.QueryInterface<IViewObject2>(sal::systools::COM_QUERY));
-    if (!pViewObject2)
-        throw uno::RuntimeException(); // TODO
+    if ( !m_pNativeImpl->m_pViewObject2.set(m_pNativeImpl->m_pObj, 
sal::systools::COM_QUERY) )
+        return false;
 
     // remove all the caches
     if ( sal::systools::COMReference< IOleCache > pIOleCache{ 
m_pNativeImpl->m_pObj, sal::systools::COM_QUERY } )
@@ -647,24 +565,23 @@ void OleComponent::InitializeObject_Impl()
         hr2 = pIOleCache->Cache( &aFormat, ADVFCACHE_ONSAVE, &nConn );
     }
 
-    auto 
pOleObject(m_pNativeImpl->m_pObj.QueryInterface<IOleObject>(sal::systools::COM_QUERY));
-    if (!pOleObject)
-        throw uno::RuntimeException(); // Static objects are not supported, 
they should be inserted as graphics
+    if ( !m_pNativeImpl->m_pOleObject.set(m_pNativeImpl->m_pObj, 
sal::systools::COM_QUERY) )
+        return false; // Static objects are not supported, they should be 
inserted as graphics
 
-    DWORD nOLEMiscFlags(0);
-    pOleObject->GetMiscStatus(DVASPECT_CONTENT, 
reinterpret_cast<DWORD*>(&nOLEMiscFlags));
+    m_pNativeImpl->m_pOleObject->GetMiscStatus( DVASPECT_CONTENT, 
reinterpret_cast<DWORD*>(&m_nOLEMiscFlags) );
     // TODO: use other misc flags also
     // the object should have drawable aspect even in case it supports only 
iconic representation
-    // if ( nOLEMiscFlags & OLEMISC_ONLYICONIC )
+    // if ( m_nOLEMiscFlags & OLEMISC_ONLYICONIC )
 
-    pOleObject->SetClientSite(m_pOleWrapClientSite);
+    m_pNativeImpl->m_pOleObject->SetClientSite( m_pOleWrapClientSite );
 
     // the only need in this registration is workaround for close notification
-    DWORD nAdvConn(0);
-    pOleObject->Advise(m_pImplAdviseSink, reinterpret_cast<DWORD*>(&nAdvConn));
-    pViewObject2->SetAdvise(DVASPECT_CONTENT, 0, m_pImplAdviseSink);
+    m_pNativeImpl->m_pOleObject->Advise( m_pImplAdviseSink, 
reinterpret_cast<DWORD*>(&m_nAdvConn) );
+    m_pNativeImpl->m_pViewObject2->SetAdvise( DVASPECT_CONTENT, 0, 
m_pImplAdviseSink );
 
-    OleSetContainedObject(pOleObject, TRUE);
+    OleSetContainedObject( m_pNativeImpl->m_pOleObject, TRUE );
+
+    return true;
 }
 
 namespace
@@ -699,62 +616,62 @@ void OleComponent::LoadEmbeddedObject( const OUString& 
aTempURL )
     if ( !aTempURL.getLength() )
         throw lang::IllegalArgumentException(); // TODO
 
-    if (m_pNativeImpl->IsStorageRegistered())
+    if ( m_pNativeImpl->m_pIStorage )
         throw io::IOException(); // TODO the object is already initialized or 
wrong initialization is done
 
     // open an IStorage based on the temporary file
-    OUString aFilePath;
-    if (osl::FileBase::getSystemPathFromFileURL(aTempURL, aFilePath) != 
::osl::FileBase::E_None)
-        throw uno::RuntimeException(); // TODO: something dangerous happened
+    HRESULT hr = OpenIStorageFromURL_Impl( aTempURL, 
&m_pNativeImpl->m_pIStorage );
 
-    sal::systools::COMReference<IStorage> pStorage;
-    HRESULT hr = StgOpenStorage(o3tl::toW(aFilePath.getStr()), nullptr,
-                                STGM_READWRITE | STGM_TRANSACTED, // | 
STGM_DELETEONRELEASE,
-                                nullptr, 0, &pStorage);
-    if (FAILED(hr) || !pStorage)
+    if ( FAILED( hr ) || !m_pNativeImpl->m_pIStorage )
         throw io::IOException(); // TODO: transport error code?
 
-    m_pNativeImpl->registerStorage(pStorage);
-
-    hr = OleLoadSeh(pStorage, &m_pNativeImpl->m_pObj);
-    if (FAILED(hr))
+    hr = OleLoadSeh(m_pNativeImpl->m_pIStorage, &m_pNativeImpl->m_pObj);
+    if ( FAILED( hr ) || !m_pNativeImpl->m_pObj )
+    {
         throw uno::RuntimeException();
+    }
 
-    InitializeObject_Impl();
+    if ( !InitializeObject_Impl() )
+        throw uno::RuntimeException(); // TODO
 }
 
 
 void OleComponent::CreateObjectFromClipboard()
 {
-    auto pStorage(m_pNativeImpl->CreateNewStorage(getTempURL()));
-    if (!pStorage)
+    if ( m_pNativeImpl->m_pIStorage )
+        throw io::IOException(); // TODO:the object is already initialized
+
+    CreateNewIStorage_Impl();
+    if ( !m_pNativeImpl->m_pIStorage )
         throw uno::RuntimeException(); // TODO
 
     IDataObject * pDO = nullptr;
     HRESULT hr = OleGetClipboard( &pDO );
-    if (FAILED(hr))
-        throw uno::RuntimeException();
-
-    hr = OleQueryCreateFromData(pDO);
-    if (S_OK == hr)
+    if( SUCCEEDED( hr ) && pDO )
     {
-        hr = OleCreateFromData( pDO,
-                                IID_IUnknown,
-                                OLERENDER_DRAW, // OLERENDER_FORMAT
-                                nullptr,        // &aFormat,
-                                nullptr,
-                                pStorage,
-                                IID_PPV_ARGS_Helper(&m_pNativeImpl->m_pObj) );
-        if (FAILED(hr))
-            throw uno::RuntimeException();
-    }
-    else
-    {
-        // Static objects are not supported
-        pDO->Release();
+        hr = OleQueryCreateFromData( pDO );
+        if( S_OK == GetScode( hr ) )
+        {
+            hr = OleCreateFromData( pDO,
+                                    IID_IUnknown,
+                                    OLERENDER_DRAW, // OLERENDER_FORMAT
+                                    nullptr,        // &aFormat,
+                                    nullptr,
+                                    m_pNativeImpl->m_pIStorage,
+                                    
reinterpret_cast<void**>(&m_pNativeImpl->m_pObj) );
+        }
+        else
+        {
+            // Static objects are not supported
+            pDO->Release();
+        }
     }
 
-    InitializeObject_Impl();
+    if ( FAILED( hr ) || !m_pNativeImpl->m_pObj )
+        throw uno::RuntimeException();
+
+    if ( !InitializeObject_Impl() )
+        throw uno::RuntimeException(); // TODO
 }
 
 
@@ -765,8 +682,11 @@ void OleComponent::CreateNewEmbeddedObject( const 
uno::Sequence< sal_Int8 >& aSe
     if ( !GetClassIDFromSequence_Impl( aSeqCLSID, aClsID ) )
         throw lang::IllegalArgumentException(); // TODO
 
-    auto pStorage(m_pNativeImpl->CreateNewStorage(getTempURL()));
-    if (!pStorage)
+    if ( m_pNativeImpl->m_pIStorage )
+        throw io::IOException(); // TODO:the object is already initialized
+
+    CreateNewIStorage_Impl();
+    if ( !m_pNativeImpl->m_pIStorage )
         throw uno::RuntimeException(); // TODO
 
     // FORMATETC aFormat = { CF_METAFILEPICT, NULL, nAspect, -1, TYMED_MFPICT 
}; // for OLE..._DRAW should be NULL
@@ -776,12 +696,14 @@ void OleComponent::CreateNewEmbeddedObject( const 
uno::Sequence< sal_Int8 >& aSe
                             OLERENDER_DRAW, // OLERENDER_FORMAT
                             nullptr,        // &aFormat,
                             nullptr,
-                            pStorage,
-                            IID_PPV_ARGS_Helper(&m_pNativeImpl->m_pObj) );
-    if (FAILED(hr))
+                            m_pNativeImpl->m_pIStorage,
+                            reinterpret_cast<void**>(&m_pNativeImpl->m_pObj) );
+
+    if ( FAILED( hr ) || !m_pNativeImpl->m_pObj )
         throw uno::RuntimeException(); // TODO
 
-    InitializeObject_Impl();
+    if ( !InitializeObject_Impl() )
+        throw uno::RuntimeException(); // TODO
 
     // TODO: getExtent???
 }
@@ -800,8 +722,11 @@ void OleComponent::CreateObjectFromData( const 
uno::Reference< datatransfer::XTr
 
 void OleComponent::CreateObjectFromFile( const OUString& aFileURL )
 {
-    auto pStorage(m_pNativeImpl->CreateNewStorage(getTempURL()));
-    if (!pStorage)
+    if ( m_pNativeImpl->m_pIStorage )
+        throw io::IOException(); // TODO:the object is already initialized
+
+    CreateNewIStorage_Impl();
+    if ( !m_pNativeImpl->m_pIStorage )
         throw uno::RuntimeException(); // TODO:
 
     OUString aFilePath;
@@ -814,19 +739,24 @@ void OleComponent::CreateObjectFromFile( const OUString& 
aFileURL )
                                     OLERENDER_DRAW, // OLERENDER_FORMAT
                                     nullptr,
                                     nullptr,
-                                    pStorage,
-                                    
IID_PPV_ARGS_Helper(&m_pNativeImpl->m_pObj) );
-    if (FAILED(hr))
+                                    m_pNativeImpl->m_pIStorage,
+                                    
reinterpret_cast<void**>(&m_pNativeImpl->m_pObj) );
+
+    if ( FAILED( hr ) || !m_pNativeImpl->m_pObj )
         throw uno::RuntimeException(); // TODO
 
-    InitializeObject_Impl();
+    if ( !InitializeObject_Impl() )
+        throw uno::RuntimeException(); // TODO
 }
 
 
 void OleComponent::CreateLinkFromFile( const OUString& aFileURL )
 {
-    auto pStorage(m_pNativeImpl->CreateNewStorage(getTempURL()));
-    if (!pStorage)
+    if ( m_pNativeImpl->m_pIStorage )
+        throw io::IOException(); // TODO:the object is already initialized
+
+    CreateNewIStorage_Impl();
+    if ( !m_pNativeImpl->m_pIStorage )
         throw uno::RuntimeException(); // TODO:
 
     OUString aFilePath;
@@ -838,33 +768,31 @@ void OleComponent::CreateLinkFromFile( const OUString& 
aFileURL )
                                         OLERENDER_DRAW, // OLERENDER_FORMAT
                                         nullptr,
                                         nullptr,
-                                        pStorage,
-                                        
IID_PPV_ARGS_Helper(&m_pNativeImpl->m_pObj) );
-    if (FAILED(hr))
+                                        m_pNativeImpl->m_pIStorage,
+                                        
reinterpret_cast<void**>(&m_pNativeImpl->m_pObj) );
+
+    if ( FAILED( hr ) || !m_pNativeImpl->m_pObj )
         throw uno::RuntimeException(); // TODO
 
-    InitializeObject_Impl();
+    if ( !InitializeObject_Impl() )
+        throw uno::RuntimeException(); // TODO
 }
 
 
 void OleComponent::InitEmbeddedCopyOfLink( rtl::Reference<OleComponent> const 
& pOleLinkComponent )
 {
-    if (!pOleLinkComponent)
+    if ( !pOleLinkComponent || !pOleLinkComponent->m_pNativeImpl->m_pObj )
         throw lang::IllegalArgumentException(); // TODO
 
-    auto pOleLinkComponentObj(pOleLinkComponent->m_pNativeImpl->getObj());
-    if (!pOleLinkComponentObj)
-        throw lang::IllegalArgumentException();
-
-    // the object must be already disconnected from the temporary URL
-    auto pStorage(m_pNativeImpl->CreateNewStorage(getTempURL()));
-
-    SafeSolarMutexReleaser releaser;
+    if ( m_pNativeImpl->m_pIStorage )
+        throw io::IOException(); // TODO:the object is already initialized
 
-    auto 
pDataObject(pOleLinkComponentObj.QueryInterface<IDataObject>(sal::systools::COM_QUERY));
+    sal::systools::COMReference< IDataObject > 
pDataObject(pOleLinkComponent->m_pNativeImpl->m_pObj, sal::systools::COM_QUERY);
     if ( pDataObject && SUCCEEDED( OleQueryCreateFromData( pDataObject ) ) )
     {
-        if (!pStorage)
+        // the object must be already disconnected from the temporary URL
+        CreateNewIStorage_Impl();
+        if ( !m_pNativeImpl->m_pIStorage )
             throw uno::RuntimeException(); // TODO:
 
         OleCreateFromData( pDataObject,
@@ -872,13 +800,13 @@ void OleComponent::InitEmbeddedCopyOfLink( 
rtl::Reference<OleComponent> const &
                                 OLERENDER_DRAW,
                                 nullptr,
                                 nullptr,
-                                pStorage,
-                                IID_PPV_ARGS_Helper(&m_pNativeImpl->m_pObj) );
+                                m_pNativeImpl->m_pIStorage,
+                                
reinterpret_cast<void**>(&m_pNativeImpl->m_pObj) );
     }
 
     if ( !m_pNativeImpl->m_pObj )
     {
-        auto 
pOleLink(pOleLinkComponentObj.QueryInterface<IOleLink>(sal::systools::COM_QUERY));
+        sal::systools::COMReference< IOleLink > 
pOleLink(m_pNativeImpl->m_pObj, sal::systools::COM_QUERY);
         if ( !pOleLink )
             throw io::IOException(); // TODO: the object doesn't support 
IOleLink
 
@@ -910,8 +838,8 @@ void OleComponent::InitEmbeddedCopyOfLink( 
rtl::Reference<OleComponent> const &
                                         OLERENDER_DRAW, // OLERENDER_FORMAT
                                         nullptr,
                                         nullptr,
-                                        pStorage,
-                                        
IID_PPV_ARGS_Helper(&m_pNativeImpl->m_pObj) );
+                                        m_pNativeImpl->m_pIStorage,
+                                        
reinterpret_cast<void**>(&m_pNativeImpl->m_pObj) );
             }
         }
 
@@ -923,29 +851,33 @@ void OleComponent::InitEmbeddedCopyOfLink( 
rtl::Reference<OleComponent> const &
             if ( SUCCEEDED( hr ) && pBindCtx )
             {
                 sal::systools::COMReference< IStorage > pObjectStorage;
-                hr = pMoniker->BindToStorage(pBindCtx, nullptr, 
IID_PPV_ARGS(&pObjectStorage));
+                hr = pMoniker->BindToStorage( pBindCtx, nullptr, IID_IStorage, 
reinterpret_cast<void**>(&pObjectStorage) );
                 if ( SUCCEEDED( hr ) && pObjectStorage )
                 {
-                    hr = pObjectStorage->CopyTo(0, nullptr, nullptr, pStorage);
+                    hr = pObjectStorage->CopyTo( 0, nullptr, nullptr, 
m_pNativeImpl->m_pIStorage );
                     if ( SUCCEEDED( hr ) )
-                        hr = OleLoadSeh(pStorage, &m_pNativeImpl->m_pObj);
+                        hr = OleLoadSeh(m_pNativeImpl->m_pIStorage, 
&m_pNativeImpl->m_pObj);
                 }
             }
         }
     }
 
-    InitializeObject_Impl();
+    // If object could not be created the only way is to use graphical 
representation
+    if ( !m_pNativeImpl->m_pObj )
+        throw uno::RuntimeException(); // TODO
+
+    if ( !InitializeObject_Impl() )
+        throw uno::RuntimeException(); // TODO
 }
 
 
 void OleComponent::RunObject()
 {
-    auto pOleObject(m_pNativeImpl->get<IOleObject>());
-    OSL_ENSURE(pOleObject, "The pointer can not be set to NULL here!");
-    if (!pOleObject)
+    OSL_ENSURE( m_pNativeImpl->m_pOleObject, "The pointer can not be set to 
NULL here!" );
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
-    if (!OleIsRunning(pOleObject))
+    if ( !OleIsRunning( m_pNativeImpl->m_pOleObject ) )
     {
         HRESULT hr = OleRun( m_pNativeImpl->m_pObj );
 
@@ -956,9 +888,6 @@ void OleComponent::RunObject()
             else
                 throw io::IOException();
         }
-        // Only now, when the object is activated, it can be registered in the 
global table;
-        // before this point, RegisterInterfaceInGlobal would return 
CO_E_OBJNOTCONNECTED
-        m_pNativeImpl->registerObj();
     }
 }
 
@@ -984,31 +913,20 @@ awt::Size OleComponent::CalculateWithFactor( const 
awt::Size& aSize,
 
 void OleComponent::CloseObject()
 {
-    auto pOleObject(m_pNativeImpl->get<IOleObject>());
-    if (pOleObject && OleIsRunning(pOleObject))
-    {
-        SafeSolarMutexReleaser releaser;
-        HRESULT hr = pOleObject->Close(OLECLOSE_NOSAVE); // must be saved 
before
-        SAL_WARN_IF(FAILED(hr), "embeddedobj.ole", "IOleObject::Close failed");
-    }
+    if ( m_pNativeImpl->m_pOleObject && OleIsRunning( 
m_pNativeImpl->m_pOleObject ) )
+        m_pNativeImpl->m_pOleObject->Close( OLECLOSE_NOSAVE ); // must be 
saved before
 }
 
 
 uno::Sequence< embed::VerbDescriptor > OleComponent::GetVerbList()
 {
-    auto pOleObject(m_pNativeImpl->get<IOleObject>());
-    if (!pOleObject)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
     if( !m_aVerbList.getLength() )
     {
         sal::systools::COMReference< IEnumOLEVERB > pEnum;
-        HRESULT hr;
-        {
-            SafeSolarMutexReleaser releaser;
-            hr = pOleObject->EnumVerbs(&pEnum);
-        }
-        if (SUCCEEDED(hr))
+        if( SUCCEEDED( m_pNativeImpl->m_pOleObject->EnumVerbs( &pEnum ) ) )
         {
             OLEVERB     szEle[ MAX_ENUM_ELE ];
             ULONG       nNum = 0;
@@ -1016,7 +934,7 @@ uno::Sequence< embed::VerbDescriptor > 
OleComponent::GetVerbList()
 
             do
             {
-                hr = pEnum->Next(MAX_ENUM_ELE, szEle, &nNum);
+                HRESULT hr = pEnum->Next( MAX_ENUM_ELE, szEle, &nNum );
                 if( hr == S_OK || hr == S_FALSE )
                 {
                     m_aVerbList.realloc( nSeqSize += nNum );
@@ -1042,17 +960,16 @@ uno::Sequence< embed::VerbDescriptor > 
OleComponent::GetVerbList()
 
 void OleComponent::ExecuteVerb( sal_Int32 nVerbID )
 {
-    RunObject();
-
-    auto pOleObject(m_pNativeImpl->get<IOleObject>());
-    if (!pOleObject)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO
 
-    SafeSolarMutexReleaser releaser;
+    HRESULT hr = OleRun( m_pNativeImpl->m_pOleObject );
+    if ( FAILED( hr ) )
+        throw io::IOException(); // TODO: a specific exception that transport 
error code can be thrown here
 
     // TODO: probably extents should be set here and stored in aRect
     // TODO: probably the parent window also should be set
-    HRESULT hr = pOleObject->DoVerb(nVerbID, nullptr, m_pOleWrapClientSite, 0, 
nullptr, nullptr);
+    hr = m_pNativeImpl->m_pOleObject->DoVerb( nVerbID, nullptr, 
m_pOleWrapClientSite, 0, nullptr, nullptr );
 
     if ( FAILED( hr ) )
         throw io::IOException(); // TODO
@@ -1061,29 +978,22 @@ void OleComponent::ExecuteVerb( sal_Int32 nVerbID )
 
 void OleComponent::SetHostName( const OUString& aEmbDocName )
 {
-    auto pOleObject(m_pNativeImpl->get<IOleObject>());
-    if (!pOleObject)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
-    SafeSolarMutexReleaser releaser;
-    pOleObject->SetHostNames(L"app name", o3tl::toW(aEmbDocName.getStr()));
+    m_pNativeImpl->m_pOleObject->SetHostNames( L"app name", o3tl::toW( 
aEmbDocName.getStr() ) );
 }
 
 
 void OleComponent::SetExtent( const awt::Size& aVisAreaSize, sal_Int64 nAspect 
)
 {
-    auto pOleObject(m_pNativeImpl->get<IOleObject>());
-    if (!pOleObject)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
     DWORD nMSAspect = static_cast<DWORD>(nAspect); // first 32 bits are for MS 
aspects
 
     SIZEL aSize = { aVisAreaSize.Width, aVisAreaSize.Height };
-    HRESULT hr;
-    {
-        SafeSolarMutexReleaser releaser;
-        hr = pOleObject->SetExtent(nMSAspect, &aSize);
-    }
+    HRESULT hr = m_pNativeImpl->m_pOleObject->SetExtent( nMSAspect, &aSize );
 
     if ( FAILED( hr ) )
     {
@@ -1099,7 +1009,7 @@ void OleComponent::SetExtent( const awt::Size& 
aVisAreaSize, sal_Int64 nAspect )
 
 awt::Size OleComponent::GetExtent( sal_Int64 nAspect )
 {
-    if (!m_pNativeImpl->m_pObj)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
     DWORD nMSAspect = static_cast<DWORD>(nAspect); // first 32 bits are for MS 
aspects
@@ -1109,17 +1019,14 @@ awt::Size OleComponent::GetExtent( sal_Int64 nAspect )
     if ( nMSAspect == DVASPECT_CONTENT )
     {
         // Try to get the size from the replacement image first
-        if (auto pDataObject = m_pNativeImpl->get<IDataObject>())
+        sal::systools::COMReference< IDataObject > 
pDataObject(m_pNativeImpl->m_pObj, sal::systools::COM_QUERY);
+        if ( pDataObject )
         {
             STGMEDIUM aMedium;
             FORMATETC aFormat = pFormatTemplates[1]; // use windows metafile 
format
             aFormat.dwAspect = nMSAspect;
 
-            HRESULT hr;
-            {
-                SafeSolarMutexReleaser releaser;
-                hr = pDataObject->GetData(&aFormat, &aMedium);
-            }
+            HRESULT hr = pDataObject->GetData( &aFormat, &aMedium );
 
             if (hr == RPC_E_WRONG_THREAD)
             {
@@ -1195,18 +1102,13 @@ awt::Size OleComponent::GetExtent( sal_Int64 nAspect )
 
 awt::Size OleComponent::GetCachedExtent( sal_Int64 nAspect )
 {
-    auto pViewObject2(m_pNativeImpl->get<IViewObject2>());
-    if (!pViewObject2)
+    if (!m_pNativeImpl->m_pViewObject2)
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
     DWORD nMSAspect = static_cast<DWORD>(nAspect); // first 32 bits are for MS 
aspects
     SIZEL aSize;
 
-    HRESULT hr;
-    {
-        SafeSolarMutexReleaser releaser;
-        hr = pViewObject2->GetExtent(nMSAspect, -1, nullptr, &aSize);
-    }
+    HRESULT hr = m_pNativeImpl->m_pViewObject2->GetExtent( nMSAspect, -1, 
nullptr, &aSize );
 
     if ( FAILED( hr ) )
     {
@@ -1227,17 +1129,12 @@ awt::Size OleComponent::GetCachedExtent( sal_Int64 
nAspect )
 
 awt::Size OleComponent::GetRecommendedExtent( sal_Int64 nAspect )
 {
-    auto pOleObject(m_pNativeImpl->get<IOleObject>());
-    if (!pOleObject)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
     DWORD nMSAspect = static_cast<DWORD>(nAspect); // first 32 bits are for MS 
aspects
     SIZEL aSize;
-    HRESULT hr;
-    {
-        SafeSolarMutexReleaser releaser;
-        hr = pOleObject->GetExtent(nMSAspect, &aSize);
-    }
+    HRESULT hr = m_pNativeImpl->m_pOleObject->GetExtent( nMSAspect, &aSize );
     if ( FAILED( hr ) )
     {
         SAL_WARN("embeddedobj.ole", " OleComponent::GetRecommendedExtent: 
GetExtent() failed");
@@ -1250,31 +1147,22 @@ awt::Size OleComponent::GetRecommendedExtent( sal_Int64 
nAspect )
 
 sal_Int64 OleComponent::GetMiscStatus( sal_Int64 nAspect )
 {
-    auto pOleObject(m_pNativeImpl->get<IOleObject>());
-    if (!pOleObject)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
-    DWORD nResult = 0;
-    {
-        SafeSolarMutexReleaser releaser;
-        pOleObject->GetMiscStatus(static_cast<DWORD>(nAspect), &nResult);
-    }
+    DWORD nResult;
+    m_pNativeImpl->m_pOleObject->GetMiscStatus( static_cast<DWORD>(nAspect), 
&nResult );
     return static_cast<sal_Int64>(nResult); // first 32 bits are for MS flags
 }
 
 
 uno::Sequence< sal_Int8 > OleComponent::GetCLSID()
 {
-    auto pOleObject(m_pNativeImpl->get<IOleObject>());
-    if (!pOleObject)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
     GUID aCLSID;
-    HRESULT hr;
-    {
-        SafeSolarMutexReleaser releaser;
-        hr = pOleObject->GetUserClassID(&aCLSID);
-    }
+    HRESULT hr = m_pNativeImpl->m_pOleObject->GetUserClassID( &aCLSID );
     if ( FAILED( hr ) )
         throw io::IOException(); // TODO:
 
@@ -1288,14 +1176,16 @@ uno::Sequence< sal_Int8 > OleComponent::GetCLSID()
 
 bool OleComponent::IsDirty()
 {
+    if ( !m_pNativeImpl->m_pOleObject )
+        throw embed::WrongStateException(); // TODO: the object is in wrong 
state
+
     if ( IsWorkaroundActive() )
         return true;
 
-    auto pPersistStorage(m_pNativeImpl->get<IPersistStorage>());
+    sal::systools::COMReference< IPersistStorage > 
pPersistStorage(m_pNativeImpl->m_pObj, sal::systools::COM_QUERY);
     if ( !pPersistStorage )
         throw io::IOException(); // TODO
 
-    SafeSolarMutexReleaser releaser;
     HRESULT hr = pPersistStorage->IsDirty();
     return ( hr != S_FALSE );
 }
@@ -1303,45 +1193,41 @@ bool OleComponent::IsDirty()
 
 void OleComponent::StoreOwnTmpIfNecessary()
 {
-    auto pOleObject(m_pNativeImpl->get<IOleObject>());
-    if (!pOleObject)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
-    auto pPersistStorage(m_pNativeImpl->get<IPersistStorage>());
+    sal::systools::COMReference< IPersistStorage > 
pPersistStorage(m_pNativeImpl->m_pObj, sal::systools::COM_QUERY);
     if ( !pPersistStorage )
         throw io::IOException(); // TODO
 
-    SafeSolarMutexReleaser releaser;
-
     if ( m_bWorkaroundActive || pPersistStorage->IsDirty() != S_FALSE )
     {
-        auto pStorage(m_pNativeImpl->getStorage());
-        HRESULT hr = OleSave(pPersistStorage, pStorage, TRUE);
+        HRESULT hr = OleSave( pPersistStorage, m_pNativeImpl->m_pIStorage, 
TRUE );
         if ( FAILED( hr ) )
         {
             // Till now was required only for AcrobatReader7.0.8
             GUID aCLSID;
-            hr = pOleObject->GetUserClassID(&aCLSID);
+            hr = m_pNativeImpl->m_pOleObject->GetUserClassID( &aCLSID );
             if ( FAILED( hr ) )
             {
                 SAL_WARN("embeddedobj.ole", 
"OleComponent::StoreOwnTmpIfNecessary: GetUserClassID() failed");
                 throw io::IOException(); // TODO
             }
 
-            hr = WriteClassStg(pStorage, aCLSID);
+            hr = WriteClassStg( m_pNativeImpl->m_pIStorage, aCLSID );
             if ( FAILED( hr ) )
                 throw io::IOException(); // TODO
 
             // the result of the following call is not checked because some 
objects, for example AcrobatReader7.0.8
             // return error even in case the saving was done correctly
-            hr = pPersistStorage->Save(pStorage, TRUE);
+            hr = pPersistStorage->Save( m_pNativeImpl->m_pIStorage, TRUE );
 
             // another workaround for AcrobatReader7.0.8 object, this object 
might think that it is not changed
             // when it has been created from file, although it must be saved
             m_bWorkaroundActive = true;
         }
 
-        hr = pStorage->Commit(STGC_DEFAULT);
+        hr = m_pNativeImpl->m_pIStorage->Commit( STGC_DEFAULT );
         if ( FAILED( hr ) )
             throw io::IOException(); // TODO
 
@@ -1533,7 +1419,7 @@ uno::Any SAL_CALL OleComponent::getTransferData( const 
datatransfer::DataFlavor&
     if ( m_bDisposed )
         throw lang::DisposedException(); // TODO
 
-    if (!m_pNativeImpl->m_pObj)
+    if ( !m_pNativeImpl->m_pOleObject )
         throw embed::WrongStateException(); // TODO: the object is in wrong 
state
 
     uno::Any aResult;
@@ -1544,7 +1430,7 @@ uno::Any SAL_CALL OleComponent::getTransferData( const 
datatransfer::DataFlavor&
         DWORD nRequestedAspect = GetAspectFromFlavor( aFlavor );
         // if own icon is set and icon aspect is requested the own icon can be 
returned directly
 
-        auto pDataObject(m_pNativeImpl->get<IDataObject>());
+        sal::systools::COMReference< IDataObject > 
pDataObject(m_pNativeImpl->m_pObj, sal::systools::COM_QUERY);
         if ( !pDataObject )
             throw io::IOException(); // TODO: transport error code
 
@@ -1571,11 +1457,7 @@ uno::Any SAL_CALL OleComponent::getTransferData( const 
datatransfer::DataFlavor&
                 FORMATETC aFormat = pFormatTemplates[nInd];
                 aFormat.dwAspect = nRequestedAspect;
 
-                HRESULT hr;
-                {
-                    SafeSolarMutexReleaser releaser;
-                    hr = pDataObject->GetData(&aFormat, &aMedium);
-                }
+                HRESULT hr = pDataObject->GetData( &aFormat, &aMedium );
                 if ( SUCCEEDED( hr ) )
                 {
                     bSupportedFlavor = m_pNativeImpl->ConvertDataForFlavor( 
aMedium, aFlavor, aResult );
@@ -1634,6 +1516,9 @@ uno::Sequence< datatransfer::DataFlavor > SAL_CALL 
OleComponent::getTransferData
     if ( m_bDisposed )
         throw lang::DisposedException(); // TODO
 
+    if ( !m_pNativeImpl->m_pOleObject )
+        throw embed::WrongStateException(); // TODO: the object is in wrong 
state
+
     RetrieveObjectDataFlavors_Impl();
 
     return m_aDataFlavors;
@@ -1646,7 +1531,13 @@ sal_Bool SAL_CALL OleComponent::isDataFlavorSupported( 
const datatransfer::DataF
     if ( m_bDisposed )
         throw lang::DisposedException(); // TODO
 
-    RetrieveObjectDataFlavors_Impl();
+    if ( !m_pNativeImpl->m_pOleObject )
+        throw embed::WrongStateException(); // TODO: the object is in wrong 
state
+
+    if ( !m_aDataFlavors.getLength() )
+    {
+        RetrieveObjectDataFlavors_Impl();
+    }
 
     for ( auto const & supportedFormat : std::as_const(m_aDataFlavors) )
         if ( supportedFormat.MimeType.equals( aFlavor.MimeType ) && 
supportedFormat.DataType == aFlavor.DataType )
@@ -1696,7 +1587,7 @@ sal_Int64 SAL_CALL OleComponent::getSomething( const 
css::uno::Sequence< sal_Int
     {
         uno::Sequence < sal_Int8 > aCLSID = GetCLSID();
         if ( MimeConfigurationHelper::ClassIDsEqual( aIdentifier, aCLSID ) )
-            return comphelper::getSomething_cast(m_pNativeImpl->m_pObj.get());
+            return 
comphelper::getSomething_cast(static_cast<IUnknown*>(m_pNativeImpl->m_pObj));
 
         // compatibility hack for old versions: CLSID was used in wrong order 
(SvGlobalName order)
         sal_Int32 nLength = aIdentifier.getLength();
@@ -1713,7 +1604,7 @@ sal_Int64 SAL_CALL OleComponent::getSomething( const 
css::uno::Sequence< sal_Int
                  aIdentifier[2] == aCLSID[1] &&
                  aIdentifier[1] == aCLSID[2] &&
                  aIdentifier[0] == aCLSID[3] )
-                return 
comphelper::getSomething_cast(m_pNativeImpl->m_pObj.get());
+                return 
reinterpret_cast<sal_Int64>(static_cast<IUnknown*>(m_pNativeImpl->m_pObj));
         }
     }
     catch ( const uno::Exception& )
diff --git a/embeddedobj/source/msole/olecomponent.hxx 
b/embeddedobj/source/msole/olecomponent.hxx
index e08d5a69b2f4..5a96b64fcbfc 100644
--- a/embeddedobj/source/msole/olecomponent.hxx
+++ b/embeddedobj/source/msole/olecomponent.hxx
@@ -41,7 +41,7 @@ namespace comphelper {
 class OleWrapperClientSite;
 class OleWrapperAdviseSink;
 class OleEmbeddedObject;
-class OleComponentNative_Impl;
+struct OleComponentNative_Impl;
 
 class OleComponent : public ::cppu::WeakImplHelper< css::util::XCloseable, 
css::lang::XComponent,
                                                     css::lang::XUnoTunnel, 
css::util::XModifiable,
@@ -52,12 +52,15 @@ class OleComponent : public ::cppu::WeakImplHelper< 
css::util::XCloseable, css::
 
     bool m_bDisposed;
     bool m_bModified;
-    std::unique_ptr<OleComponentNative_Impl> m_pNativeImpl;
+    OleComponentNative_Impl* m_pNativeImpl;
 
     OleEmbeddedObject* m_pUnoOleObject;
     OleWrapperClientSite* m_pOleWrapClientSite;
     OleWrapperAdviseSink* m_pImplAdviseSink;
 
+    sal_Int32 m_nOLEMiscFlags;
+    sal_Int32 m_nAdvConn;
+
     css::uno::Sequence< css::embed::VerbDescriptor > m_aVerbList;
     css::uno::Sequence< css::datatransfer::DataFlavor > m_aDataFlavors;
 
@@ -69,10 +72,9 @@ class OleComponent : public ::cppu::WeakImplHelper< 
css::util::XCloseable, css::
     // such objects report the dirty state wrongly sometimes and do not allow 
to store them any time
     bool m_bWorkaroundActive;
 
-    void InitializeObject_Impl();
-
-    OUString getTempURL() const;
+    bool InitializeObject_Impl();
 
+    void CreateNewIStorage_Impl();
     void RetrieveObjectDataFlavors_Impl();
     void Dispose();
 
diff --git a/embeddedobj/source/msole/oleembed.cxx 
b/embeddedobj/source/msole/oleembed.cxx
index 63d5f700b089..d06969925109 100644
--- a/embeddedobj/source/msole/oleembed.cxx
+++ b/embeddedobj/source/msole/oleembed.cxx
@@ -495,12 +495,12 @@ void SAL_CALL OleEmbeddedObject::changeState( sal_Int32 
nNewState )
                 // the loaded state must be set before, because of 
notifications!
                 m_nObjectState = nNewState;
 
-                aGuard.clear();
                 {
                     VerbExecutionControllerGuard aVerbGuard( 
m_aVerbExecutionController );
                     m_pOleComponent->CloseObject();
                 }
 
+                aGuard.clear();
                 StateChangeNotification_Impl( false, nOldState, m_nObjectState 
);
                 aGuard.reset();
             }
@@ -863,11 +863,9 @@ void SAL_CALL OleEmbeddedObject::doVerb( sal_Int32 nVerbID 
)
             // ==== the STAMPIT related solution =============================
             m_aVerbExecutionController.StartControlExecution();
 
-            {
-                ClearedMutexArea clearedMutex(aGuard);
-                m_pOleComponent->ExecuteVerb(nVerbID);
-                m_pOleComponent->SetHostName(m_aContainerName);
-            }
+
+            m_pOleComponent->ExecuteVerb( nVerbID );
+            m_pOleComponent->SetHostName( m_aContainerName );
 
             // ==== the STAMPIT related solution =============================
             bool bModifiedOnExecution = 
m_aVerbExecutionController.EndControlExecution_WasModified();
@@ -974,7 +972,7 @@ uno::Sequence< embed::VerbDescriptor > SAL_CALL 
OleEmbeddedObject::getSupportedV
     }
     // end wrapping related part ====================
 
-    osl::ClearableMutexGuard aGuard(m_aMutex);
+    ::osl::MutexGuard aGuard( m_aMutex );
     if ( m_bDisposed )
         throw lang::DisposedException(); // TODO
 
@@ -991,7 +989,6 @@ uno::Sequence< embed::VerbDescriptor > SAL_CALL 
OleEmbeddedObject::getSupportedV
         //  throw embed::NeedsRunningStateException(); // TODO:
         // }
 
-        aGuard.clear();
         return m_pOleComponent->GetVerbList();
     }
     else
@@ -1131,7 +1128,7 @@ sal_Int64 SAL_CALL OleEmbeddedObject::getStatus( sal_Int64
     }
     // end wrapping related part ====================
 
-    osl::ResettableMutexGuard aGuard(m_aMutex);
+    ::osl::MutexGuard aGuard( m_aMutex );
     if ( m_bDisposed )
         throw lang::DisposedException(); // TODO
 
@@ -1146,10 +1143,8 @@ sal_Int64 SAL_CALL OleEmbeddedObject::getStatus( 
sal_Int64
         nResult = m_nStatus;
     else if ( m_pOleComponent )
     {
-        {
-            ClearedMutexArea clearedMutex(aGuard);
-            m_nStatus = m_pOleComponent->GetMiscStatus(nAspect);
-        }
+
+        m_nStatus = m_pOleComponent->GetMiscStatus( nAspect );
         m_nStatusAspect = nAspect;
         m_bGotStatus = true;
         nResult = m_nStatus;
diff --git a/embeddedobj/source/msole/olevisual.cxx 
b/embeddedobj/source/msole/olevisual.cxx
index bcbacffe5d64..7d8de650db3e 100644
--- a/embeddedobj/source/msole/olevisual.cxx
+++ b/embeddedobj/source/msole/olevisual.cxx
@@ -325,7 +325,7 @@ embed::VisualRepresentation SAL_CALL 
OleEmbeddedObject::getPreferredVisualRepres
     }
     // end wrapping related part ====================
 
-    osl::ResettableMutexGuard aGuard(m_aMutex);
+    ::osl::MutexGuard aGuard( m_aMutex );
     if ( m_bDisposed )
         throw lang::DisposedException(); // TODO
 
@@ -364,10 +364,7 @@ embed::VisualRepresentation SAL_CALL 
OleEmbeddedObject::getPreferredVisualRepres
                     cppu::UnoType<uno::Sequence< sal_Int8 >>::get() );
 
             embed::VisualRepresentation aVisualRepr;
-            {
-                ClearedMutexArea clearedMutex(aGuard);
-                aVisualRepr.Data = 
m_pOleComponent->getTransferData(aDataFlavor);
-            }
+            aVisualRepr.Data = m_pOleComponent->getTransferData( aDataFlavor );
             aVisualRepr.Flavor = aDataFlavor;
 
             uno::Sequence< sal_Int8 > aVisReplSeq;
commit 51c7be65ddd3de7ba98212e9f23230b4694b5e3e
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Mar 27 17:50:56 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Mar 27 17:50:56 2024 +0500

    Revert "Use weak reference to SfxObjectShell in SfxEventHint to avoid 
use-after-free"
    
    This reverts commit 1230a418f7ae6e83d97da1eb945366aff57e3fa2.

diff --git a/basctl/source/basicide/unomodel.cxx 
b/basctl/source/basicide/unomodel.cxx
index d4ce9544ce2d..4a9ee759f060 100644
--- a/basctl/source/basicide/unomodel.cxx
+++ b/basctl/source/basicide/unomodel.cxx
@@ -123,7 +123,7 @@ com_sun_star_comp_basic_BasicID_get_implementation(
 {
     SolarMutexGuard aGuard;
     basctl::EnsureIde();
-    rtl::Reference<SfxObjectShell> pShell = new basctl::DocShell();
+    SfxObjectShell* pShell = new basctl::DocShell();
     auto pModel = pShell->GetModel();
     pModel->acquire();
     return pModel.get();
diff --git a/basic/source/basmgr/basicmanagerrepository.cxx 
b/basic/source/basmgr/basicmanagerrepository.cxx
index 4ece6f6e2c7f..7a2ed5efd20a 100644
--- a/basic/source/basmgr/basicmanagerrepository.cxx
+++ b/basic/source/basmgr/basicmanagerrepository.cxx
@@ -430,7 +430,7 @@ namespace basic
             OUString aAppBasicDir = SvtPathOptions().GetBasicPath();
 
             // Storage and BaseURL are only needed by binary documents!
-            rtl::Reference<SotStorage> xDummyStor = new SotStorage(OUString());
+            tools::SvRef<SotStorage> xDummyStor = new SotStorage( OUString() );
             _out_rpBasicManager.reset(new BasicManager( *xDummyStor, u"" /* 
TODO/LATER: xStorage */,
                                                                 pAppBasic,
                                                                 &aAppBasicDir, 
true ));
diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx
index 71a937f81b5f..72776dd08153 100644
--- a/basic/source/basmgr/basmgr.cxx
+++ b/basic/source/basmgr/basmgr.cxx
@@ -635,7 +635,7 @@ void BasicManager::ImpCreateStdLib( StarBASIC* 
pParentFromStdLib )
 
 void BasicManager::LoadBasicManager( SotStorage& rStorage, std::u16string_view 
rBaseURL )
 {
-    rtl::Reference<SotStorageStream> xManagerStream = rStorage.OpenSotStream( 
szManagerStream, eStreamReadMode );
+    tools::SvRef<SotStorageStream> xManagerStream = rStorage.OpenSotStream( 
szManagerStream, eStreamReadMode );
 
     OUString aStorName( rStorage.GetName() );
     // #i13114 removed, DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
@@ -727,7 +727,7 @@ void BasicManager::LoadBasicManager( SotStorage& rStorage, 
std::u16string_view r
 
 void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
 {
-    rtl::Reference<SotStorageStream> xManagerStream = rStorage.OpenSotStream( 
szOldManagerStream, eStreamReadMode );
+    tools::SvRef<SotStorageStream> xManagerStream = rStorage.OpenSotStream( 
szOldManagerStream, eStreamReadMode );
 
     OUString aStorName( rStorage.GetName() );
     DBG_ASSERT( aStorName.getLength(), "No Storage Name!" );
@@ -780,7 +780,7 @@ void BasicManager::LoadOldBasicManager( SotStorage& 
rStorage )
         aLibRelStorage = aLibRelStorage.smartRel2Abs( aLibRelStorageName, 
bWasAbsolute);
         DBG_ASSERT(!bWasAbsolute, "RelStorageName was absolute!" );
 
-        rtl::Reference<SotStorage> xStorageRef;
+        tools::SvRef<SotStorage> xStorageRef;
         if ( aLibAbsStorage == aCurStorage || aLibRelStorageName == szImbedded 
)
         {
             xStorageRef = &rStorage;
@@ -841,7 +841,7 @@ bool BasicManager::ImpLoadLibrary( BasicLibInfo* pLibInfo, 
SotStorage* pCurStora
     {
         aStorageName = GetStorageName();
     }
-    rtl::Reference<SotStorage> xStorage;
+    tools::SvRef<SotStorage> xStorage;
     // The current must not be opened again...
     if ( pCurStorage )
     {
@@ -864,7 +864,7 @@ bool BasicManager::ImpLoadLibrary( BasicLibInfo* pLibInfo, 
SotStorage* pCurStora
     {
         xStorage = new SotStorage( false, aStorageName, eStorageReadMode );
     }
-    rtl::Reference<SotStorage> xBasicStorage = xStorage->OpenSotStorage( 
szBasicStorage, eStorageReadMode, false );
+    tools::SvRef<SotStorage> xBasicStorage = xStorage->OpenSotStorage( 
szBasicStorage, eStorageReadMode, false );
 
     if ( !xBasicStorage.is() || xBasicStorage->GetError() )
     {
@@ -874,7 +874,7 @@ bool BasicManager::ImpLoadLibrary( BasicLibInfo* pLibInfo, 
SotStorage* pCurStora
     else
     {
         // In the Basic-Storage every lib is in a Stream...
-        rtl::Reference<SotStorageStream> xBasicStream = 
xBasicStorage->OpenSotStream( pLibInfo->GetLibName(), eStreamReadMode );
+        tools::SvRef<SotStorageStream> xBasicStream = 
xBasicStorage->OpenSotStream( pLibInfo->GetLibName(), eStreamReadMode );
         if ( !xBasicStream.is() || xBasicStream->GetError() )
         {
             StringErrorInfo* pErrInf = new StringErrorInfo( 
ERRCODE_BASMGR_LIBLOAD , pLibInfo->GetLibName(), DialogMask::ButtonsOk );
@@ -1096,7 +1096,7 @@ bool BasicManager::RemoveLib( sal_uInt16 nLib, bool 
bDelBasicFromStorage )
     if (bDelBasicFromStorage && !(*itLibInfo)->IsReference() &&
            (!(*itLibInfo)->IsExtern() || 
SotStorage::IsStorageFile((*itLibInfo)->GetStorageName())))
     {
-        rtl::Reference<SotStorage> xStorage;
+        tools::SvRef<SotStorage> xStorage;
         try
         {
             if (!(*itLibInfo)->IsExtern())
@@ -1115,7 +1115,7 @@ bool BasicManager::RemoveLib( sal_uInt16 nLib, bool 
bDelBasicFromStorage )
 
         if (xStorage.is() && xStorage->IsStorage(szBasicStorage))
         {
-            rtl::Reference<SotStorage> xBasicStorage = xStorage->OpenSotStorage
+            tools::SvRef<SotStorage> xBasicStorage = xStorage->OpenSotStorage
                             ( szBasicStorage, StreamMode::STD_READWRITE, false 
);
 
             if ( !xBasicStorage.is() || xBasicStorage->GetError() )
@@ -1289,7 +1289,7 @@ StarBASIC* BasicManager::CreateLib( const OUString& 
rLibName, const OUString& Pa
         {
             try
             {
-                rtl::Reference<SotStorage> xStorage = new SotStorage(false, 
LinkTargetURL, StreamMode::READ | StreamMode::SHARE_DENYWRITE);
+                tools::SvRef<SotStorage> xStorage = new SotStorage(false, 
LinkTargetURL, StreamMode::READ | StreamMode::SHARE_DENYWRITE);
                 if (!xStorage->GetError())
                 {
                     pLib = AddLib(*xStorage, rLibName, true);
diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx
index 3956c001ca31..eea449ac47fc 100644
--- a/basic/source/uno/scriptcont.cxx
+++ b/basic/source/uno/scriptcont.cxx
@@ -334,7 +334,7 @@ rtl::Reference<SfxLibraryContainer> 
SfxScriptLibraryContainer::createInstanceImp
 void SfxScriptLibraryContainer::importFromOldStorage( const OUString& aFile )
 {
     // TODO: move loading from old storage to binary filters?
-    rtl::Reference<SotStorage> xStorage(new SotStorage(false, aFile));
+    auto xStorage = tools::make_ref<SotStorage>( false, aFile );
     if( xStorage->GetError() == ERRCODE_NONE )
     {
         auto pBasicManager = std::make_unique<BasicManager> ( *xStorage, aFile 
);
diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx
index c8ed7a6113b2..054011e2a390 100644
--- a/editeng/source/misc/svxacorr.cxx
+++ b/editeng/source/misc/svxacorr.cxx
@@ -2228,7 +2228,7 @@ bool SvxAutoCorrectLanguageLists::IsFileChanged_Imp()
 void SvxAutoCorrectLanguageLists::LoadXMLExceptList_Imp(
                                         std::unique_ptr<SvStringsISortDtor>& 
rpLst,
                                         const OUString& sStrmName,
-                                        rtl::Reference<SotStorage>& rStg)
+                                        tools::SvRef<SotStorage>& rStg)
 {
     if( rpLst )
         rpLst->clear();
@@ -2238,7 +2238,7 @@ void SvxAutoCorrectLanguageLists::LoadXMLExceptList_Imp(
     {
         if( rStg.is() && rStg->IsStream( sStrmName ) )
         {
-            rtl::Reference<SotStorageStream> xStrm = rStg->OpenSotStream( 
sStrmName,
+            tools::SvRef<SotStorageStream> xStrm = rStg->OpenSotStream( 
sStrmName,
                 ( StreamMode::READ | StreamMode::SHARE_DENYWRITE | 
StreamMode::NOCREATE ) );
             if( ERRCODE_NONE != xStrm->GetError())
             {
@@ -2299,7 +2299,7 @@ void SvxAutoCorrectLanguageLists::LoadXMLExceptList_Imp(
 void SvxAutoCorrectLanguageLists::SaveExceptList_Imp(
                             const SvStringsISortDtor& rLst,
                             const OUString& sStrmName,
-                            rtl::Reference<SotStorage> const &rStg,
+                            tools::SvRef<SotStorage> const &rStg,
                             bool bConvert )
 {
     if( !rStg.is() )
@@ -2312,7 +2312,7 @@ void SvxAutoCorrectLanguageLists::SaveExceptList_Imp(
     }
     else
     {
-        rtl::Reference<SotStorageStream> xStrm = rStg->OpenSotStream( 
sStrmName,
+        tools::SvRef<SotStorageStream> xStrm = rStg->OpenSotStream( sStrmName,
                 ( StreamMode::READ | StreamMode::WRITE | 
StreamMode::SHARE_DENYWRITE ) );
         if( xStrm.is() )
         {
@@ -2431,7 +2431,7 @@ bool 
SvxAutoCorrectLanguageLists::AddToCplSttExceptList(const OUString& rNew)
     if( !rNew.isEmpty() && GetCplSttExceptList()->insert( rNew ).second )
     {
         MakeUserStorage_Impl();
-        rtl::Reference<SotStorage> xStg = new SotStorage(sUserAutoCorrFile, 
StreamMode::READWRITE);
+        tools::SvRef<SotStorage> xStg = new SotStorage( sUserAutoCorrFile, 
StreamMode::READWRITE );
 
         SaveExceptList_Imp( *pCplStt_ExcptLst, pXMLImplCplStt_ExcptLstStr, 
xStg );
 
@@ -2451,7 +2451,7 @@ bool 
SvxAutoCorrectLanguageLists::AddToWordStartExceptList(const OUString& rNew)
     if( !rNew.isEmpty() && GetWordStartExceptList()->insert( rNew ).second )
     {
         MakeUserStorage_Impl();
-        rtl::Reference<SotStorage> xStg = new SotStorage(sUserAutoCorrFile, 
StreamMode::READWRITE);
+        tools::SvRef<SotStorage> xStg = new SotStorage( sUserAutoCorrFile, 
StreamMode::READWRITE );
 
         SaveExceptList_Imp( *pWordStart_ExcptLst, 
pXMLImplWordStart_ExcptLstStr, xStg );
 
@@ -2469,7 +2469,7 @@ SvStringsISortDtor* 
SvxAutoCorrectLanguageLists::LoadCplSttExceptList()
 {
     try
     {
-        rtl::Reference<SotStorage> xStg = new SotStorage( sShareAutoCorrFile, 
StreamMode::READ | StreamMode::SHARE_DENYNONE );
+        tools::SvRef<SotStorage> xStg = new SotStorage( sShareAutoCorrFile, 
StreamMode::READ | StreamMode::SHARE_DENYNONE );
         if( xStg.is() && xStg->IsContained( pXMLImplCplStt_ExcptLstStr ) )
             LoadXMLExceptList_Imp( pCplStt_ExcptLst, 
pXMLImplCplStt_ExcptLstStr, xStg );
     }
@@ -2482,7 +2482,7 @@ SvStringsISortDtor* 
SvxAutoCorrectLanguageLists::LoadCplSttExceptList()
 void SvxAutoCorrectLanguageLists::SaveCplSttExceptList()
 {
     MakeUserStorage_Impl();
-    rtl::Reference<SotStorage> xStg = new SotStorage(sUserAutoCorrFile, 
StreamMode::READWRITE);
+    tools::SvRef<SotStorage> xStg = new SotStorage( sUserAutoCorrFile, 
StreamMode::READWRITE );
 
     SaveExceptList_Imp( *pCplStt_ExcptLst, pXMLImplCplStt_ExcptLstStr, xStg );
 
@@ -2498,7 +2498,7 @@ SvStringsISortDtor* 
SvxAutoCorrectLanguageLists::LoadWordStartExceptList()
 {
     try
     {
-        rtl::Reference<SotStorage> xStg = new SotStorage( sShareAutoCorrFile, 
StreamMode::READ | StreamMode::SHARE_DENYNONE );
+        tools::SvRef<SotStorage> xStg = new SotStorage( sShareAutoCorrFile, 
StreamMode::READ | StreamMode::SHARE_DENYNONE );
         if( xStg.is() && xStg->IsContained( pXMLImplWordStart_ExcptLstStr ) )
             LoadXMLExceptList_Imp( pWordStart_ExcptLst, 
pXMLImplWordStart_ExcptLstStr, xStg );
     }
@@ -2512,7 +2512,7 @@ SvStringsISortDtor* 
SvxAutoCorrectLanguageLists::LoadWordStartExceptList()
 void SvxAutoCorrectLanguageLists::SaveWordStartExceptList()
 {
     MakeUserStorage_Impl();
-    rtl::Reference<SotStorage> xStg = new SotStorage(sUserAutoCorrFile, 
StreamMode::READWRITE);
+    tools::SvRef<SotStorage> xStg = new SotStorage( sUserAutoCorrFile, 
StreamMode::READWRITE );
 
     SaveExceptList_Imp( *pWordStart_ExcptLst, pXMLImplWordStart_ExcptLstStr, 
xStg );
 
@@ -2542,7 +2542,7 @@ void SvxAutoCorrectLanguageLists::RemoveStream_Imp( const 
OUString& rName )
 {
     if( sShareAutoCorrFile != sUserAutoCorrFile )
     {
-        rtl::Reference<SotStorage> xStg = new SotStorage(sUserAutoCorrFile, 
StreamMode::READWRITE);
+        tools::SvRef<SotStorage> xStg = new SotStorage( sUserAutoCorrFile, 
StreamMode::READWRITE );
         if( xStg.is() && ERRCODE_NONE == xStg->GetError() &&
             xStg->IsStream( rName ) )
         {
@@ -2604,8 +2604,8 @@ void SvxAutoCorrectLanguageLists::MakeUserStorage_Impl()
     }
     if (bConvert && !bError)
     {
-        rtl::Reference<SotStorage> xSrcStg = new SotStorage( aDest.GetMainURL( 
INetURLObject::DecodeMechanism::ToIUri ), StreamMode::READ );
-        rtl::Reference<SotStorage> xDstStg = new SotStorage(sUserAutoCorrFile, 
StreamMode::WRITE);
+        tools::SvRef<SotStorage> xSrcStg = new SotStorage( aDest.GetMainURL( 
INetURLObject::DecodeMechanism::ToIUri ), StreamMode::READ );
+        tools::SvRef<SotStorage> xDstStg = new SotStorage( sUserAutoCorrFile, 
StreamMode::WRITE );
 
         if( xSrcStg.is() && xDstStg.is() )
         {
@@ -2653,7 +2653,7 @@ bool SvxAutoCorrectLanguageLists::MakeBlocklist_Imp( 
SotStorage& rStg )
     bool bRet = true, bRemove = !pAutocorr_List || pAutocorr_List->empty();
     if( !bRemove )
     {
-        rtl::Reference<SotStorageStream> refList = rStg.OpenSotStream( 
pXMLImplAutocorr_ListStr,
+        tools::SvRef<SotStorageStream> refList = rStg.OpenSotStream( 
pXMLImplAutocorr_ListStr,
                     ( StreamMode::READ | StreamMode::WRITE | 
StreamMode::SHARE_DENYWRITE ) );
         if( refList.is() )
         {
@@ -2704,7 +2704,7 @@ bool SvxAutoCorrectLanguageLists::MakeCombinedChanges( 
std::vector<SvxAutocorrWo
     GetAutocorrWordList();
 
     MakeUserStorage_Impl();
-    rtl::Reference<SotStorage> xStorage = new SotStorage(sUserAutoCorrFile, 
StreamMode::READWRITE);
+    tools::SvRef<SotStorage> xStorage = new SotStorage( sUserAutoCorrFile, 
StreamMode::READWRITE );
 
     bool bRet = xStorage.is() && ERRCODE_NONE == xStorage->GetError();
 
@@ -2773,7 +2773,7 @@ bool SvxAutoCorrectLanguageLists::PutText( const 
OUString& rShort, const OUStrin
     GetAutocorrWordList();
 
     MakeUserStorage_Impl();
-    rtl::Reference<SotStorage> xStg = new SotStorage(sUserAutoCorrFile, 
StreamMode::READWRITE);
+    tools::SvRef<SotStorage> xStg = new SotStorage( sUserAutoCorrFile, 
StreamMode::READWRITE );
 
     bool bRet = xStg.is() && ERRCODE_NONE == xStg->GetError();
 
@@ -2831,7 +2831,7 @@ void SvxAutoCorrectLanguageLists::PutText( const 
OUString& rShort,
         {
             if( pAutocorr_List->Insert( SvxAutocorrWord(rShort, sLong, false) 
) )
             {
-                rtl::Reference<SotStorage> xStor = new SotStorage( 
sUserAutoCorrFile, StreamMode::READWRITE );
+                tools::SvRef<SotStorage> xStor = new SotStorage( 
sUserAutoCorrFile, StreamMode::READWRITE );
                 MakeBlocklist_Imp( *xStor );
             }
         }
diff --git a/filter/source/msfilter/msdffimp.cxx 
b/filter/source/msfilter/msdffimp.cxx
index bfd141b4dc73..cdcad2778f6f 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -6756,7 +6756,7 @@ void SvxMSDffManager::ProcessClientAnchor2( SvStream& /* 
rSt */, DffRecordHeader
     // will be overridden by SJ in Draw
 }
 
-bool SvxMSDffManager::GetOLEStorageName( sal_uInt32, OUString&, 
rtl::Reference<SotStorage>&, uno::Reference < embed::XStorage >& ) const
+bool SvxMSDffManager::GetOLEStorageName( sal_uInt32, OUString&, 
tools::SvRef<SotStorage>&, uno::Reference < embed::XStorage >& ) const
 {
     return false;
 }
@@ -6775,7 +6775,7 @@ rtl::Reference<SdrObject> SvxMSDffManager::ImportOLE( 
sal_uInt32 nOLEId,
 {
     rtl::Reference<SdrObject> pRet;
     OUString sStorageName;
-    rtl::Reference<SotStorage> xSrcStg;
+    tools::SvRef<SotStorage> xSrcStg;
     ErrCode nError = ERRCODE_NONE;
     uno::Reference < embed::XStorage > xDstStg;
     if( GetOLEStorageName( nOLEId, sStorageName, xSrcStg, xDstStg ))
@@ -6797,7 +6797,7 @@ rtl::Reference<SdrObject> SvxMSDffManager::ImportOLE( 
sal_uInt32 nOLEId,
 
 bool SvxMSDffManager::MakeContentStream( SotStorage * pStor, const GDIMetaFile 
& rMtf )
 {
-    rtl::Reference<SotStorageStream> xStm = 
pStor->OpenSotStream(SVEXT_PERSIST_STREAM);
+    tools::SvRef<SotStorageStream> xStm = 
pStor->OpenSotStream(SVEXT_PERSIST_STREAM);
     xStm->SetVersion( pStor->GetVersion() );
     xStm->SetBufferSize( 8192 );
 
@@ -6937,10 +6937,10 @@ const ClsIDs aClsIDs[] = {
 
 
 bool SvxMSDffManager::ConvertToOle2( SvStream& rStm, sal_uInt32 nReadLen,
-                    const GDIMetaFile * pMtf, const 
rtl::Reference<SotStorage>& rDest )
+                    const GDIMetaFile * pMtf, const tools::SvRef<SotStorage>& 
rDest )
 {
     bool bMtfRead = false;
-    rtl::Reference<SotStorageStream> xOle10Stm = rDest->OpenSotStream( 
"Ole10Native",
+    tools::SvRef<SotStorageStream> xOle10Stm = rDest->OpenSotStream( 
"Ole10Native",
                                                     StreamMode::WRITE| 
StreamMode::SHARE_DENYALL );
     if( xOle10Stm->GetError() )
         return false;
@@ -6986,7 +6986,7 @@ bool SvxMSDffManager::ConvertToOle2( SvStream& rStm, 
sal_uInt32 nReadLen,
                 // write to ole10 stream
                 xOle10Stm->WriteUInt32( nDataLen );
                 xOle10Stm->WriteBytes(pData.get(), nDataLen);
-                xOle10Stm.clear();
+                xOle10Stm = tools::SvRef<SotStorageStream>();
 
                 // set the compobj stream
                 const ClsIDs* pIds;
@@ -7104,7 +7104,7 @@ OUString SvxMSDffManager::GetFilterNameFromClassID( const 
SvGlobalName& aGlobNam
 
 void SvxMSDffManager::ExtractOwnStream(SotStorage& rSrcStg, SvMemoryStream& 
rMemStream)
 {
-    rtl::Reference<SotStorageStream> xStr
+    tools::SvRef<SotStorageStream> xStr
         = rSrcStg.OpenSotStream("package_stream", StreamMode::STD_READ);
     xStr->ReadStream(rMemStream);
 }
@@ -7177,7 +7177,7 @@ css::uno::Reference < css::embed::XEmbeddedObject >  
SvxMSDffManager::CheckForCo
         }
         else
         {
-            rtl::Reference<SotStorage> xStorage = new SotStorage(false, 
aMemStream);
+            tools::SvRef<SotStorage> xStorage = new SotStorage( false, 
aMemStream );
             rSrcStg.CopyTo( xStorage.get() );
             xStorage->Commit();
             xStorage.clear();
@@ -7291,7 +7291,7 @@ css::uno::Reference < css::embed::XEmbeddedObject >  
SvxMSDffManager::CheckForCo
 rtl::Reference<SdrOle2Obj> SvxMSDffManager::CreateSdrOLEFromStorage(
     SdrModel& rSdrModel,
     const OUString& rStorageName,
-    rtl::Reference<SotStorage> const & rSrcStorage,
+    tools::SvRef<SotStorage> const & rSrcStorage,
     const uno::Reference < embed::XStorage >& xDestStorage,
     const Graphic& rGrf,
     const tools::Rectangle& rBoundRect,
@@ -7314,12 +7314,12 @@ rtl::Reference<SdrOle2Obj> 
SvxMSDffManager::CreateSdrOLEFromStorage(
         OUString aDstStgName = MSO_OLE_Obj + OUString::number( ++nMSOleObjCntr 
);
 
         {
-            rtl::Reference<SotStorage> xObjStg = 
rSrcStorage->OpenSotStorage(rStorageName);
+            tools::SvRef<SotStorage> xObjStg = rSrcStorage->OpenSotStorage( 
rStorageName );
             if( xObjStg.is()  )
             {
                 {
                     sal_uInt8 aTestA[10];   // exist the CompObj-Stream ?
-                    rtl::Reference<SotStorageStream> xSrcTst = 
xObjStg->OpenSotStream("CompObj");
+                    tools::SvRef<SotStorageStream> xSrcTst = 
xObjStg->OpenSotStream( "CompObj" );
                     bValidStorage = xSrcTst.is() && sizeof( aTestA ) ==
                                     xSrcTst->ReadBytes(aTestA, sizeof(aTestA));
                     if( !bValidStorage )
@@ -7340,7 +7340,7 @@ rtl::Reference<SdrOle2Obj> 
SvxMSDffManager::CreateSdrOLEFromStorage(
                         // is a kind of embedded objects in Word documents
                         // TODO/LATER: should the caller be notified if the 
aspect changes in future?
 
-                        rtl::Reference<SotStorageStream> xObjInfoSrc = 
xObjStg->OpenSotStream(
+                        tools::SvRef<SotStorageStream> xObjInfoSrc = 
xObjStg->OpenSotStream(
                             "ObjInfo", StreamMode::STD_READ );
                         if ( xObjInfoSrc.is() && !xObjInfoSrc->GetError() )
                         {
@@ -7382,11 +7382,11 @@ rtl::Reference<SdrOle2Obj> 
SvxMSDffManager::CreateSdrOLEFromStorage(
         if( bValidStorage )
         {
             // object is not an own object
-            rtl::Reference<SotStorage> xObjStor = SotStorage::OpenOLEStorage( 
xDestStorage, aDstStgName, StreamMode::READWRITE );
+            tools::SvRef<SotStorage> xObjStor = SotStorage::OpenOLEStorage( 
xDestStorage, aDstStgName, StreamMode::READWRITE );
 
             if ( xObjStor.is() )
             {
-                rtl::Reference<SotStorage> xSrcStor = 
rSrcStorage->OpenSotStorage( rStorageName, StreamMode::READ );
+                tools::SvRef<SotStorage> xSrcStor = 
rSrcStorage->OpenSotStorage( rStorageName, StreamMode::READ );
                 xSrcStor->CopyTo( xObjStor.get() );
 
                 if( !xObjStor->GetError() )
@@ -7413,7 +7413,7 @@ rtl::Reference<SdrOle2Obj> 
SvxMSDffManager::CreateSdrOLEFromStorage(
             else
             {
                 // or is it an OLE-1 Stream in the DataStream?
-                rtl::Reference<SotStorage> xObjStor = 
SotStorage::OpenOLEStorage( xDestStorage, aDstStgName );
+                tools::SvRef<SotStorage> xObjStor = 
SotStorage::OpenOLEStorage( xDestStorage, aDstStgName );
                 //TODO/MBA: remove metafile conversion from ConvertToOle2
                 //when is this code used?!
                 GDIMetaFile aMtf;
diff --git a/filter/source/msfilter/msoleexp.cxx 
b/filter/source/msfilter/msoleexp.cxx
index 3229bf57ec54..cd9f521da605 100644
--- a/filter/source/msfilter/msoleexp.cxx
+++ b/filter/source/msfilter/msoleexp.cxx
@@ -203,7 +203,7 @@ void SvxMSExportOLEObjects::ExportOLEObject( 
svt::EmbeddedObjectRef const & rObj
             }
             catch( const uno::Exception& ) {} // #TODO really handle 
exceptions - interactionalhandler etc. ?
 
-            rtl::Reference<SotStorage> xOLEStor = new SotStorage( pStream, 
true );
+            tools::SvRef<SotStorage> xOLEStor = new SotStorage( pStream, true 
);
             xOLEStor->CopyTo( &rDestStg );
             rDestStg.Commit();
         }
@@ -224,7 +224,7 @@ void SvxMSExportOLEObjects::ExportOLEObject( 
svt::EmbeddedObjectRef const & rObj
             rDestStg.SetClass( aEmbName,
                                 SotClipboardFormatId::EMBEDDED_OBJ_OLE,
                                 GetStorageType( aEmbName ) );
-            rtl::Reference<SotStorageStream> xExtStm = rDestStg.OpenSotStream(
+            tools::SvRef<SotStorageStream> xExtStm = rDestStg.OpenSotStream(
                                             "properties_stream");
 
             bool bExtentSuccess = false;
@@ -279,7 +279,7 @@ void SvxMSExportOLEObjects::ExportOLEObject( 
svt::EmbeddedObjectRef const & rObj
 
             if ( bExtentSuccess )
             {
-                rtl::Reference<SotStorageStream> xEmbStm = 
rDestStg.OpenSotStream(
+                tools::SvRef<SotStorageStream> xEmbStm = 
rDestStg.OpenSotStream(
                                                 "package_stream");
                 if( !xEmbStm->GetError() )
                 {
@@ -326,7 +326,7 @@ void SvxMSExportOLEObjects::ExportOLEObject( 
svt::EmbeddedObjectRef const & rObj
             catch ( const uno::Exception& )
             {}
 
-            rtl::Reference<SotStorage> xOLEStor = SotStorage::OpenOLEStorage( 
xStor, aTempName, StreamMode::STD_READ );
+            tools::SvRef<SotStorage> xOLEStor = SotStorage::OpenOLEStorage( 
xStor, aTempName, StreamMode::STD_READ );
             xOLEStor->CopyTo( &rDestStg );
             rDestStg.Commit();
         }
diff --git a/filter/source/msfilter/rtfutil.cxx 
b/filter/source/msfilter/rtfutil.cxx
index f9881c86a2b9..75f453c347c9 100644
--- a/filter/source/msfilter/rtfutil.cxx
+++ b/filter/source/msfilter/rtfutil.cxx
@@ -26,7 +26,7 @@ namespace
 void WrapOle1InOle2(SvStream& rOle1, sal_uInt32 nOle1Size, SvStream& rOle2,
                     const OString& rClassName)
 {
-    rtl::Reference<SotStorage> pStorage = new SotStorage(rOle2);
+    tools::SvRef<SotStorage> pStorage = new SotStorage(rOle2);
     OString aAnsiUserType;
     SvGlobalName aName;
     if (rClassName == "PBrush")
@@ -46,7 +46,7 @@ void WrapOle1InOle2(SvStream& rOle1, sal_uInt32 nOle1Size, 
SvStream& rOle2,
     pStorage->SetClass(aName, SotClipboardFormatId::NONE, "");
 
     // [MS-OLEDS] 2.3.7 CompObjHeader
-    rtl::Reference<SotStorageStream> pCompObj = 
pStorage->OpenSotStream("CompObj");
+    tools::SvRef<SotStorageStream> pCompObj = 
pStorage->OpenSotStream("CompObj");
     // Reserved1
     pCompObj->WriteUInt32(0xfffe0001);
     // Version
@@ -80,7 +80,7 @@ void WrapOle1InOle2(SvStream& rOle1, sal_uInt32 nOle1Size, 
SvStream& rOle2,
     pCompObj.clear();
 
     // [MS-OLEDS] 2.3.6 OLENativeStream
-    rtl::Reference<SotStorageStream> pOleNative = 
pStorage->OpenSotStream("Ole10Native");
+    tools::SvRef<SotStorageStream> pOleNative = 
pStorage->OpenSotStream("Ole10Native");
     // NativeDataSize
     pOleNative->WriteUInt32(nOle1Size);
     pOleNative->WriteStream(rOle1, nOle1Size);
diff --git a/filter/source/msfilter/svdfppt.cxx 
b/filter/source/msfilter/svdfppt.cxx
index 5f74aa47eea2..cb6381fb6fd3 100644
--- a/filter/source/msfilter/svdfppt.cxx
+++ b/filter/source/msfilter/svdfppt.cxx
@@ -1677,7 +1677,7 @@ SdrPowerPointImport::~SdrPowerPointImport()
     m_pNotePages.reset();
 }
 
-bool PPTConvertOCXControls::ReadOCXStream( rtl::Reference<SotStorage>& rSrc,
+bool PPTConvertOCXControls::ReadOCXStream( tools::SvRef<SotStorage>& rSrc,
         css::uno::Reference< css::drawing::XShape > *pShapeRef )
 {
     bool bRes = false;
@@ -1856,14 +1856,14 @@ rtl::Reference<SdrObject> 
SdrPowerPointImport::ImportOLE( sal_uInt32 nOLEId,
             {
                 pDest->Seek(0);
                 Storage* pObjStor = new Storage(*pDest, false);
-                rtl::Reference<SotStorage> xObjStor(new SotStorage(pObjStor));
+                tools::SvRef<SotStorage> xObjStor( new SotStorage( pObjStor ) 
);
                 if ( xObjStor.is() && !xObjStor->GetError() )
                 {
                     if ( xObjStor->GetClassName() == SvGlobalName() )
                     {
                         xObjStor->SetClass( SvGlobalName( 
pObjStor->GetClassId() ), pObjStor->GetFormat(), pObjStor->GetUserName() );
                     }
-                    rtl::Reference<SotStorageStream> xSrcTst = 
xObjStor->OpenSotStream("Ole");
+                    tools::SvRef<SotStorageStream> xSrcTst = 
xObjStor->OpenSotStream( "Ole" );
                     if ( xSrcTst.is() )
                     {
                         sal_uInt8 aTestA[ 10 ];
@@ -1914,7 +1914,7 @@ rtl::Reference<SdrObject> SdrPowerPointImport::ImportOLE( 
sal_uInt32 nOLEId,
                                 const css::uno::Reference < 
css::embed::XStorage >& rStorage = rOe.pShell->GetStorage();
                                 if (rStorage.is())
                                 {
-                                    rtl::Reference<SotStorage> xTarget = 
SotStorage::OpenOLEStorage(rStorage, aNm, StreamMode::READWRITE);
+                                    tools::SvRef<SotStorage> xTarget = 
SotStorage::OpenOLEStorage(rStorage, aNm, StreamMode::READWRITE);
                                     if (xObjStor.is() && xTarget.is())
                                     {
                                         xObjStor->CopyTo(xTarget.get());
@@ -2035,16 +2035,16 @@ void SdrPowerPointImport::SeekOle( SfxObjectShell* 
pShell, sal_uInt32 nFilterOpt
                     std::unique_ptr<SvMemoryStream> pBas = ImportExOleObjStg( 
nPersistPtr, nOleId );
                     if ( pBas )
                     {
-                        rtl::Reference<SotStorage> xSource(new 
SotStorage(pBas.release(), true));
-                        rtl::Reference<SotStorage> xDest( new SotStorage( new 
SvMemoryStream(), true ) );
+                        tools::SvRef<SotStorage> xSource( new SotStorage( 
pBas.release(), true ) );
+                        tools::SvRef<SotStorage> xDest( new SotStorage( new 
SvMemoryStream(), true ) );
                         if ( xSource.is() && xDest.is() )
                         {
                             // is this a visual basic storage ?
-                            rtl::Reference<SotStorage> xSubStorage = 
xSource->OpenSotStorage( "VBA",
+                            tools::SvRef<SotStorage> xSubStorage = 
xSource->OpenSotStorage( "VBA",
                                 StreamMode::READWRITE | StreamMode::NOCREATE | 
StreamMode::SHARE_DENYALL );
                             if( xSubStorage.is() && ( ERRCODE_NONE == 
xSubStorage->GetError() ) )
                             {
-                                rtl::Reference<SotStorage> xMacros = 
xDest->OpenSotStorage( "MACROS" );
+                                tools::SvRef<SotStorage> xMacros = 
xDest->OpenSotStorage( "MACROS" );
                                 if ( xMacros.is() )
                                 {
                                     SvStorageInfoList aList;
@@ -2063,13 +2063,13 @@ void SdrPowerPointImport::SeekOle( SfxObjectShell* 
pShell, sal_uInt32 nFilterOpt
                                         uno::Reference < embed::XStorage > 
xDoc( pShell->GetStorage() );
                                         if ( xDoc.is() )
                                         {
-                                            rtl::Reference<SotStorage> xVBA = 
SotStorage::OpenOLEStorage( xDoc, SvxImportMSVBasic::GetMSBasicStorageName() );
+                                            tools::SvRef<SotStorage> xVBA = 
SotStorage::OpenOLEStorage( xDoc, SvxImportMSVBasic::GetMSBasicStorageName() );
                                             if ( xVBA.is() && ( 
xVBA->GetError() == ERRCODE_NONE ) )
                                             {
-                                                rtl::Reference<SotStorage> 
xSubVBA = xVBA->OpenSotStorage( "_MS_VBA_Overhead" );
+                                                tools::SvRef<SotStorage> 
xSubVBA = xVBA->OpenSotStorage( "_MS_VBA_Overhead" );
                                                 if ( xSubVBA.is() && ( 
xSubVBA->GetError() == ERRCODE_NONE ) )
                                                 {
-                                                    
rtl::Reference<SotStorageStream> xOriginal = xSubVBA->OpenSotStream( 
"_MS_VBA_Overhead2" );
+                                                    
tools::SvRef<SotStorageStream> xOriginal = xSubVBA->OpenSotStream( 
"_MS_VBA_Overhead2" );
                                                     if ( xOriginal.is() && ( 
xOriginal->GetError() == ERRCODE_NONE ) )
                                                     {
                                                         if ( nPersistPtr && ( 
nPersistPtr < m_nPersistPtrCnt ) )
diff --git a/filter/source/msfilter/svxmsbas2.cxx 
b/filter/source/msfilter/svxmsbas2.cxx
index 71ac50fd3928..8a4ce43f1914 100644
--- a/filter/source/msfilter/svxmsbas2.cxx
+++ b/filter/source/msfilter/svxmsbas2.cxx
@@ -33,7 +33,7 @@ ErrCode SvxImportMSVBasic::SaveOrDelMSVBAStorage( bool 
bSaveInto,
     ErrCode nRet = ERRCODE_NONE;
     uno::Reference < embed::XStorage > xSrcRoot( rDocSh.GetStorage() );
     OUString aDstStgName( GetMSBasicStorageName() );
-    rtl::Reference<SotStorage> xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot, 
aDstStgName,
+    tools::SvRef<SotStorage> xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot, 
aDstStgName,
                                 StreamMode::READWRITE | StreamMode::NOCREATE | 
StreamMode::SHARE_DENYALL ) );
     if( xVBAStg.is() && !xVBAStg->GetError() )
     {
@@ -45,8 +45,8 @@ ErrCode SvxImportMSVBasic::SaveOrDelMSVBAStorage( bool 
bSaveInto,
             if( pBasicMan && pBasicMan->IsBasicModified() )
                 nRet = ERRCODE_SVX_MODIFIED_VBASIC_STORAGE;
 #endif
-            rtl::Reference<SotStorage> xSrc = SotStorage::OpenOLEStorage( 
xSrcRoot, aDstStgName, StreamMode::STD_READ );
-            rtl::Reference<SotStorage> xDst = xRoot->OpenSotStorage( 
rStorageName, StreamMode::READWRITE | StreamMode::TRUNC );
+            tools::SvRef<SotStorage> xSrc = SotStorage::OpenOLEStorage( 
xSrcRoot, aDstStgName, StreamMode::STD_READ );
+            tools::SvRef<SotStorage> xDst = xRoot->OpenSotStorage( 
rStorageName, StreamMode::READWRITE | StreamMode::TRUNC );
             xSrc->CopyTo( xDst.get() );
             xDst->Commit();
             ErrCode nError = xDst->GetError();
@@ -65,7 +65,7 @@ ErrCode SvxImportMSVBasic::SaveOrDelMSVBAStorage( bool 
bSaveInto,
 ErrCode SvxImportMSVBasic::GetSaveWarningOfMSVBAStorage( SfxObjectShell 
&rDocSh)
 {
     uno::Reference < embed::XStorage > xSrcRoot( rDocSh.GetStorage() );
-    rtl::Reference<SotStorage> xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot, 
GetMSBasicStorageName(),
+    tools::SvRef<SotStorage> xVBAStg( SotStorage::OpenOLEStorage( xSrcRoot, 
GetMSBasicStorageName(),
                     StreamMode::READ | StreamMode::NOCREATE | 
StreamMode::SHARE_DENYALL ));
     return ( xVBAStg.is() && !xVBAStg->GetError() )
                     ? ERRCODE_SVX_VBASIC_STORAGE_EXIST
diff --git a/include/editeng/svxacorr.hxx b/include/editeng/svxacorr.hxx
index d8d0c3ec499c..f71af87bc5b8 100644
--- a/include/editeng/svxacorr.hxx
+++ b/include/editeng/svxacorr.hxx
@@ -24,7 +24,6 @@
 #include <o3tl/typed_flags_set.hxx>
 #include <o3tl/string_view.hxx>
 #include <i18nlangtag/languagetag.hxx>
-#include <rtl/ref.hxx>
 #include <tools/time.hxx>
 #include <tools/date.hxx>
 #include <editeng/swafopt.hxx>
@@ -200,10 +199,10 @@ class EDITENG_DLLPUBLIC SvxAutoCorrectLanguageLists
     bool IsFileChanged_Imp();
     void LoadXMLExceptList_Imp( std::unique_ptr<SvStringsISortDtor>& rpLst,
                                 const OUString& sStrmName,
-                                rtl::Reference<SotStorage>& rStg);
+                                tools::SvRef<SotStorage>& rStg);
     static void SaveExceptList_Imp( const SvStringsISortDtor& rLst,
                                 const OUString& sStrmName,
-                                rtl::Reference<SotStorage> const & rStg,
+                                tools::SvRef<SotStorage> const & rStg,
                                 bool bConvert = false);
 
     bool MakeBlocklist_Imp( SotStorage& rStg );
diff --git a/include/filter/msfilter/msdffimp.hxx 
b/include/filter/msfilter/msdffimp.hxx
index 7be2fe6eef87..7f2c5a2763d0 100644
--- a/include/filter/msfilter/msdffimp.hxx
+++ b/include/filter/msfilter/msdffimp.hxx
@@ -535,7 +535,7 @@ protected:
 // the following method needs to be overridden for the import of OLE objects
     virtual bool GetOLEStorageName( sal_uInt32 nOLEId,
                                       OUString& rStorageName,
-                                      rtl::Reference<SotStorage>& rSrcStorage,
+                                      tools::SvRef<SotStorage>& rSrcStorage,
                                       css::uno::Reference < 
css::embed::XStorage >& xDestStg
                                     ) const;
 
@@ -630,7 +630,7 @@ public:
     static bool         ConvertToOle2( SvStream& rStm,
                                        sal_uInt32 nLen,
                                        const GDIMetaFile*,
-                                       const rtl::Reference<SotStorage> & 
rDest );
+                                       const tools::SvRef<SotStorage> & rDest 
);
 
     void SetModel(SdrModel* pModel, tools::Long nApplicationScale);
     SdrModel*  GetModel() const { return pSdrModel; }
@@ -718,7 +718,7 @@ public:
     static rtl::Reference<SdrOle2Obj> CreateSdrOLEFromStorage(
         SdrModel& rSdrModel,
         const OUString& rStorageName,
-        rtl::Reference<SotStorage> const & rSrcStorage,
+        tools::SvRef<SotStorage> const & rSrcStorage,
         const css::uno::Reference < css::embed::XStorage >& xDestStg,
         const Graphic& rGraf,
         const tools::Rectangle& rBoundRect,
diff --git a/include/filter/msfilter/svdfppt.hxx 
b/include/filter/msfilter/svdfppt.hxx
index 4affb12a4649..9c515615e0af 100644
--- a/include/filter/msfilter/svdfppt.hxx
+++ b/include/filter/msfilter/svdfppt.hxx
@@ -655,7 +655,7 @@ public:
                                 SvxMSDffSolverContainer* pSolverContainer,
                                 std::vector<rtl::Reference<SdrObject>>& 
rBackgroundColoredObjects
                             );
-    virtual bool ReadFormControl( rtl::Reference<SotStorage>& rSrc1, 
css::uno::Reference< css::form::XFormComponent > & rFormComp ) const = 0;
+    virtual bool ReadFormControl( tools::SvRef<SotStorage>& rSrc1, 
css::uno::Reference< css::form::XFormComponent > & rFormComp ) const = 0;
 };
 
 struct PPTTextParagraphStyleAtomInterpreter
@@ -1285,7 +1285,7 @@ public:
         ePageKind               ( ePKind ),
         mpPPTImporter           ( pPPTImporter )
     {};
-    bool ReadOCXStream( rtl::Reference<SotStorage>& rSrc1,
+    bool ReadOCXStream( tools::SvRef<SotStorage>& rSrc1,
         css::uno::Reference<css::drawing::XShape > *pShapeRef );
     virtual bool InsertControl(
         const css::uno::Reference< css::form::XFormComponent > &rFComp,
diff --git a/include/filter/msfilter/svxmsbas.hxx 
b/include/filter/msfilter/svxmsbas.hxx
index 7d4578e98037..304191ab7950 100644
--- a/include/filter/msfilter/svxmsbas.hxx
+++ b/include/filter/msfilter/svxmsbas.hxx
@@ -64,7 +64,7 @@ public:
     static OUString GetMSBasicStorageName();
 
 private:
-    rtl::Reference<SotStorage> xRoot;
+    tools::SvRef<SotStorage> xRoot;
     SfxObjectShell& rDocSh;
 };
 
diff --git a/include/oox/ole/olehelper.hxx b/include/oox/ole/olehelper.hxx
index 256896193903..a2810460bcd3 100644
--- a/include/oox/ole/olehelper.hxx
+++ b/include/oox/ole/olehelper.hxx
@@ -25,9 +25,9 @@
 #include <oox/dllapi.h>
 #include <oox/helper/binarystreambase.hxx>
 #include <oox/helper/graphichelper.hxx>
-#include <rtl/ref.hxx>
 #include <rtl/ustring.hxx>
 #include <sal/types.h>
+#include <tools/ref.hxx>
 #include <memory>
 
 namespace com::sun::star {
@@ -183,10 +183,10 @@ protected:
 public:
     MSConvertOCXControls( const css::uno::Reference< css::frame::XModel >& 
rxModel );
     virtual ~MSConvertOCXControls() override;
-    bool ReadOCXStorage( rtl::Reference<SotStorage> const & rSrc1, 
css::uno::Reference< css::form::XFormComponent > & rxFormComp );
-    bool ReadOCXCtlsStream(rtl::Reference<SotStorageStream> const & rSrc1, 
css::uno::Reference< css::form::XFormComponent > & rxFormComp,
+    bool ReadOCXStorage( tools::SvRef<SotStorage> const & rSrc1, 
css::uno::Reference< css::form::XFormComponent > & rxFormComp );
+    bool ReadOCXCtlsStream(tools::SvRef<SotStorageStream> const & rSrc1, 
css::uno::Reference< css::form::XFormComponent > & rxFormComp,
                                    sal_Int32 nPos, sal_Int32 nSize );
-    static bool WriteOCXStream( const css::uno::Reference< css::frame::XModel 
>& rxModel, rtl::Reference<SotStorage> const &rSrc1, const css::uno::Reference< 
css::awt::XControlModel > &rControlModel, const css::awt::Size& rSize,OUString 
&rName);
+    static bool WriteOCXStream( const css::uno::Reference< css::frame::XModel 
>& rxModel, tools::SvRef<SotStorage> const &rSrc1, const css::uno::Reference< 
css::awt::XControlModel > &rControlModel, const css::awt::Size& rSize,OUString 
&rName);
     static bool WriteOCXExcelKludgeStream( const css::uno::Reference< 
css::frame::XModel >& rxModel, const css::uno::Reference< 
css::io::XOutputStream >& xOutStrm, const css::uno::Reference< 
css::awt::XControlModel > &rControlModel, const css::awt::Size& rSize,OUString 
&rName);
 };
 
diff --git a/include/sfx2/event.hxx b/include/sfx2/event.hxx
index d94e839b5618..021472830ab8 100644
--- a/include/sfx2/event.hxx
+++ b/include/sfx2/event.hxx
@@ -23,12 +23,10 @@
 
 #include <ostream>
 
-#include <unotools/weakref.hxx>
 #include <sfx2/dllapi.h>
 #include <svl/hint.hxx>
 #include <unotools/eventcfg.hxx>
 #include <rtl/ustring.hxx>
-#include <sfx2/objsh.hxx>
 
 #include <com/sun/star/uno/Sequence.hxx>
 #include <com/sun/star/frame/XController2.hpp>
@@ -113,6 +111,8 @@ inline std::basic_ostream<charT, traits> & operator <<(
     }
 }
 
+class SfxObjectShell;
+
 enum class SfxEventHintId {
     NONE = 0,
     ActivateDoc,
@@ -191,7 +191,7 @@ inline std::basic_ostream<charT, traits> & operator <<(
 
 class SFX2_DLLPUBLIC SfxEventHint : public SfxHint
 {
-    unotools::WeakReference<SfxObjectShell> pObjShell;
+    SfxObjectShell*     pObjShell;
     OUString            aEventName;
     SfxEventHintId      nEventId;
 
@@ -208,7 +208,8 @@ public:
     const OUString&     GetEventName() const
                         { return aEventName; }
 
-    rtl::Reference<SfxObjectShell> GetObjShell() const { return 
pObjShell.get(); }
+    SfxObjectShell*     GetObjShell() const
+                        { return pObjShell; }
 };
 
 
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 5d98cb0409af..79f22c978dcb 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -173,7 +173,7 @@ template<class T> bool checkSfxObjectShell(const 
SfxObjectShell* pShell)
 }
 
 class SFX2_DLLPUBLIC SfxObjectShell :
-    public SfxShell, public SotObject,
+    public SfxShell, virtual public SotObject,
     public ::comphelper::IEmbeddedHelper
 {
 friend struct ModifyBlocker_Impl;
@@ -822,7 +822,7 @@ public:
     };
 
 
-typedef rtl::Reference<SfxObjectShell> SfxObjectShellRef;
+typedef tools::SvRef<SfxObjectShell> SfxObjectShellRef;
 
 class SfxObjectShellLock
 {
diff --git a/include/sot/object.hxx b/include/sot/object.hxx
index 6cd3634bd557..1657986c8490 100644
--- a/include/sot/object.hxx
+++ b/include/sot/object.hxx
@@ -22,11 +22,10 @@
 
 #include <sal/config.h>
 
-#include <cppuhelper/weak.hxx>
-#include <rtl/ref.hxx>
+#include <tools/ref.hxx>
 #include <sot/sotdllapi.h>
 
-class SOT_DLLPUBLIC SotObject : public cppu::OWeakObject
+class SOT_DLLPUBLIC SotObject : virtual public SvRefBase
 {
     sal_uInt16 nOwnerLockCount;
     bool bInClose; // TRUE, in DoClose
@@ -43,7 +42,6 @@ public:
     void OwnerLock(bool bLock);
     bool DoClose();
     bool IsInClose() const { return bInClose; }
-    oslInterlockedCount GetRefCount() const { return m_refCount; }
 
 private:
     SotObject& operator=(const SotObject&) = delete;
diff --git a/include/sot/storage.hxx b/include/sot/storage.hxx
index 2a49b4a39475..ac11340ac26d 100644
--- a/include/sot/storage.hxx
+++ b/include/sot/storage.hxx
@@ -142,9 +142,9 @@ public:
 
     // create stream with connection to Storage,
     // more or less a Parent-Child relationship
-    rtl::Reference<SotStorageStream> OpenSotStream(const OUString & rEleName,
+    tools::SvRef<SotStorageStream> OpenSotStream(const OUString & rEleName,
                                      StreamMode = StreamMode::STD_READWRITE);
-    rtl::Reference<SotStorage> OpenSotStorage(const OUString & rEleName,
+    SotStorage* OpenSotStorage(const OUString & rEleName,
                                StreamMode = StreamMode::STD_READWRITE,
                                bool transacted = true);
 
@@ -161,7 +161,7 @@ public:
     static bool IsOLEStorage(const OUString & rFileName);
     static bool IsOLEStorage(SvStream* pStream);
 
-    static rtl::Reference<SotStorage> 
OpenOLEStorage(css::uno::Reference<css::embed::XStorage> const & xStorage,
+    static SotStorage* 
OpenOLEStorage(css::uno::Reference<css::embed::XStorage> const & xStorage,
                                       OUString const & rEleName, StreamMode = 
StreamMode::STD_READWRITE);
     static SotClipboardFormatId 
GetFormatID(css::uno::Reference<css::embed::XStorage> const & xStorage);
     static sal_Int32 GetVersion(css::uno::Reference<css::embed::XStorage> 
const & xStorage);
diff --git a/include/svx/gallerybinaryengine.hxx 
b/include/svx/gallerybinaryengine.hxx
index 2f9c7ce00508..5e89b5dd756d 100644
--- a/include/svx/gallerybinaryengine.hxx
+++ b/include/svx/gallerybinaryengine.hxx
@@ -47,7 +47,7 @@ class GalleryThemeEntry;
 class SVXCORE_DLLPUBLIC GalleryBinaryEngine final : public GalleryFileStorage
 {
 private:
-    rtl::Reference<SotStorage> m_aSvDrawStorageRef;
+    tools::SvRef<SotStorage> m_aSvDrawStorageRef;
     const GalleryBinaryStorageLocations& maGalleryStorageLocations;
     GalleryObjectCollection& mrGalleryObjectCollection;
     bool mbReadOnly;
@@ -69,7 +69,7 @@ public:
     void setDestDir(const OUString& rDestDir, bool bRelative);
 
     SAL_DLLPRIVATE void ImplCreateSvDrawStorage();
-    SAL_DLLPRIVATE const rtl::Reference<SotStorage>& GetSvDrawStorage() const;
+    SAL_DLLPRIVATE const tools::SvRef<SotStorage>& GetSvDrawStorage() const;
 
     const INetURLObject& getThemeURL() const { return 
maGalleryStorageLocations.getThemeURL(); }
 
diff --git a/oox/source/ole/olehelper.cxx b/oox/source/ole/olehelper.cxx
index e5a81320156b..d953cf17f9da 100644
--- a/oox/source/ole/olehelper.cxx
+++ b/oox/source/ole/olehelper.cxx
@@ -437,7 +437,7 @@ MSConvertOCXControls::importControlFromStream( 
::oox::BinaryInputStream& rInStrm
 }
 
 bool
-MSConvertOCXControls::ReadOCXCtlsStream( rtl::Reference<SotStorageStream> 
const & rSrc1, Reference< XFormComponent > & rxFormComp,
+MSConvertOCXControls::ReadOCXCtlsStream( tools::SvRef<SotStorageStream> const 
& rSrc1, Reference< XFormComponent > & rxFormComp,
                                    sal_Int32 nPos,
                                    sal_Int32 nStreamSize)
 {
@@ -486,18 +486,18 @@ bool MSConvertOCXControls::importControlFromStream( 
::oox::BinaryInputStream& rI
     return rxFormComp.is();
 }
 
-bool MSConvertOCXControls::ReadOCXStorage( rtl::Reference<SotStorage> const & 
xOleStg,
+bool MSConvertOCXControls::ReadOCXStorage( tools::SvRef<SotStorage> const & 
xOleStg,
                                   Reference< XFormComponent > & rxFormComp )
 {
     if ( xOleStg.is() )
     {
-        rtl::Reference<SotStorageStream> pNameStream = 
xOleStg->OpenSotStream("OCXNAME", StreamMode::READ);
+        tools::SvRef<SotStorageStream> pNameStream = 
xOleStg->OpenSotStream("OCXNAME", StreamMode::READ);
         BinaryXInputStream aNameStream( Reference< XInputStream >( new 
utl::OSeekableInputStreamWrapper( *pNameStream ) ), true );
 
-        rtl::Reference<SotStorageStream> pContents = 
xOleStg->OpenSotStream("contents", StreamMode::READ);
-e 
... etc. - the rest is truncated

Reply via email to