MS Word

I researched Office Automation on this website and found many useful articles. The most useful was the "Building an Office2K COM addin with VC++/ATL" article by Mr. Dey. I have a dll that is used for MS Word Automation. I put a button on the toolbar which saves whatever is typed in and quits the application. I have a problem, though, after about the 3rd or 4th time of entering MS Word, MS Word will crash. I have isolated the crash to the invoke statement for the Quit:

//Invoke the Quit method
szFunction = OLESTR("Quit");
hr = m_spApp->GetIDsOfNames(IID_NULL, &szFunction, 1,

hr = m_spApp->Invoke(dispid_Quit, IID_NULL, LOCALE_USER_DEFAULT,

I am not sure what the problem is. I found an article on MSDN that has this exact same code. So why would the Invoke GPF? Could it be that I am missing the Release statements (m_spApp->Release)? I modeled my dll after the example in the article "Building an Office2K COM addin with VC++/ATL" so m_spApp is actually a private member in the .h file. HELP!

Perhaps it not in the invoke, it is somewhere else? It was suggested that I try changing "szFunction = OLESTR("Quit")" to "LPOLESTR pszFunction = new OLECHAR[5]" but this does not work either. I have found that if I change the SaveAs from ActiveDocument to the app, it will ask me if I want save the document and there is never a GPF. Could it be something other than the invoke statement? Any ideas on what I could be missing?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!