Word Event returns no value

  • Thread starter Event Trapping using C++
  • Start date
E

Event Trapping using C++

I'm using ATL and c++ to develop an Add-in for Microsoft Word. The problem
that I'm having is that the parameters for the events that I'm trying to
capture aren't being filled with data. They're essentially null. The
problem is only happening with events that pass back more than one parameter.

The events that I am trapping are DocumentOpen, NewDocument,
DocumentBeforePrint, and DocumentBeforeSave

DocumentOpen, and NewDocument event trapping work fine.

The dispinterface is ApplicationEvents2; I've also tried using
ApplicationEvents3, and ApplicationEvents4 with the same results.


/***********************************************
* IDL for DocumentOpen, NewDocument and DocumentBeforePrint
* and DocumentBeforeSave
************************************************/
[id(0x00000004), helpcontext(0x00061a84)]
void DocumentOpen([in] Document* Doc);

[id(0x00000009), helpcontext(0x00061a88)]
void NewDocument([in] Document* Doc);

[id(0x00000007), helpcontext(0x00061a86)]
void DocumentBeforePrint(
[in] Document* Doc,
[in] VARIANT_BOOL* Cancel);

[id(0x00000008), helpcontext(0x00061a87)]
void DocumentBeforeSave(
[in] Document* Doc,
[in] VARIANT_BOOL* SaveAsUI,
[in] VARIANT_BOOL* Cancel);


/**********************************************
* Here is the SINK_MAP
***********************************************/
BEGIN_SINK_MAP(MyAddin)
SINK_ENTRY_INFO(1,__uuidof
(Word::ApplicationEvents2),4,DocumentOpen,&DocumentOpenInfo)
SINK_ENTRY_INFO(1,__uuidof(Word::ApplicationEvents2),9,NewDocument,&NewDocumentInfo)
SINK_ENTRY_INFO(1,__uuidof(Word::ApplicationEvents2),7,DocumentBeforePrint,&DocumentBeforePrintInfo)
SINK_ENTRY_INFO(1,__uuidof(Word::ApplicationEvents2),8,DocumentBeforeSave,&DocumentBeforeSaveInfo)
END_SINK_MAP()

/******************************************************
* Here are the ATL_FUNC_INFO structures I've declared
*******************************************************/
_ATL_FUNC_INFO NewDocumentInfo = {CC_STDCALL,VT_EMPTY,1,
{VT_DISPATCH|VT_BYREF}};
_ATL_FUNC_INFO DocumentBeforePrintInfo = {CC_STDCALL,VT_EMPTY,2,
{VT_DISPATCH|VT_BYREF, VT_BOOL|VT_BYREF}};
_ATL_FUNC_INFO DocumentOpenInfo = {CC_STDCALL,VT_EMPTY,1,
VT_DISPATCH|VT_BYREF}};
_ATL_FUNC_INFO DocumentBeforeSaveInfo = {CC_STDCALL,VT_EMPTY,3,
{VT_DISPATCH|VT_BYREF, VT_BOOL|VT_BYREF, VT_BOOL|VT_BYREF}};

void __stdcall MyAddin::DocumentOpen(IDispatchPtr ptr)
{
//Process DocumentOpen Event
}

void __stdcall MyAddin::NewDocument(IDispatchPtr ptr)
{
//Process NewDocument Event
}


void __stdcall MyAddin::DocumentBeforePrint(IDispatchPtr ptr, VARIANT_BOOL*
pvtCancel )
{

//The __vfPtr in ptr comes back as 0x00000000. I don't know why
}

void __stdcall MyAddin::DocumentBeforeSave(IDispatchPtr ptr, VARIANT_BOOL*
pSaveAsUI, VARIANT_BOOL* pCancel )
{
//The __vfPtr in ptr comes back as 0x00000000. I don't know why
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top