L
Levente
Hello,
I have a simple Word add-in. In the OnBeforeSave event, I need top show the
SaveAs dialog manually. If I do this AND also set the parameter pbSaveAsUI
passed to OnBeforeSave to VARIANT_TRUE (indicating that I already displayed
the SaveAs dialog and I do not want it shown again), then Word will crash
with an access violation AFTER exiting my event handler.
What I do is lilke this:
_ATL_FUNC_INFO OnDocBeforeSaveEventInfo = { CC_STDCALL, VT_EMPTY, 3,
{VT_DISPATCH, VT_BOOL | VT_BYREF, VT_BOOL | VT_BYREF} };
STDMETHODIMP CWordSink::OnDocBeforeSave(IDispatch *pDocument, VARIANT_BOOL
*pbSaveAsUI, VARIANT_BOOL *pbCancel)
{
CComQIPtr<Word::_Document> ptrDoc = pDocument;
DialogsPtr ptrDialogs = m_ptrApplication->Dialogs;
DialogPtr ptrSaveAsDlg = ptrDialogs ?
ptrDialogs->Item(wdDialogFileSaveAs) : NULL;
ptrDialogs = (IUnknown*)NULL;
if(ptrSaveAsDlg)
ptrSaveAsDlg->Show();
*pbSaveAsUI = VARIANT_FALSE;
return S_OK;
}
It only happens in WordXP and Word2003, not in Word2000. I also observed
that if I close the SaveAs dialog with Cancel, then it will not crash.
If anyone can give me some help/hints it would be greately appreciated.
Thanks a lot!
Best regards,
Levente
I have a simple Word add-in. In the OnBeforeSave event, I need top show the
SaveAs dialog manually. If I do this AND also set the parameter pbSaveAsUI
passed to OnBeforeSave to VARIANT_TRUE (indicating that I already displayed
the SaveAs dialog and I do not want it shown again), then Word will crash
with an access violation AFTER exiting my event handler.
What I do is lilke this:
_ATL_FUNC_INFO OnDocBeforeSaveEventInfo = { CC_STDCALL, VT_EMPTY, 3,
{VT_DISPATCH, VT_BOOL | VT_BYREF, VT_BOOL | VT_BYREF} };
STDMETHODIMP CWordSink::OnDocBeforeSave(IDispatch *pDocument, VARIANT_BOOL
*pbSaveAsUI, VARIANT_BOOL *pbCancel)
{
CComQIPtr<Word::_Document> ptrDoc = pDocument;
DialogsPtr ptrDialogs = m_ptrApplication->Dialogs;
DialogPtr ptrSaveAsDlg = ptrDialogs ?
ptrDialogs->Item(wdDialogFileSaveAs) : NULL;
ptrDialogs = (IUnknown*)NULL;
if(ptrSaveAsDlg)
ptrSaveAsDlg->Show();
*pbSaveAsUI = VARIANT_FALSE;
return S_OK;
}
It only happens in WordXP and Word2003, not in Word2000. I also observed
that if I close the SaveAs dialog with Cancel, then it will not crash.
If anyone can give me some help/hints it would be greately appreciated.
Thanks a lot!
Best regards,
Levente