Remove CommandBarControl problem

T

Toxter

Hello everyone,

I'm developing Word 2003 addin.

My addin adds some new menu items to Word menu bar.

Something like this:



Microsoft.Office.Core.CommandBarControl cc;



public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)

{

applicationObject = application;

addInInstance = addInInst;

try

{

Microsoft.Office.Interop.Word.Application wApp =
(Microsoft.Office.Interop.Word.Application)application;

((Microsoft.Office.Interop.Word.ApplicationEvents4_Event)wApp).Quit += new
Microsoft.Office.Interop.Word.ApplicationEvents4_QuitEventHandler(Connect_Quit);

object missing = Type.Missing;

cc =
wApp.CommandBars.ActiveMenuBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlPopup,

missing, missing, missing, false);

cc.Caption = "Call BT";

}

catch (Exception ex){}

}



void Connect_Quit()

{

try

{

Microsoft.Office.Interop.Word.Application wApp =
(Microsoft.Office.Interop.Word.Application)applicationObject;

cc.Delete(Type.Missing);

}

catch (Exception ex)

{

System.Windows.Forms.MessageBox.Show(ex.Message);

}

}





What I'm trying to do is to cleanup on Word.Quit all of my added menu items
and toolbars.

But I'm geting an exception:

Exception from HRESULT: 0x800A01A8


So my desirable scenario is:
1. Start Word;
2. Add my toolbars
3. User is working in Word;
4. Begin of Shutdown of Word;
5. Delete my toolbars;
6. Word is closed.

How can I remove all of my added controls on Word shutdown?
Thanks.
 
J

Jayme.Pechan

I'm not sure about your specific error but try putting your cleanup code in
the OnDisconnection or the OnBeginShutdown events instead.
 
T

Toxter

Hello Jayme,

Indeed I have tried that also, before posting here.
But I'm getting the same exception in OnDisconnection or the OnBeginShutdown
events.

Do you know any other solution?

Thanks.
 

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