Outlook 2003 Add-in for XP Events
1 min read
In the process of building a COM Add-in for Outlook I ran into the issue of events not being fired with XP. I needed to capture the ItemAdd, ItemSend and SelectionChange events, which his was working great on my 2003 server dev box, but when installed on XP they did not fire. I tried many workarounds, but nothing was working, so I posted at OutlookCode.com and Robert Halstead was nice enough to share a work around with me.
What you have to do is add the “static” modifier to the variable declaration. It is hard to believe that I could not find this online somewhere and I hope someone with the same issue finds this post.
Here is some sample code with the workaround.
public class Connect : Object, Extensibility.IDTExtensibility2{ private static Microsoft.Office.Interop.Outlook.Items sentFolderItems; public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom) { sentFolderItems = applicationObject.Session.GetDefaultFolder(OlDefaultFolders.olFolderSentMail).Items; sentFolderItems.ItemAdd += new ItemsEvents_ItemAddEventHandler(SentItems_ItemAdd);Share: