void ComSession::ThrowIfError( HRESULT result, IUnknown* pObjectWithError, REFIID rErrorInterface) const { if (FAILED(result)) { std::auto_ptr<std::wostringstream> msg(new std::wostringstream); DumpErrorInfo(msg.get(), pObjectWithError, rErrorInterface); throw wexception(msg->str().c_str()); } }
HRESULT CSQLCore::Init(LPCOLESTR strSQLConfig, DWORD nThreadIDNotify, DWORD cSilentThreads, DWORD cNotifyThreads) { HRESULT hr = E_FAIL; if (cSilentThreads + cNotifyThreads < 1 || cSilentThreads + cNotifyThreads > 20) // must have between 1 and 20 threads return E_INVALIDARG; m_nThreadIDNotify = nThreadIDNotify; m_cSilentThreads = cSilentThreads; m_cNotifyThreads = cNotifyThreads; // create event used to signal that ALL sql threads should exit m_hKillSQLEvent = CreateEvent(NULL, TRUE, FALSE, NULL); assert(m_hKillSQLEvent); hr = m_connection.OpenFromInitializationString(strSQLConfig); if (FAILED(hr)) { DumpErrorInfo(m_connection.m_spInit, IID_IDBInitialize, NULL); return hr; } m_hQueryNotify = CreateSemaphore(NULL, 0, MAXLONG, NULL); m_hQuerySilent = CreateSemaphore(NULL, 0, MAXLONG, NULL); m_pthdQueue = new CSQLQueueThread(m_hKillSQLEvent, this); assert (m_pthdQueue); m_pargSilentThreads = (CSQLThread **) new char[sizeof(CSQLThread *) * m_cSilentThreads]; m_pargNotifyThreads = (CSQLThread **) new char[sizeof(CSQLThread *) * m_cNotifyThreads]; DWORD i = 0; for (i = 0; i < m_cNotifyThreads; i++) { m_pargNotifyThreads[i] = new CSQLThread(m_hKillSQLEvent, true, this); } for (i = 0; i < m_cSilentThreads; i++) { m_pargSilentThreads[i] = new CSQLThread(m_hKillSQLEvent, false, this); } return hr; }
// DumpErrorInfo queries SQLOLEDB error interfaces, retrieving available // status or error information. inline void ComSession::DumpErrorInfo( IUnknown* pObjectWithError, REFIID rErrorInterface) const { DumpErrorInfo(&std::wcout, pObjectWithError, rErrorInterface); }