summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers/ado/ADriver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'connectivity/source/drivers/ado/ADriver.cxx')
-rw-r--r--connectivity/source/drivers/ado/ADriver.cxx20
1 files changed, 15 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()