none
What are the arguments used in Word events (C++)? RRS feed

  • Question

  • Is there any resource detailing arguments (or DISPIDs, for that matter) from Word events? For example, I know that the BeforeDocumentSave event, using IApplicationEvents2, passes a document and two booleans. I guess the document can be cast as *IDispatch, but the booleans I can't seem to appropriately type.

     

    In my application, I am looking at handling events either through MFCs and the DISPATCH_MAP macro, or an implementation of IDispatch/IApplicationEvents2. When using MFC and the DISPATCH_MAP I am able to handle parameter-less events, but not things like BeforeDocumentSave, I pressume because I cannot get the arguments right. My best guess is:

    BEGIN_DISPATCH_MAP(MyEventSink, CCmdTarget)
            DISP_FUNCTION_ID(MyEventSink, "Quit", 2, Quit , VT_EMPTY, NULL)
            DISP_FUNCTION_ID(MyEventSink, "DocumentBeforeSave", 8, DocumentBeforeSave, VT_EMPTY, VTS_DISPATCH VTS_PBOOL VTS_PBOOL)
    END_DISPATCH_MAP()

    My Quit method fires, my BeforeDocumentSave does not.

    If I try using a custom class derived from IDispatch, I get disparrams, but am unsure of how to cast its contents (except the document, which I'm pretty sure is a IDispatch pointer). My best guess here would be to cast the two rgvargs as boolean pointers, but it doesn't like that.

    Below is what dispparams looks like, when I set up a breakpoint to trap the BeforeDocumentSave event. The argument count is three. The first argument appears to be IDispatch, but I cannot work out how to interpret the other two.

     

     


    • Edited by JosephFox Tuesday, October 18, 2011 10:10 AM Added dispparams screenshot
    Monday, October 17, 2011 1:41 PM

All replies

  • Hi JosephFox,

    Thanks for your post.

    How do you use BeforeDocumentSave() event on your side? Would you mind providing a sample code which could identify this problem? If so, we could reproduce this issue on our side.

    Have a nice day.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, October 20, 2011 9:28 AM
  • Using MFC, I've followed this walkthrough. I just updated the GUID to the ApplicationEvents2 interface.

    http://support.microsoft.com/kb/183599

     

    The other way I've tried it is with this code:

    http://social.msdn.microsoft.com/Forums/en/worddev/thread/9ad12dea-2e7e-4888-a3d4-9fac803ab718

     

    I have no preference for using either. By which I mean; I am interested in both. Comment on either is welcome, I'd like to understand more about all the mechanisms involved. That learning seems worth doing for its own sake. I don't care which ultimately gets me there.

     

    By the way, not what you asked, but in trying to get what surely must be a reference bool from the 2nd and 3rd disparrams arguments, I've tried:

                //VARIANTARG *cancelSave = pdispparams[2].rgvarg->pvarVal;
                //short *cancelSave = pdispparams[2].rgvarg->pboolVal;
                //short cancelSave = pdispparams[2].rgvarg->boolVal;
                //short *cancelSave = (short*)pdispparams[2].rgvarg; *cancelSave = 0xFFFF;

    All of which result in access violations.

    Thursday, October 20, 2011 4:00 PM