summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--connectivity/source/drivers/ado/ADriver.cxx20
-rw-r--r--connectivity/source/inc/ado/ADriver.hxx2
2 files changed, 17 insertions, 5 deletions
diff --git a/connectivity/source/drivers/ado/ADriver.cxx b/connectivity/source/drivers/ado/ADriver.cxx
index 926a818eebb2..4ec59deeee36 100644
--- a/connectivity/source/drivers/ado/ADriver.cxx
+++ b/connectivity/source/drivers/ado/ADriver.cxx
@@ -45,20 +45,30 @@ using namespace com::sun::star::sdbcx;
ODriver::ODriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _xORB)
: ODriver_BASE(m_aMutex)
,m_xORB(_xORB)
+ ,mnNbCallCoInitializeExForReinit(0)
{
- if ( FAILED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)) )
+ HRESULT hr;
+ while ((hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)) == RPC_E_CHANGED_MODE)
{
+ // so we're in RPC_E_CHANGED_MODE case
+ // the pb was it was already initialized with COINIT_MULTITHREADED
+ // close this init
CoUninitialize();
- int h = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
- (void)h;
- ++h;
+ // and increment counter for dtr part
+ ++mnNbCallCoInitializeExForReinit;
+
+ // and keep on the loop if there were multi initializations
}
+ if (FAILED(hr))
+ std::abort();
}
ODriver::~ODriver()
{
CoUninitialize();
- CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
+ // Put back all the inits, if there were, before the use of ADO
+ for (int i = 0; i < mnNbCallCoInitializeExForReinit; ++i)
+ CoInitializeEx(nullptr, COINIT_MULTITHREADED);
}
void ODriver::disposing()
diff --git a/connectivity/source/inc/ado/ADriver.hxx b/connectivity/source/inc/ado/ADriver.hxx
index 22b23b4cada7..df017f2b6fa2 100644
--- a/connectivity/source/inc/ado/ADriver.hxx
+++ b/connectivity/source/inc/ado/ADriver.hxx
@@ -48,6 +48,8 @@ namespace connectivity
// for this Driver
css::uno::Reference< css::lang::XMultiServiceFactory > m_xORB;
+ // to put back all the inits with COINIT_MULTITHREADED if needed
+ int mnNbCallCoInitializeExForReinit;
public:
ODriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _xORB);