Removing CommandBar and related objects from Outlook

N

Nate007

I've written a Com Add-In for Outlook in C#. The Add-In implments the
Extensibility.IDTExtensibility2 interface and is working nicely, but I cannot
remove the command buttons that I had added while testing the add-in.

I want to remove some CommandBarButtons from the main explorer window (the
standard 'Inbox' explorer that comes up in outlook by default). I've tried
this in both the OnDisconnection and OnBeginShutdown methods. The problem
that I'm encountering is that I can't get a reference to the Explorer object.
I've tried 2 different syntax to get the Explorer's reference:

object oActiveExplorer = this.oOutlook.ActiveExplorer();

and

object oActiveExplorer =
this.oOutlook.GetType().InvokeMember("ActiveExplorer",BindingFlags.GetProperty,null,this.oOutlook,null);

(this.oOutlook is an Outlook.Application reference to the Outlook app passed
in via the OnConnection method)

Both of these are returning null. Also, a check of the Explorers collection
showed that there were no members. I assume that this is because Outlook is
in the middle of closing at this point, and the explorer and other visual
components have been discarded already. Is this the case? If so, what is
the recommended way of cleaning up customized menus, etc?

I read about a property in Word called CustomizationContext or something to
that effect. This property tells Word where to save the customization (I
guess it would be which .dot file). I didn't see a similar type of thing in
Outlook. Did I miss it?

Perhaps Outlook is disposing of the COM Add-Ins asynchronously, so I can't
depend on a reference to the explorer being available?

Also, trying to remove them manually in Outlook doesn't work. They appear
on the list of menu items to customize, but they're dimmed out so you can't
edit them.

Anyway, I would appreciate anyone's input on this. Thanks in advance for
your help.

-Nate
 
K

Ken Slovak - [MVP - Outlook]

Use the Explorer.Close event and when you create your CommandBar object set
it to Temporary = True.

On_Disconnection will not fire if you have any Outlook objects instantiated
and by the time it fires everything Outlook related is out of scope.
 

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