G
gorella
1) Created a Shared Add-In under Extensibility Projects.
2) Right mouse - Build - no errors
3) Right mouse - install - Wizards does its thing
4) Under Registry - I have only 2 entries for add-in under Outlook
MyAddIn.Connect --- Default and FileName
5) I have a message that should pop up on startup and it never does.
6) I also tried recieving a new email and nothing happens.
7) I'm using an XP w/VS .NET 2003 and Outlook 2002.
Code is below:
namespace MyAddin1
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Ol = Outlook ;
using MSO = Microsoft.Office.Core;
[GuidAttribute("BD716F7F-26AE-44C1-8C9C-E4D79373A886"),
ProgId("MyAddin1.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
private Ol.Application myApplicationObject;
private object myAddInInstance;
private Ol.MAPIFolder myInboxFolder;
public Connect()
{
}
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array
custom)
{
MessageBox.Show("Loading");
// Get the initial Application object
myApplicationObject = (Ol.Application) application;
myAddInInstance = addInInst;
//applicationObject = application;
//addInInstance = addInInst;
}
public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
try
{
if (myInboxFolder != null)
{
// Unregister Events
myInboxFolder.Items.ItemAdd +=new
Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
// Release Reference to COM Object
Marshal.ReleaseComObject ( myInboxFolder );
}
myAddInInstance = null;
// Release Outlook COM Object
if (myApplicationObject != null) Marshal.ReleaseComObject
(myApplicationObject);
// Perform a Garbage Collection
GC.Collect ();
}
catch (System.Exception ex)
{
MessageBox.Show (ex.Message);
}
}
public void OnAddInsUpdate(ref System.Array custom)
{
}
public void OnStartupComplete(ref System.Array custom)
{
try
{
MessageBox.Show("Loading");
// Get the InboxFolder Object
myInboxFolder = myApplicationObject.Session.GetDefaultFolder
(Ol.OlDefaultFolders.olFolderInbox );
// Register for ItemAdd Event
// Note: if more then 16 Items are added, the event doesn't
come.
myInboxFolder.Items.ItemAdd +=new
Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
}
catch (System.Exception ex)
{
MessageBox.Show (ex.Message);
}
}
public void OnBeginShutdown(ref System.Array custom)
{
}
private void Items_ItemAdd(object Item)
{
try
{
// Check the ItemType, could be a MeetingAccept or something
else
if (Item is Ol.MailItem )
{
// Cast to MailItem Object
Ol.MailItem myNewMail = (Ol.MailItem ) Item;
// Do something with Item
MessageBox.Show (myNewMail.Subject );
// Release COM Object
Marshal.ReleaseComObject (myNewMail);
}
}
catch (System.Exception ex)
{
MessageBox.Show (ex.Message);
}
}
}
}
2) Right mouse - Build - no errors
3) Right mouse - install - Wizards does its thing
4) Under Registry - I have only 2 entries for add-in under Outlook
MyAddIn.Connect --- Default and FileName
5) I have a message that should pop up on startup and it never does.
6) I also tried recieving a new email and nothing happens.
7) I'm using an XP w/VS .NET 2003 and Outlook 2002.
Code is below:
namespace MyAddin1
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Ol = Outlook ;
using MSO = Microsoft.Office.Core;
[GuidAttribute("BD716F7F-26AE-44C1-8C9C-E4D79373A886"),
ProgId("MyAddin1.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
private Ol.Application myApplicationObject;
private object myAddInInstance;
private Ol.MAPIFolder myInboxFolder;
public Connect()
{
}
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array
custom)
{
MessageBox.Show("Loading");
// Get the initial Application object
myApplicationObject = (Ol.Application) application;
myAddInInstance = addInInst;
//applicationObject = application;
//addInInstance = addInInst;
}
public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
try
{
if (myInboxFolder != null)
{
// Unregister Events
myInboxFolder.Items.ItemAdd +=new
Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
// Release Reference to COM Object
Marshal.ReleaseComObject ( myInboxFolder );
}
myAddInInstance = null;
// Release Outlook COM Object
if (myApplicationObject != null) Marshal.ReleaseComObject
(myApplicationObject);
// Perform a Garbage Collection
GC.Collect ();
}
catch (System.Exception ex)
{
MessageBox.Show (ex.Message);
}
}
public void OnAddInsUpdate(ref System.Array custom)
{
}
public void OnStartupComplete(ref System.Array custom)
{
try
{
MessageBox.Show("Loading");
// Get the InboxFolder Object
myInboxFolder = myApplicationObject.Session.GetDefaultFolder
(Ol.OlDefaultFolders.olFolderInbox );
// Register for ItemAdd Event
// Note: if more then 16 Items are added, the event doesn't
come.
myInboxFolder.Items.ItemAdd +=new
Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
}
catch (System.Exception ex)
{
MessageBox.Show (ex.Message);
}
}
public void OnBeginShutdown(ref System.Array custom)
{
}
private void Items_ItemAdd(object Item)
{
try
{
// Check the ItemType, could be a MeetingAccept or something
else
if (Item is Ol.MailItem )
{
// Cast to MailItem Object
Ol.MailItem myNewMail = (Ol.MailItem ) Item;
// Do something with Item
MessageBox.Show (myNewMail.Subject );
// Release COM Object
Marshal.ReleaseComObject (myNewMail);
}
}
catch (System.Exception ex)
{
MessageBox.Show (ex.Message);
}
}
}
}