tags:

views:

329

answers:

2

Original post:
When Outlook is launched, the Add-In is loaded and adds a toolbar with some buttons.

toolBar = OutlookApp.ActiveExplorer().CommandBars.Add(MENU_TAG, MsoBarPosition.msoBarTop, false, true);

Everything was working fine, but now one user has his Outlook shortcut set to launch Outlook minimized.

And then OutlookApp.ActiveExplorer() return null. Is there some event I can use to catch when there is an ActiveExplorer and then add the commandbar?

OutlookApp.Explorers.NewExplorer doesn't work.

Also, when I show a messagebox before I add the CommandBar: everything works fine, even with Outlook minimized... Why?

edit:
Accessing the Explorers proprerty directly did work, as someone said in the answers. So this solves the problem for a minimized outlook... But...

One of the users does not have Outlook run minimized, and still the plugin loads before any gui is available. There are not even 1 explorer in the Explorers collection :( How is this possible?

edit 2:
I tried using a timer as suggested by 76mel, checking ActiveExplorer for null every 100ms. This adds the buttons as expected, but I can set the Picture property of the button.

I get this exception:
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

+1  A: 

Hi If there is no UI = no explorer :(

Try waiting until the Explorers.NewExplorer event fires to be able to get a CommandBars object.

Marcus

Update: Yes it looks like a timer will do the trick ok a bit hacky. So wire up a timer when you have a null ActiveExplorer and check for the ActiveExplorer onTick. Once the user pops outlook you get you atcive explorer and you can then add you tool bars.

76mel
Doesn't work, since that event isn't fired when opening the Outlook main window. Any other ideas?
Ward Werbrouck
Yes sorry, it would seem that in 2007 it does not fire. May be a timer is ther way to go .. that start on null check for the null on tick and ends when not null. I will have a play ...
76mel
When using a Timer I can't set the icons on my buttons. I get this amazing exception: "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
Ward Werbrouck
Yes I have seen that error before ... it can mean anything ! but can you send me your code showin how you set ur icons as I would like to debug through it.
76mel
Arrrh .Are are you using the thread timer class? if so that will spawn another thread ..and you need to play on the UI thread. I think the form timer class works the main thread.
76mel
Allright, I was indeed using the wrong Timer! Using the System.Windows.Forms.Timer works just fine. So I go with your answer, since it doesn't expect user action before adding the toolbar. Thanks!
Ward Werbrouck
+1  A: 

I'm not familiar with managed addins, but I found this answer. If there is no ActiveExplorer, try to access the Explorers collections directly, like in Explorers[1].

I had the same problem in my ECE and solved it by waiting for OnObjectChange callback that would be called when the user changes a folder in Outlook, and then I try to recreate the toolbar. This might roughly correspond to the FolderSwitch event in the Outlook object model.

Just my 2c.

Petr Prazak
Thanks, this solved it in the case I was talking about.But now there is another related problem. I also tried the OnObjectChange before, but it's kind of awkard since it only loads the toolbar when the user clicks something in Outlook.
Ward Werbrouck
Yes, you are right, but I think it is only a minor nuisance and users can live with that. At least in my plugin. There's still must be some kind of an event for us to react to. I'm not friend of the timer solutions.
Petr Prazak
I agree with you Petr, this is very hacky but the OOM is not very developer friendly. This technique has been around for a long time since the outlook 2000 days ..
76mel
Thanks for you input Pter, but I went with 76mel's answer. It doesn't need a user action before adding the toolbar. What if the first thing the user wants to do is use the not yet added toolbar? Doesn't seem very user friendly...
Ward Werbrouck