Invoking SaveAs dialog manually crashes Word

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
 
C

Cindy M.

Hi 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.
If I'm understanding correctly how you've interpreted the DocumentBeforeSave
event, then I think you need to go back and read the Help again. Setting
SaveAsUI to true should be showing the dialogbox:

SaveAsUI True to display the Save As dialog box.

I believe you want to set it to False?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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