Can ADXOutlookItemEvents be hooked to

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

Can ADXOutlookItemEvents be hooked to
 
Bert Sinnema




Posts: 55
Joined: 2015-04-16
Hi!

I am running into a problem. Probably another misread of documentation but i'll share it anyway for the community:

I seem to have a problem with the ADXOutlookItemEvents interface when connecting it to a MailItem in an inline response. While it does fire the events accordingly, I get a System.COMException when I am trying to call the ItemObj property. Since it does work with items that were connected from an Inspector I suspected that I may have forgotten to release a COM object or that I released it where I shouldn't have.

To investigate I created a small lab project with an ADXOutlookItemEvents class that I connect to the itemObject parameter in the ExplorerInlineResponse event. However, it gives me the same behaviour.

What am I doing wrong?


Built on:
ADX: 9.0.4610 Professional
VS2017: 15.7.1
Outlook 2016 O365: 1805 build 9330.2078 (16.0.9330.2073)

Code can be downloaded here

AddinModule.cs

 public partial class AddinModule : AddinExpress.MSO.ADXAddinModule
    {


        OutlookItemEvents outlookItemEvents;

        public AddinModule()
        {
            Application.EnableVisualStyles();
            InitializeComponent();
            // Please add any initialization code to the AddinInitialize event handler
        }
 
        #omitted generated code by adx

        private void AddinModule_AddinInitialize(object sender, EventArgs e)
        {
            outlookItemEvents = new OutlookItemEvents(this);
        }

        private void adxOutlookAppEvents1_ExplorerInlineResponse(object sender, object itemObject)
        {
            outlookItemEvents.ConnectTo(itemObject, true);
        }
    }


OutlookItemEvents.cs


    public class OutlookItemEvents : ADXOutlookItemEvents
    {

        public OutlookItemEvents(ADXAddinModule module) : base(module){}

        //omitted other methods for forum post

        public override void ProcessSend(ADXCancelEventArgs e)
        {

            if (ItemObj is Outlook.MailItem)// this causes a System.COMException (no longer in RCW etc.)
            {
                MessageBox.Show("SENT");
            }



            e.Cancel = true;
        }

    }
Posted 24 May, 2018 04:16:43 Top
Andrei Smolin


Add-in Express team


Posts: 15284
Joined: 2006-05-11
Hello Bert,

The issue is caused by the fact that Add-in Express releases COM objects passed to an event handler right after the event handler completes.
       private void adxOutlookAppEvents1_ExplorerInlineResponse(object sender, object itemObject) 
       { 
           outlookItemEvents.ConnectTo(itemObject, true); 
       } 


Replace this method with this one:

       private void adxOutlookAppEvents1_ExplorerInlineResponse(object sender, object itemObject) 
       { 
            Outlook.Explorer explorer = OutlookApp.ActiveExplorer();
            outlookItemEvents.ConnectTo(explorer.ActiveInlineResponse, true);
            Marshal.ReleaseComObject(explorer);
       } 


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 24 May, 2018 06:35:59 Top