Closing Winword document thru WordAddin creates problem.
-
Hi, We have developed add in for Office 2003 suite. For Word I am able to sink DocumentOpen, DocumentChange, DocumentBeforeClose events...(and other events also). When I am trying to close Word Document from word container (I am not closing Word Application but only the document) using following code DocumentBeforeClose(IDispatch*, VARIANT_BOOL *pvtCancel) { MSWORD::_DOcumentPtr pDoc; msWordApp->get_ActiveDocument(&pDoc); pDoc->Close(); } After closing document my winword application gets crash. I want to know what could be the problem here. I have wriiten it as a Word AddIn using .Net framework(VC++). Pls suggest me. Thanks
SNI
-
Hi, We have developed add in for Office 2003 suite. For Word I am able to sink DocumentOpen, DocumentChange, DocumentBeforeClose events...(and other events also). When I am trying to close Word Document from word container (I am not closing Word Application but only the document) using following code DocumentBeforeClose(IDispatch*, VARIANT_BOOL *pvtCancel) { MSWORD::_DOcumentPtr pDoc; msWordApp->get_ActiveDocument(&pDoc); pDoc->Close(); } After closing document my winword application gets crash. I want to know what could be the problem here. I have wriiten it as a Word AddIn using .Net framework(VC++). Pls suggest me. Thanks
SNI
-
Crashing the application often is because you are using a NULL pointer. You can check for this simply by adding an if statement before you close..
I have checked with pointer and poiter is valid. But the thing is that when we close document using File-->Close (File Menu). there are two close calls are coming to winword. first that we are calling pDoc->close() and other is winword calls close when we use File-->Close (File Menu). If I open two documents and close the file then instead of closing a single document it closes both the documents and the container remain. COnclusion is there are two close calls are going but since we are opening only one document, only one document gets closed and there is no other document to close and hence crashed. Pls let me know how to handle this? Any idea if we can use IDispatch* use in DocumentBeforeClose.... or something else we can do. Actually there are two close event which winword fires and one that we are explicitely calling (this is required for our logic to work) inside DocumentBeforeClose... How can we tell winword that close has been already fired...
SNI
modified on Thursday, April 23, 2009 3:54 AM