I found a good KB article on a problem similar to this in other outlook
apps. Its at
http://support.microsoft.com/?id=830519. I think its the
same problem, although the KB article refers to Word and Excel rather
than Outlook.
I tried applying the fix in the KB article, and my custom sink helper
just never gets called. I have no idea why. Pretty sure I did it
right.
Anyone successful with this and Outlook?
Thanks,
Mike
Here is my ApplicationEventSinkHelper object:
using System;
using System.Runtime.InteropServices;
using Outlook; // The default name for a custom Word IA.
// If you use Office XP and you have the PIAs
// referenced in your project, you must change the previous line to
read:
// using Word = Microsoft.Office.Interop.Word;
//
// The following helper code attempts to work around a microsoft bug in
pre-Outlook2003.
// The problem is that the Cancel argument doesn't properly pass back in
the
// EventSend handler. See
http://support.microsoft.com/?id=830519 for
details.
//
namespace OutlookApplicationEvents
{
/// <summary>
/// Hand-grown definition of the ItemEvents interface.
/// </summary>
[InterfaceType(ComInterfaceType.InterfaceIsIDispatc h),
GuidAttribute("0006304E-0000-0000-C000-000000000046")]
public interface DOutlookApplicationEvents
{
[DispId(0x0000f002)] void ItemSend(object Item, ref bool Cancel);
[DispId(0x0000f003)] void NewMail();
[DispId(0x0000f004)] void Reminder(object Item);
[DispId(0x0000f005)] void OptionsPagesAdd(Outlook.PropertyPages
Pages);
[DispId(0x0000f006)] void Startup();
[DispId(0x0000f007)] void Quit();
}
/// <summary>
/// Custom handler to help sync the events
/// </summary>
public class OutlookAppEventHelper : DOutlookApplicationEvents,
IDisposable
{
/// <summary>
/// ctor
/// </summary>
public OutlookAppEventHelper()
{
m_oConnectionPoint = null;
m_Cookie = 0;
}
public void ItemSend(object Item, ref bool Cancel)
{
System.Diagnostics.Debug.WriteLine("Got called");
}
public void NewMail()
{
System.Diagnostics.Debug.WriteLine("Got called");
}
public void Reminder(object Item)
{
System.Diagnostics.Debug.WriteLine("Got called");
}
public void OptionsPagesAdd(Outlook.PropertyPages Pages)
{
System.Diagnostics.Debug.WriteLine("Got called");
}
public void Startup()
{
System.Diagnostics.Debug.WriteLine("Got called");
}
public void Quit()
{
System.Diagnostics.Debug.WriteLine("Got called");
}
private UCOMIConnectionPoint m_oConnectionPoint;
private int m_Cookie;
/// <summary>
/// Setup a connection
/// </summary>
/// <param name="obj"></param>
public void SetupConnection(Outlook.Application obj)
{
if (m_Cookie != 0) return;
// GUID of the DIID_ItemEvents dispinterface.
Guid guid = new Guid("{0006304E-0000-0000-C000-000000000046}"); //
events
// QI for IConnectionPointContainer.
UCOMIConnectionPointContainer oConnPointContainer =
(UCOMIConnectionPointContainer)obj;
// Find the connection point and then advise.
oConnPointContainer.FindConnectionPoint(ref guid, out
m_oConnectionPoint);
m_oConnectionPoint.Advise(this, out m_Cookie);
}
/// <summary>
/// tear down a connection
/// </summary>
public void RemoveConnection()
{
if (m_Cookie != 0)
{
m_oConnectionPoint.Unadvise(m_Cookie);
m_oConnectionPoint = null;
m_Cookie = 0;
}
}
/// <summary>
/// Dispose
/// </summary>
public void Dispose()
{
RemoveConnection();
}
}
}
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!