Cancel save from a native (C++) AddIn RRS feed

  • Question

  • Cancelling a save seems like the simplest thing, but I'm completely stumped.

    I have a native, C++, AddIn. I can trap Word's BeforeSave event using an application-event listening class within my AddIn.

    When the BeforeSave invoke is sent by word, I get a DISPARRAMS pointer, which contains three arguments.

    1. The first is a reference to the document being saved. I can access the document members fine.
    2. The second argument, according to the vt value, is a boolean by reference. It allows me to cancel or show the SaveAs dialog. I can force show it like so: "*(pDispParams->rgvarg[1].pboolVal) = VARIANT_TRUE"
    3. The third argument, according to the vt value, is also a boolean by reference. It ought to allow me to cancel the save operation. However, despite using an identical syntax as above, I see no effect.

    Can anyone think why this might be? Am I missing something? I've tried setting the third argument (after de-referencing) to VARIANT_FALSE, but whatever I do seems ineffectual. I'm sure this is in-process since I can alter the appearance of the SaveAs dialog.

    Edit: Word 2007. Cough.
    • Edited by JosephFox Thursday, August 23, 2012 7:03 PM
    Thursday, August 23, 2012 6:55 PM

All replies

  • Hi JosephFox,

    Thanks for posting in the MSND Forum.

    I will involve some experts who are familiar with your issue, and this may take some time. Much appreciate for your patience and understanding.

    Best Regards,

    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    Monday, August 27, 2012 1:48 AM
  • Will look into this issue and update you.  Could you please upload your sample so that we could better research your issue?


    Friday, August 31, 2012 11:56 PM
  • CApplicationEventListener is a class in my AddIn, initialized in OnStartupComplete. It fires appropriately, whenever a document is saved.

    STDMETHODIMP CApplicationEventListener::Invoke(DISPID dispIDMember, REFIID riid, LCID lcid,
                                           WORD wFlags, DISPPARAMS* pDispParams,
                                           VARIANT* pVarResult,
                                           EXCEPINFO* pExcepInfo,
                                           UINT* puArgErr)
       //Validate arguments.
       if ((riid != IID_NULL))
          return E_INVALIDARG;
       HRESULT hr = S_OK;  // Initialize.
       switch (dispIDMember)
          case 0x00000008: // BeforeSave event
    		// Get document
    		Word::_Document *pDoc = reinterpret_cast<Word::_Document*>(pDispParams->rgvarg[0].pdispVal); 
    		// See if this is the document we're looking for
    		BSTR name = NULL;
                    // I check the name here
                    // Cancel Save
    		*(pDispParams->rgvarg[1].pboolVal) = VARIANT_FALSE; // Show SaveAs dialog?
    		*(pDispParams->rgvarg[2].pboolVal) = VARIANT_TRUE;  // Cancel save?
       return hr;
    Edit: The rest of CApplicationEventsListener is as described in this article.
    • Edited by JosephFox Saturday, September 1, 2012 10:21 AM
    Saturday, September 1, 2012 10:17 AM
  • Hello Joseph,

    I created a sample application based on the article and tested the application on multiple machines. The DocumentBeforeSave event was captured and was cancelled successfully.

    In one of the machines the Events were not getting captured. I did a repair install of Office and the issue was resolved. You can try to do a repair install of Office.

    I have shared the sample at the following location. Please note that the sample will be removed after 7 days.!107&authkey=!AM8Wjpw_t-3MWcA

    Could you please check if the sample works for you?


    Sreerenj G Nair

    Thursday, September 27, 2012 4:43 PM
  • I appreciate you taking the time to do that.

    However; no, the result is the same. The save is captured, but not cancelled. This is now on Word 2013, Windows 8 preview. I tried repairing Office.

    Thursday, October 4, 2012 4:17 PM
  • Hello JosephFox,

    This would require a more in-depth level of support and falls into the paid support category. Please visit the below link to see the various paid support options that are available to better meet your needs.;en-us;offerprophone


    Sreerenj G Nair

    Tuesday, October 9, 2012 4:29 PM