Issue Add-in initialization when started without Explorer

Add-in Express™ Support Service
That's what is more important than anything else

Issue Add-in initialization when started without Explorer
I have some trouble getting my add-in to work when Outlook is started explorerless 
Bert Sinnema


Guest


Hi,

I have a wrapper for my Inspectors so i can save states and do operations per Inspector.
I hooked up an AddinModule_AddinInitialize event to the module:

As you can see this is where i have a dictionary where the key is the window handle and the value is the wrapper.

        void AddinModule_AddinInitialize(object sender, EventArgs e)
        {
            _Inspectors = this.OutlookApp.Inspectors;
            _InspectorWrappers = new Dictionary<IntPtr, InspectorWrapper>();
            _Inspectors.NewInspector += Inspectors_NewInspector;     
        }

        void Inspectors_NewInspector(Outlook.Inspector Inspector)
        {
            _InspectorWrappers.Add(GetOutlookWindowHandle(Inspector), new InspectorWrapper(Inspector));
            Marshal.ReleaseComObject(Inspector);
        }


Now whenever a button is pressed or an event fires i can get the right wrapper based on the window handle and do my operations specifically for that Inspector/Item:

InspectorWrapper wrapper = InspectorWrappers[GetOutlookWindowHandle(inspector)];


This all works perfectly, BUT. when I start Outlook without the explorer with one of the following use-cases this doesn't work.


  • right click the outlook icon and click new email
  • right-click a file and select: send to -> Mail recipient
  • Open an MSG file from the file system


Obviously the opening inspector is not in the Dictionary cause the New_Inspector event was not triggered. I tried to add the following in AddinModule_AddinInitialize thinking that this event will be fired when started without Explorer:




            for (int i = 0; i < _Inspectors.Count; i++)
            {
                Outlook.Inspector inspector = _Inspectors[i] as Outlook.Inspector;
                _InspectorWrappers.Add(GetOutlookWindowHandle(inspector), new InspectorWrapper(inspector));

                Marshal.ReleaseComObject(inspector);
            }


Instead it skips this step and gives me NullReferenceExceptions on the operations that try to get the wrapper out of the dictionary.
Posted 22 Apr, 2015 10:17:03 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
Bert,

All Office collections are 1-based.

SendTo | Mail Recipient starts a so called SimpleMapi inspector. It is opened modally and it doesn't produce InspectorActivate.


Andrei Smolin
Add-in Express Team Leader
Posted 22 Apr, 2015 11:13:11 Top
Bert Sinnema


Guest


Ok,

So its instantiated differently. Is there a way to catch this so i can still add it to my wrapper collection?
In a traditional VSTO add-in this is exactly how i did it and there it does work.
Posted 22 Apr, 2015 11:53:07 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
Bert,

You get such an inspector using the e.Context parameter of the PropertyChanging event of the corresponding Ribbon control.


Andrei Smolin
Add-in Express Team Leader
Posted 23 Apr, 2015 09:54:28 Top