Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Closing Winword document thru WordAddin creates problem.

Closing Winword document thru WordAddin creates problem.

Scheduled Pinned Locked Moved COM
csharpc++dotnetdockerhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SNI
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • S 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

      B Offline
      B Offline
      Baltoro
      wrote on last edited by
      #2

      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..

      S 1 Reply Last reply
      0
      • B Baltoro

        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..

        S Offline
        S Offline
        SNI
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups