Removing button from Outlook on shutdown

N

Nick

Hi there,

I know this question has been asked many a time before, and I have
actually read 90% of the replies regarding it, unfortunately no solution is
working for me at the moment.

I create the button on startup and keep a reference to the
CommandBarControlPtr object. On shutdown, rather than attempting to find
the button again, I use that reference, which still has exactly the same
address as it did when it was functioning, but for some reason or another
the object is invalid.

I therefore cannot remove the button from the toolbar. I've tried in
onBeginShutdown and onDisconnection, but it's not working anywhere, the
second I touch the Delete method it freaks out. I'm sure there must be some
logical reasoning behind this, but everything I have tried upto this point
has failed to help, the object seemingly falls out of scope.

Any ideas on how I can resolve this?

Nick.
 
K

Ken Slovak - [MVP - Outlook]

If you've read all the replies you already know the answer. Both of those
events are too late and the buttons you created for the UI are already out
of scope for Outlook at that time. You need to delete the UI you created
earlier than that.

If this is an Explorer button you should be trapping the Explorer.Close()
event and attempting to delete the UI there for that Explorer. You also
should be creating the UI in the first place with the Temporary argument set
to true.
 
N

Nick

Hey Ken,

Well strangely enough I hadn't come across that solution until about an
hour ago. I've implemented the close event although I don't think I've done
it totally correct the button is now deleting as it should be. I like the
way Microsoft breaks it's own standards, fantastic.

What I'm actually doing in the Invoke event is checking the first
parameter to see if it = 61448 as this seemed to be the value around the
close event. You wouldn't happen to have any reference on the correct way
to check to see if it is the close method or not would you? Or is that the
correct way?

Thanks a million for your time it's most appreciated.

Nick.
 
K

Ken Slovak - [MVP - Outlook]

I have no idea what you're talking about related to = 61448. I don't do C++
code though.

In C# or any of the basic languages you subscribe to the Close event for the
Explorer when the NewExplorer() event of the Explorers collection fires or
for the initial Explorer you instantiate an instance of that on startup if
Application.Explorers.Count > 0. That should provide an event that will fire
when that Explorer is closing.
 
N

Nick

Hi Ken,

Oh okay, it's just it's implemented a little different in C++, you have
to use the IDispatch interface which fires all events through the same
callback. Everything seems to be working fine at the moment anyways so I'll
just give it a thorough testing and with anyluck it can stay as is.

Cheers anyway.

Nick.
 
S

SvenC

Hi Nick,
I create the button on startup and keep a reference to the
CommandBarControlPtr object. On shutdown, rather than attempting to
find the button again, I use that reference, which still has exactly
the same address as it did when it was functioning, but for some
reason or another the object is invalid.

You can create command bar controls as temporary on a command bar.
So it is not persisted and you do not need to remove it.

See the temp parameter of the Add method.
 

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