What is the call order of the Add-in initialization events in Outlook?

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

What is the call order of the Add-in initialization events in Outlook?
 
developer_cp




Posts: 48
Joined: 2016-10-28
I'm trying to perform the Uninstall, but the stuff in AddinModule_AddinInitialize and AddinModule_AddinStartupComplete are always getting called.

I have the following registered in the InitializeComponent();

            this.RegisterForAllUsers = true;
            this.SupportedApps = AddinExpress.MSO.ADXOfficeHostApp.ohaOutlook;
            this.AddinInitialize += new AddinExpress.MSO.ADXEvents_EventHandler(this.AddinModule_AddinInitialize);
            this.AddinStartupComplete += new AddinExpress.MSO.ADXEvents_EventHandler(this.AddinModule_AddinStartupComplete);
            this.AddinBeginShutdown += new AddinExpress.MSO.ADXEvents_EventHandler(this.AddinModule_AddinBeginShutdown);

            this.BeforeUninstallControls += new ADXUninstallControls_EventHandler(this.AddinModule_BeforeUninstallControls);
            this.AfterUninstallControls += new ADXUninstallControls_EventHandler(this.AddinModule_AfterUninstallControls);


I am doing all my uninstall works in BeforeUninstallControls... but whenever I try to uninstall, stuff inside my AddinStartupComplete would get call and would start fetching mails in the background.
Posted 02 Nov, 2016 12:59:32 Top
developer_cp




Posts: 48
Joined: 2016-10-28
Where can i find the BeforeUninstall and AfterUninstall hook in the VisualStudio Add-in designer? I couldn't find them in the Properties panel. Does these 2 hooks need to be added manually? And if yes, did i add them at the right location? Perhaps they should not be in the InitializeComponent()?
Posted 02 Nov, 2016 17:01:28 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello,

Click the designer surface of the add-in module and see the Properties tab. Switch to the Events view if required.


developer_cp writes:
I'm trying to perform the Uninstall, but the stuff in AddinModule_AddinInitialize and AddinModule_AddinStartupComplete are always getting called.


What do you mean by "perform the Uninstall"? Intercepting the BeforeUninstallControls and AfterUninstallControls events causes the host application to start when you unregister your add-in.


Andrei Smolin
Add-in Express Team Leader
Posted 03 Nov, 2016 04:54:41 Top
developer_cp




Posts: 48
Joined: 2016-10-28
Intercepting the BeforeUninstallControls and AfterUninstallControls events causes the host application to start when you unregister your add-in.


That seems to be exactly what's happening... What is the proper way to perform some actions during the uninstall process?
I am trying to iterate through all the MailItem and remove custom attributes that was added.

And to do that, i am currently doing that inside BeforeUninstallControls (also tried it in the AfterUninstallControls).

Should I be doing the tasks inside UninstallControls instead?
That block of code was generated by Add-in express, and the auto-generated comments mentioned not to modify it...


        #region Add-in Express automatic code
 
        // Required by Add-in Express - do not modify
        // the methods within this region

        public override void UninstallControls()
        {
            base.UninstallControls();
        }

        #endregion


PS: Why would "intercepting" the Before/AfterUninstallControls would even cause the host app to start? That logic doesn't make sense.
Posted 03 Nov, 2016 09:50:00 Top
developer_cp




Posts: 48
Joined: 2016-10-28
I've found a hack/workaround.

        public override void UninstallControls()
        {
            // Adding my custom action here into the UninstallControls.
            base.UninstallControls();
        }

        #endregion


But it still doesn't fix the fact that Before/AfterUninstallControls hooks being completely useless if it triggers the host application to start.
Posted 04 Nov, 2016 08:12:30 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello,

These events are added to let the developer to clean and delete the things that the add-in modifies and creates.

When the add-in is being uninstalled, adxregistrator.exe creates an instance of the module and invokes the ADXAddinModule.UninstallControls() method. if an event handler is specified for any or both of these events, Add-in Express host application is started. The primary goal is to delete non-temporary CommandBar controls that the add-in leaves behind. Imagine this scenario: version #1 of your add-in leaves a CommandBar button undeleted (by mistake). In this case you can handle the BeforeUninstallControls method so that the event handler adds a new CommandbarButton component to the module; Add-in Express will find that component, locate the control and delete it.

Also you can use these events to delete e.g. the folder that an Outlook Solution Module creates.

If you don't intercept these event, the host application will be started if you use a non-temporary command bar or Outlook Bar shortcut on the add-in module. Anyway, when the host application is started, your add-in is turned off by that moment.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Nov, 2016 08:29:37 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
developer_cp writes:
But it still doesn't fix the fact that Before/AfterUninstallControls hooks being completely useless if it triggers the host application to start.


Are you saying these events don't occur for you?


Andrei Smolin
Add-in Express Team Leader
Posted 04 Nov, 2016 08:30:49 Top
developer_cp




Posts: 48
Joined: 2016-10-28
I think such design is a bit weird and does not make sense?

The 2 event names suggests that they operates around the UninstallControl event that occur, which it does NOT start the host application, so I don't think they should start doing its own thing and start the host application... there is a huge flaw with the Before/After event if you start the host application:

Example:
A plugin involves parsing and modifying/adding custom mail item attributes, at start up it would begin its operations.
You try to uninstall the plugin, and try to perform the clean up work at the BeforeUninstallControls hook.
But because BeforeUninstallControls causes the host application to start, it begins accessing/parsing/modifying the mail item.
Meanwhile you try to clean up the mail items during the uninstall...


With things they are right now, the only way for a developer to perform custom action during the uninstall (WITHOUT starting host app) is to hack up the UninstallControls function auto-generated by the Add-in Express.
Posted 04 Nov, 2016 09:02:01 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
developer_cp writes:
But because BeforeUninstallControls causes the host application to start, it begins accessing/parsing/modifying the mail item.


On the contrary. When Add-in Express starts the host application, your add-in's LoadBehavior in the registry is set to 0. This effectively prevents your add-in from being loaded.

That is, you use these events (not hacks of any sort) to clean the things which you cannot clean when the add-in unloads. If the behavior that you experience differs from the description above, please let me know: I'll create a sample project that demonstrates this behavior.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Nov, 2016 09:29:31 Top
developer_cp




Posts: 48
Joined: 2016-10-28
In that case it is indeed NOT following the flow you are describing.


        public AddinModule()
        {            
            Application.EnableVisualStyles();

            InitializeComponent();
        }

        private void InitializeComponent()
        {
             // it has these hooks 
            this.RegisterForAllUsers = true;
            this.SupportedApps = AddinExpress.MSO.ADXOfficeHostApp.ohaOutlook;
            this.AddinInitialize += new AddinExpress.MSO.ADXEvents_EventHandler(this.AddinModule_AddinInitialize);
            this.AddinStartupComplete += new AddinExpress.MSO.ADXEvents_EventHandler(this.AddinModule_AddinStartupComplete);
            this.AddinBeginShutdown += new AddinExpress.MSO.ADXEvents_EventHandler(this.AddinModule_AddinBeginShutdown);

            this.OnRibbonBeforeCreate += new AddinExpress.MSO.ADXRibbonBeforeCreate_EventHandler(this.AddinModule_OnRibbonBeforeCreate);
         }


AddinInitialize, AddniStartupComplete are all getting triggered. This project was originally created using a very old version (pre 2010 or 2008?) of the Add-in Express plugin for Visual Studio 2010, we recently upgraded it to the latest with VS2015. I've also created a new dummy project just to compare whether the hooks are adding into the right place vs the old one, and they seems to be good.

Is there any flag i need to set so that the LoadBehavior would get set to 0?
Posted 04 Nov, 2016 09:41:31 Top