// Sample code to produce an oo crash // Calling InsertImage twice will cause crash in OO Reference m_rRemoteSMgr; Reference m_rFrame; HRESULT InsertImage(BSTR imageName) throw() { HRESULT hr; Reference rTextViewCursor; if(!GetViewCursor(&rTextViewCursor)) return E_FAIL; Reference rPageCursor( rTextViewCursor, UNO_QUERY ); rPageCursor->jumpToFirstPage(); rPageCursor->jumpToStartOfPage(); // Query service manager for a URLTransformer interface Reference rParser(m_rRemoteSMgr->createInstance (L"com.sun.star.util.URLTransformer"), UNO_QUERY) ; if (!rParser.is()) { return E_FAIL; } // Create the command URL for insert image ::com::sun::star::util::URL url; url.Complete = rtl::OUString( L"slot:10241" ); //SID_INSERT_GRAPHIC url.Port = (short)0; // Parse the URL rParser->parseSmart(url, rtl::OUString(L"slot")); // workaround bug in dispatch url.Complete = url.Main; //Query the frame for an XDispatchProvider interface Reference rProvider(m_rFrame, UNO_QUERY); if (!rProvider.is()) return E_FAIL; // Get the dispatcher for the URL Reference rDispatcher = rProvider->queryDispatch(url, rtl::OUString(L""), 0); if(!rDispatcher.is()) { return E_FAIL; } //create a temp args and populate the value Sequence aArgs(3); PropertyValue *props = (PropertyValue *) aArgs.getArray(); props[0].Name = L"FileName"; props[0].Value <<= rtl::OUString( (wchar_t*) imageName ); props[1].Name = L"FilterName"; props[1].Value <<= rtl::OUString( L"EPS" ); props[2].Name = L"AsLink"; props[2].Value <<= (sal_Bool) true; rDispatcher->dispatch(url, aArgs); return hr; } BOOL GetViewCursor(Reference *pxViewCursor) throw() { if (!pxViewCursor ) { return FALSE; } Reference xController = m_rFrame->getController(); if (!xController.is()) { return FALSE; } Reference xModel = xController->getModel(); if (!xModel.is()) { return FALSE; } // Lock controllers to prevent user interaction xModel->lockControllers(); try { // Query controller for an XTextViewCursorSupplier interface Reference rTextViewCursorSupplier( xController, UNO_QUERY ); if (!rTextViewCursorSupplier.is()) { xModel->unlockControllers(); return FALSE; } // Query textViewCursorSUpplier for a (the?) text view cursor *pxViewCursor = rTextViewCursorSupplier->getViewCursor(); } catch (...) { } xModel->unlockControllers(); return (*pxViewCursor).is(); }