Outlook new inspector event not firing

R

ramz_g

Hi,
I have developed an add-in for Outlook which adds a menu to the Outlook
menubar.
I have also registered the Outlook.NewInspector event. This event fires
without any problem when I click on "New" as soon as I open Outlook...
However, if I click on "New" after clicking on any of the items in my add-in
menu, the Outlook.NewInspector is not getting fired... Can anyone pls shed
some light on why this is happening?

Thanks,
Ram
 
K

Ken Slovak - [MVP - Outlook]

This is just a guess since you didn't show the code you use to declare the
event handler and didn't provide much information such as Outlook version or
language used.

Are you declaring an Inspectors collection object at a class level that
won't get garbage collected? If not, and I suspect the answer is no, that's
what's happening to your event handler.
 
R

ramz_g

Hi Ken,

Just as I posted this question, I found a similar problem being discussed in
a different forum.. And yes, I hadnt declared the Inspectors collection
object at the class level... After I did it, my code is working fine..

Thanks a lot for your reply...

Thanks,
Ram
 
N

Nad Cc

Hi I have the same error, Here's my code:

namespace OC_MX
{
using System;
using System.Runtime.InteropServices;
//using System.Windows.Forms;
using OCServer;
using Outlook = Microsoft.Office.Interop.Outlook;


[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"), ProgId("OutlookCRM_MX.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
#region constructor

public Connect()
{
CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");
addin = new OutlookAddin();

CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");
}
#endregion

#region AddInBasicTriggers

public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
try
{
CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");
applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
InspectorMailItem = applicationObject.Inspectors;

InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);

addin.OnConnection(application, connectMode, addInInst, ref custom);

if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");
}
catch (System.Exception ex)
{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= " + ex.Message); }
}


public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");
addin.onDisconnection();
if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");
CLogger.WriteLog(ELogLevel.INFO, "************************************************************************************************************************************************************* - End");
}

public void OnStartupComplete(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");

addin.startup();
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");
}

public void OnBeginShutdown(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");
addin.onBeginShutdown();
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");
CLogger.WriteLog(ELogLevel.INFO, "**********************************************************************************************************");
}

//event triggered when item is opened
private void Inspectors_NewInspector(Outlook.Inspector i)
{
System.Windows.Forms.MessageBox.Show("inspector");


}

#endregion

OutlookAddin addin;
private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be declared at class level. If Not, the event NewInspector may not be launched when any item is opened;
private Outlook.Application applicationObject;
private object addInInstance;
}
}

I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY ISSUES with lookout.

Can you help me please?

Thanks,
NadCC

Hi,
I have developed an add-in for Outlook which adds a menu to the Outlook
menubar.
I have also registered the Outlook.NewInspector event. This event fires
without any problem when I click on "New" as soon as I open Outlook...
However, if I click on "New" after clicking on any of the items in my add-in
menu, the Outlook.NewInspector is not getting fired... Can anyone pls shed
some light on why this is happening?

Thanks,
Ram
On Monday, December 21, 2009 11:42 AM Ken Slovak - [MVP - Outlook] wrote:
This is just a guess since you did not show the code you use to declare the
event handler and did not provide much information such as Outlook version or
language used.

Are you declaring an Inspectors collection object at a class level that
will not get garbage collected? If not, and I suspect the answer is no, that is
what is happening to your event handler.
On Monday, December 21, 2009 12:54 PM ramz_g wrote:
Hi Ken,

Just as I posted this question, I found a similar problem being discussed in
a different forum.. And yes, I hadnt declared the Inspectors collection
object at the class level... After I did it, my code is working fine..

Thanks a lot for your reply...

Thanks,
Ram

"Ken Slovak - [MVP - Outlook]" wrote:
 
N

Nad Cc

Hi I have the same error, Here's my code:

namespace OC_MX
{
using System;
using System.Runtime.InteropServices;
//using System.Windows.Forms;
using OCServer;
using Outlook = Microsoft.Office.Interop.Outlook;


[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"), ProgId("OutlookCRM_MX.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
#region constructor

public Connect()
{
CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");
addin = new OutlookAddin();

CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");
}
#endregion

#region AddInBasicTriggers

public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
try
{
CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");
applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
InspectorMailItem = applicationObject.Inspectors;

InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);

addin.OnConnection(application, connectMode, addInInst, ref custom);

if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");
}
catch (System.Exception ex)
{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= " + ex.Message); }
}


public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");
addin.onDisconnection();
if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");
CLogger.WriteLog(ELogLevel.INFO, "************************************************************************************************************************************************************* - End");
}

public void OnStartupComplete(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");

addin.startup();
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");
}

public void OnBeginShutdown(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");
addin.onBeginShutdown();
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");
CLogger.WriteLog(ELogLevel.INFO, "**********************************************************************************************************");
}

//event triggered when item is opened
private void Inspectors_NewInspector(Outlook.Inspector i)
{
System.Windows.Forms.MessageBox.Show("inspector");


}

#endregion

OutlookAddin addin;
private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be declared at class level. If Not, the event NewInspector may not be launched when any item is opened;
private Outlook.Application applicationObject;
private object addInInstance;
}
}

I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY ISSUES with lookout.

Can you help me please?

Thanks,
NadCC

Hi,
I have developed an add-in for Outlook which adds a menu to the Outlook
menubar.
I have also registered the Outlook.NewInspector event. This event fires
without any problem when I click on "New" as soon as I open Outlook...
However, if I click on "New" after clicking on any of the items in my add-in
menu, the Outlook.NewInspector is not getting fired... Can anyone pls shed
some light on why this is happening?

Thanks,
Ram
On Monday, December 21, 2009 11:42 AM Ken Slovak - [MVP - Outlook] wrote:
This is just a guess since you did not show the code you use to declare the
event handler and did not provide much information such as Outlook version or
language used.

Are you declaring an Inspectors collection object at a class level that
will not get garbage collected? If not, and I suspect the answer is no, that is
what is happening to your event handler.
On Monday, December 21, 2009 12:54 PM ramz_g wrote:
Hi Ken,

Just as I posted this question, I found a similar problem being discussed in
a different forum.. And yes, I hadnt declared the Inspectors collection
object at the class level... After I did it, my code is working fine..

Thanks a lot for your reply...

Thanks,
Ram

"Ken Slovak - [MVP - Outlook]" wrote:
namespace OC_MX

{

using System;

using System.Runtime.InteropServices;

//using System.Windows.Forms;

using OCServer;

using Outlook = Microsoft.Office.Interop.Outlook;





[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"), ProgId("OutlookCRM_MX.Connect")]

public class Connect : Object, Extensibility.IDTExtensibility2

{

#region constructor



public Connect()

{

CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");

addin = new OutlookAddin();



CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");

}

#endregion



#region AddInBasicTriggers



public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)

{

try

{

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");

applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;

addInInstance = addInInst;

InspectorMailItem = applicationObject.Inspectors;



InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);



addin.OnConnection(application, connectMode, addInInst, ref custom);



if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)

{

OnStartupComplete(ref custom);

}



CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");

}

catch (System.Exception ex)

{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= " + ex.Message); }

}





public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");

addin.onDisconnection();

if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)

{

OnBeginShutdown(ref custom);

}

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");

CLogger.WriteLog(ELogLevel.INFO, "************************************************************************************************************************************************************* - End");

}



public void OnStartupComplete(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");



addin.startup();

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");

}



public void OnBeginShutdown(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");

addin.onBeginShutdown();

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");

CLogger.WriteLog(ELogLevel.INFO, "**********************************************************************************************************");

}



//event triggered when item is opened

private void Inspectors_NewInspector(Outlook.Inspector i)

{

System.Windows.Forms.MessageBox.Show("inspector");





}



#endregion



OutlookAddin addin;

private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be declared at class level. If Not, the event NewInspector may not be launched when any item is opened;

private Outlook.Application applicationObject;

private object addInInstance;

}

}



I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY ISSUES with lookout.



Can you help me please?



Thanks,

NadCC
 
N

Nad Cc

Hi I have the same error, Here's my code:

namespace OC_MX
{
using System;
using System.Runtime.InteropServices;
//using System.Windows.Forms;
using OCServer;
using Outlook = Microsoft.Office.Interop.Outlook;


[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"), ProgId("OutlookCRM_MX.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
#region constructor

public Connect()
{
CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");
addin = new OutlookAddin();

CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");
}
#endregion

#region AddInBasicTriggers

public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
try
{
CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");
applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
InspectorMailItem = applicationObject.Inspectors;

InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);

addin.OnConnection(application, connectMode, addInInst, ref custom);

if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");
}
catch (System.Exception ex)
{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= " + ex.Message); }
}


public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");
addin.onDisconnection();
if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");
CLogger.WriteLog(ELogLevel.INFO, "************************************************************************************************************************************************************* - End");
}

public void OnStartupComplete(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");

addin.startup();
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");
}

public void OnBeginShutdown(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");
addin.onBeginShutdown();
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");
CLogger.WriteLog(ELogLevel.INFO, "**********************************************************************************************************");
}

//event triggered when item is opened
private void Inspectors_NewInspector(Outlook.Inspector i)
{
System.Windows.Forms.MessageBox.Show("inspector");


}

#endregion

OutlookAddin addin;
private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be declared at class level. If Not, the event NewInspector may not be launched when any item is opened;
private Outlook.Application applicationObject;
private object addInInstance;
}
}

I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY ISSUES with lookout.

Can you help me please?

Thanks,
NadCC

Hi,
I have developed an add-in for Outlook which adds a menu to the Outlook
menubar.
I have also registered the Outlook.NewInspector event. This event fires
without any problem when I click on "New" as soon as I open Outlook...
However, if I click on "New" after clicking on any of the items in my add-in
menu, the Outlook.NewInspector is not getting fired... Can anyone pls shed
some light on why this is happening?

Thanks,
Ram
On Monday, December 21, 2009 11:42 AM Ken Slovak - [MVP - Outlook] wrote:
This is just a guess since you did not show the code you use to declare the
event handler and did not provide much information such as Outlook version or
language used.

Are you declaring an Inspectors collection object at a class level that
will not get garbage collected? If not, and I suspect the answer is no, that is
what is happening to your event handler.
On Monday, December 21, 2009 12:54 PM ramz_g wrote:
Hi Ken,

Just as I posted this question, I found a similar problem being discussed in
a different forum.. And yes, I hadnt declared the Inspectors collection
object at the class level... After I did it, my code is working fine..

Thanks a lot for your reply...

Thanks,
Ram

"Ken Slovak - [MVP - Outlook]" wrote:
namespace OC_MX

{

using System;

using System.Runtime.InteropServices;

//using System.Windows.Forms;

using OCServer;

using Outlook = Microsoft.Office.Interop.Outlook;





[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"), ProgId("OutlookCRM_MX.Connect")]

public class Connect : Object, Extensibility.IDTExtensibility2

{

#region constructor



public Connect()

{

CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");

addin = new OutlookAddin();



CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");

}

#endregion



#region AddInBasicTriggers



public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)

{

try

{

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");

applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;

addInInstance = addInInst;

InspectorMailItem = applicationObject.Inspectors;



InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);



addin.OnConnection(application, connectMode, addInInst, ref custom);



if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)

{

OnStartupComplete(ref custom);

}



CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");

}

catch (System.Exception ex)

{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= " + ex.Message); }

}





public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");

addin.onDisconnection();

if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)

{

OnBeginShutdown(ref custom);

}

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");

CLogger.WriteLog(ELogLevel.INFO, "************************************************************************************************************************************************************* - End");

}



public void OnStartupComplete(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");



addin.startup();

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");

}



public void OnBeginShutdown(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");

addin.onBeginShutdown();

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");

CLogger.WriteLog(ELogLevel.INFO, "**********************************************************************************************************");

}



//event triggered when item is opened

private void Inspectors_NewInspector(Outlook.Inspector i)

{

System.Windows.Forms.MessageBox.Show("inspector");





}



#endregion



OutlookAddin addin;

private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be declared at class level. If Not, the event NewInspector may not be launched when any item is opened;

private Outlook.Application applicationObject;

private object addInInstance;

}

}



I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY ISSUES with lookout.



Can you help me please?



Thanks,

NadCC
namespace OC_MX

{

using System;

using System.Runtime.InteropServices;

//using System.Windows.Forms;

using OCServer;

using Outlook = Microsoft.Office.Interop.Outlook;





[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"), ProgId("OutlookCRM_MX.Connect")]

public class Connect : Object, Extensibility.IDTExtensibility2

{

#region constructor



public Connect()

{

CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");

addin = new OutlookAddin();



CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");

}

#endregion



#region AddInBasicTriggers



public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)

{

try

{

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");

applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;

addInInstance = addInInst;

InspectorMailItem = applicationObject.Inspectors;



InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);



addin.OnConnection(application, connectMode, addInInst, ref custom);



if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)

{

OnStartupComplete(ref custom);

}



CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");

}

catch (System.Exception ex)

{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= " + ex.Message); }

}





public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");

addin.onDisconnection();

if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)

{

OnBeginShutdown(ref custom);

}

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");

CLogger.WriteLog(ELogLevel.INFO, "************************************************************************************************************************************************************* - End");

}



public void OnStartupComplete(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");



addin.startup();

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");

}



public void OnBeginShutdown(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");

addin.onBeginShutdown();

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");

CLogger.WriteLog(ELogLevel.INFO, "**********************************************************************************************************");

}



//event triggered when item is opened

private void Inspectors_NewInspector(Outlook.Inspector i)

{

System.Windows.Forms.MessageBox.Show("inspector");





}



#endregion



OutlookAddin addin;

private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be declared at class level. If Not, the event NewInspector may not be launched when any item is opened;

private Outlook.Application applicationObject;

private object addInInstance;

}

}



I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY ISSUES with lookout.



Can you help me please?



Thanks,

NadCC
 
N

Nad Cc

Hi I have the same error, Here's my code:

namespace OC_MX
{
using System;
using System.Runtime.InteropServices;
//using System.Windows.Forms;
using OCServer;
using Outlook = Microsoft.Office.Interop.Outlook;


[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"), ProgId("OutlookCRM_MX.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
#region constructor

public Connect()
{
CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");
addin = new OutlookAddin();

CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");
}
#endregion

#region AddInBasicTriggers

public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
try
{
CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");
applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
InspectorMailItem = applicationObject.Inspectors;

InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);

addin.OnConnection(application, connectMode, addInInst, ref custom);

if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");
}
catch (System.Exception ex)
{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= " + ex.Message); }
}


public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");
addin.onDisconnection();
if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");
CLogger.WriteLog(ELogLevel.INFO, "************************************************************************************************************************************************************* - End");
}

public void OnStartupComplete(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");

addin.startup();
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");
}

public void OnBeginShutdown(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");
addin.onBeginShutdown();
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");
CLogger.WriteLog(ELogLevel.INFO, "**********************************************************************************************************");
}

//event triggered when item is opened
private void Inspectors_NewInspector(Outlook.Inspector i)
{
System.Windows.Forms.MessageBox.Show("inspector");


}

#endregion

OutlookAddin addin;
private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be declared at class level. If Not, the event NewInspector may not be launched when any item is opened;
private Outlook.Application applicationObject;
private object addInInstance;
}
}

I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY ISSUES with lookout.

Can you help me please?

Thanks,
NadCC

Hi,
I have developed an add-in for Outlook which adds a menu to the Outlook
menubar.
I have also registered the Outlook.NewInspector event. This event fires
without any problem when I click on "New" as soon as I open Outlook...
However, if I click on "New" after clicking on any of the items in my add-in
menu, the Outlook.NewInspector is not getting fired... Can anyone pls shed
some light on why this is happening?

Thanks,
Ram
On Monday, December 21, 2009 11:42 AM Ken Slovak - [MVP - Outlook] wrote:
This is just a guess since you did not show the code you use to declare the
event handler and did not provide much information such as Outlook version or
language used.

Are you declaring an Inspectors collection object at a class level that
will not get garbage collected? If not, and I suspect the answer is no, that is
what is happening to your event handler.
On Monday, December 21, 2009 12:54 PM ramz_g wrote:
Hi Ken,

Just as I posted this question, I found a similar problem being discussed in
a different forum.. And yes, I hadnt declared the Inspectors collection
object at the class level... After I did it, my code is working fine..

Thanks a lot for your reply...

Thanks,
Ram

"Ken Slovak - [MVP - Outlook]" wrote:
namespace OC_MX

{

using System;

using System.Runtime.InteropServices;

//using System.Windows.Forms;

using OCServer;

using Outlook = Microsoft.Office.Interop.Outlook;





[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"), ProgId("OutlookCRM_MX.Connect")]

public class Connect : Object, Extensibility.IDTExtensibility2

{

#region constructor



public Connect()

{

CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");

addin = new OutlookAddin();



CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");

}

#endregion



#region AddInBasicTriggers



public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)

{

try

{

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");

applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;

addInInstance = addInInst;

InspectorMailItem = applicationObject.Inspectors;



InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);



addin.OnConnection(application, connectMode, addInInst, ref custom);



if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)

{

OnStartupComplete(ref custom);

}



CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");

}

catch (System.Exception ex)

{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= " + ex.Message); }

}





public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");

addin.onDisconnection();

if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)

{

OnBeginShutdown(ref custom);

}

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");

CLogger.WriteLog(ELogLevel.INFO, "************************************************************************************************************************************************************* - End");

}



public void OnStartupComplete(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");



addin.startup();

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");

}



public void OnBeginShutdown(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");

addin.onBeginShutdown();

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");

CLogger.WriteLog(ELogLevel.INFO, "**********************************************************************************************************");

}



//event triggered when item is opened

private void Inspectors_NewInspector(Outlook.Inspector i)

{

System.Windows.Forms.MessageBox.Show("inspector");





}



#endregion



OutlookAddin addin;

private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be declared at class level. If Not, the event NewInspector may not be launched when any item is opened;

private Outlook.Application applicationObject;

private object addInInstance;

}

}



I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY ISSUES with lookout.



Can you help me please?



Thanks,

NadCC
namespace OC_MX

{

using System;

using System.Runtime.InteropServices;

//using System.Windows.Forms;

using OCServer;

using Outlook = Microsoft.Office.Interop.Outlook;





[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"), ProgId("OutlookCRM_MX.Connect")]

public class Connect : Object, Extensibility.IDTExtensibility2

{

#region constructor



public Connect()

{

CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");

addin = new OutlookAddin();



CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");

}

#endregion



#region AddInBasicTriggers



public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)

{

try

{

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");

applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;

addInInstance = addInInst;

InspectorMailItem = applicationObject.Inspectors;



InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);



addin.OnConnection(application, connectMode, addInInst, ref custom);



if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)

{

OnStartupComplete(ref custom);

}



CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");

}

catch (System.Exception ex)

{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= " + ex.Message); }

}





public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");

addin.onDisconnection();

if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)

{

OnBeginShutdown(ref custom);

}

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");

CLogger.WriteLog(ELogLevel.INFO, "************************************************************************************************************************************************************* - End");

}



public void OnStartupComplete(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");



addin.startup();

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");

}



public void OnBeginShutdown(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");

addin.onBeginShutdown();

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");

CLogger.WriteLog(ELogLevel.INFO, "**********************************************************************************************************");

}



//event triggered when item is opened

private void Inspectors_NewInspector(Outlook.Inspector i)

{

System.Windows.Forms.MessageBox.Show("inspector");





}



#endregion



OutlookAddin addin;

private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be declared at class level. If Not, the event NewInspector may not be launched when any item is opened;

private Outlook.Application applicationObject;

private object addInInstance;

}

}



I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY ISSUES with lookout.



Can you help me please?



Thanks,

NadCC
namespace OC_MX

{

using System;

using System.Runtime.InteropServices;

//using System.Windows.Forms;

using OCServer;

using Outlook = Microsoft.Office.Interop.Outlook;





[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"), ProgId("OutlookCRM_MX.Connect")]

public class Connect : Object, Extensibility.IDTExtensibility2

{

#region constructor



public Connect()

{

CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");

addin = new OutlookAddin();



CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");

}

#endregion



#region AddInBasicTriggers



public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)

{

try

{

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");

applicationObject = (Microsoft.Office.Interop.Outlook.Application)application;

addInInstance = addInInst;

InspectorMailItem = applicationObject.Inspectors;



InspectorMailItem.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);



addin.OnConnection(application, connectMode, addInInst, ref custom);



if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)

{

OnStartupComplete(ref custom);

}



CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");

}

catch (System.Exception ex)

{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= " + ex.Message); }

}





public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");

addin.onDisconnection();

if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)

{

OnBeginShutdown(ref custom);

}

CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");

CLogger.WriteLog(ELogLevel.INFO, "************************************************************************************************************************************************************* - End");

}



public void OnStartupComplete(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");



addin.startup();

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");

}



public void OnBeginShutdown(ref System.Array custom)

{

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");

addin.onBeginShutdown();

CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");

CLogger.WriteLog(ELogLevel.INFO, "**********************************************************************************************************");

}



//event triggered when item is opened

private void Inspectors_NewInspector(Outlook.Inspector i)

{

System.Windows.Forms.MessageBox.Show("inspector");





}



#endregion



OutlookAddin addin;

private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be declared at class level. If Not, the event NewInspector may not be launched when any item is opened;

private Outlook.Application applicationObject;

private object addInInstance;

}

}



I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY ISSUES with lookout.



Can you help me please?



Thanks,

NadCC
 
K

Ken Slovak

No need to post 4 times.

Did you bother to look at the answer the previous poster received? Your
problem has the exact same cause, you aren't declaring an Inspectors
collection object at class level and adding the event handler to that
object. So your handler goes out of scope when OnConnection() ends and your
handler gets garbage collected.




Nad Cc said:
Hi I have the same error, Here's my code:

namespace OC_MX
{
using System;
using System.Runtime.InteropServices;
//using System.Windows.Forms;
using OCServer;
using Outlook = Microsoft.Office.Interop.Outlook;


[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"),
ProgId("OutlookCRM_MX.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
#region constructor

public Connect()
{
CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");
addin = new OutlookAddin();

CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");
}
#endregion

#region AddInBasicTriggers

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
try
{
CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");
applicationObject =
(Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
InspectorMailItem = applicationObject.Inspectors;

InspectorMailItem.NewInspector += new
Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);

addin.OnConnection(application, connectMode, addInInst, ref
custom);

if (connectMode !=
Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");
}
catch (System.Exception ex)
{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception=
" + ex.Message); }
}


public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - Begin");
addin.onDisconnection();
if (disconnectMode !=
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
CLogger.WriteLog(ELogLevel.INFO, "OnDisconnection - End");
CLogger.WriteLog(ELogLevel.INFO,
"*************************************************************************************************************************************************************
- End");
}

public void OnStartupComplete(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");

addin.startup();
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");
}

public void OnBeginShutdown(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - Begin");
addin.onBeginShutdown();
CLogger.WriteLog(ELogLevel.INFO, "OnBeginShutdown - End");
CLogger.WriteLog(ELogLevel.INFO,
"**********************************************************************************************************");
}

//event triggered when item is opened
private void Inspectors_NewInspector(Outlook.Inspector i)
{
System.Windows.Forms.MessageBox.Show("inspector");


}

#endregion

OutlookAddin addin;
private Outlook.Inspectors InspectorMailItem;//InspectorMailitem
must be declared at class level. If Not, the event NewInspector may not be
launched when any item is opened;
private Outlook.Application applicationObject;
private object addInInstance;
}
}

I am using Microsoft.Office.Interop.Outlook 10.0.4504.0 FOR COMPATIBILITY
ISSUES with lookout.

Can you help me please?

Thanks,
NadCC

Hi,
I have developed an add-in for Outlook which adds a menu to the Outlook
menubar.
I have also registered the Outlook.NewInspector event. This event fires
without any problem when I click on "New" as soon as I open Outlook...
However, if I click on "New" after clicking on any of the items in my
add-in
menu, the Outlook.NewInspector is not getting fired... Can anyone pls
shed
some light on why this is happening?

Thanks,
Ram
This is just a guess since you did not show the code you use to declare
the
event handler and did not provide much information such as Outlook
version or
language used.

Are you declaring an Inspectors collection object at a class level that
will not get garbage collected? If not, and I suspect the answer is no,
that is
what is happening to your event handler.
On Monday, December 21, 2009 12:54 PM ramz_g wrote:
Hi Ken,

Just as I posted this question, I found a similar problem being
discussed in
a different forum.. And yes, I hadnt declared the Inspectors collection
object at the class level... After I did it, my code is working fine..

Thanks a lot for your reply...

Thanks,
Ram

"Ken Slovak - [MVP - Outlook]" wrote:
Submitted via EggHeadCafe - Software Developer Portal of Choice
Lucene.Net Indexing Searching Entry Level Tutorial
http://www.eggheadcafe.com/tutorial...-indexing-searching-entry-level-tutorial.aspx
 
N

nadcc

Ken Slovak - [MVP - Outlook] wrote on 12/21/2009 11:42 ET
This is just a guess since you didn't show the code you use to declare th
event handler and didn't provide much information such as Outlook version o
language used

Are you declaring an Inspectors collection object at a class level tha
won't get garbage collected? If not, and I suspect the answer is no, that'
what's happening to your event handler

Ken Slova
[MVP - Outlook
http://www.slovaktech.co
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.ht


"ramz_g" wrote in messag
news
Hi
I have developed an add-in for Outlook which adds a menu to the Outloo
menubar
I have also registered the Outlook.NewInspector event. This event fire
without any problem when I click on "New" as soon as I ope
Outlook..
However, if I click on "New" after clicking on any of the items i
m
add-i
menu, the Outlook.NewInspector is not getting fired... Can anyone pls she
some light on why this is happening

Thanks
Ra
Hi Ken

I am having the same problem. Here's my code

namespace OC_M

using System
using System.Runtime.InteropServices
using OCServer
using Outlook = Microsoft.Office.Interop.Outlook

[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D")
ProgId("OutlookCRM_MX.Connect")
public class Connect : Object, Extensibility.IDTExtensibility

#region constructo
public Connect(

CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin")
addin = new OutlookAddin()
CLogger.WriteLog(ELogLevel.INFO, "Construtor - End")

#endregio

public void OnConnection(object application, Extensibility.ext_ConnectMod
connectMode, object addInInst, ref System.Array custom

tr

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin")
applicationObject = (Microsoft.Office.Interop.Outlook.Application)application
addInInstance = addInInst
InspectorMailItem = applicationObject.Inspectors

InspectorMailItem.NewInspector += ne

Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector)

addin.OnConnection(application, connectMode, addInInst, ref custom)

if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup

OnStartupComplete(ref custom)


CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End")

catch (System.Exception ex
{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= "
ex.Message);


public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode
re
System.Array custom

addin.onDisconnection()
if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown

OnBeginShutdown(ref custom)




public void OnStartupComplete(ref System.Array custom

CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin")
addin.startup()
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End")



public void OnBeginShutdown(ref System.Array custom

//..


//event triggered when item is opene
private void Inspectors_NewInspector(Outlook.Inspector i

System.Windows.Forms.MessageBox.Show("inspector")




OutlookAddin addin
private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must b
declared at class level. If Not, the event NewInspector may not be launche
whe
any item is opened
private Outlook.Application applicationObject
private object addInInstance



I am using Microsoft.Office.Interop.outlook 10.0.4504.0 for compatibilit
reasons with lookout

Can you help me please

Thanks
nc
 
K

Ken Slovak

I don't know what else you need, you already know that you need to declare
your Inspectors collection at class level and not in your OnConnection()
code. Just do it and the even will fire correctly.

// this is at class level, before any procedures
Outlook.Inspectors whateverYouFeelLikeNamingTheInspectorsCollection = null;
// now assign your event handler to whatever you named your Inspectors
object in OnConnection()




Hi Ken,

I am having the same problem. Here's my code:

namespace OC_MX
{
using System;
using System.Runtime.InteropServices;
using OCServer;
using Outlook = Microsoft.Office.Interop.Outlook;

[GuidAttribute("33B2620D-CF67-44F3-A25D-C61B2B25A57D"),
ProgId("OutlookCRM_MX.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
#region constructor
public Connect()
{
CLogger.WriteLog(ELogLevel.INFO, "Construtor - Begin");
addin = new OutlookAddin();
CLogger.WriteLog(ELogLevel.INFO, "Construtor - End");
}
#endregion

public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
try
{
CLogger.WriteLog(ELogLevel.INFO, "OnConnection - Begin");
applicationObject =
(Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
InspectorMailItem = applicationObject.Inspectors;

InspectorMailItem.NewInspector += new

Outlook.InspectorsEvents_NewInspectorEventHandler(addin.Inspectors_NewInspector);

addin.OnConnection(application, connectMode, addInInst, ref custom);

if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}

CLogger.WriteLog(ELogLevel.INFO, "OnConnection - End");
}
catch (System.Exception ex)
{ CLogger.WriteLog(ELogLevel.ERROR, "OnConnection - Exception= "
+
ex.Message); }
}

public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode,
ref
System.Array custom)
{
addin.onDisconnection();
if (disconnectMode !=
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
}


public void OnStartupComplete(ref System.Array custom)
{
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - Begin");
addin.startup();
CLogger.WriteLog(ELogLevel.INFO, "OnStartupComplete - End");
}


public void OnBeginShutdown(ref System.Array custom)
{
//...
}

//event triggered when item is opened
private void Inspectors_NewInspector(Outlook.Inspector i)
{
System.Windows.Forms.MessageBox.Show("inspector");

}


OutlookAddin addin;
private Outlook.Inspectors InspectorMailItem;//InspectorMailitem must be
declared at class level. If Not, the event NewInspector may not be
launched
when
any item is opened;
private Outlook.Application applicationObject;
private object addInInstance;
}
}

I am using Microsoft.Office.Interop.outlook 10.0.4504.0 for compatibility
reasons with lookout.

Can you help me please?

Thanks,
nc
 
N

Nad Cc

Hi Ken,

Thank you for your quick answer and patience. the new inspector is firing but I try to add a button through this newinspector handler and the code contains commandbars, the new inspector stops firing:

here's my code:


private void Inspectors_NewInspector(Outlook.Inspector i)
{
System.Windows.Forms.MessageBox.Show("inspector");
string messageClass = "";

if (i.CurrentItem is Outlook.MailItem)
{
mitem = i.CurrentItem as Outlook.MailItem;
messageClass = mitem.MessageClass;
}

Outlook.Selection outlookSelection = applicationObject.ActiveExplorer().Selection;

/****************/
/****************/
/****************/
/****************/
try
{
oCommandBars = i.CommandBars;
}

catch (System.Exception)
{
// Outlook has the CommandBars collection on the Explorer object.
object oActiveExplorer;
oActiveExplorer = applicationObject.GetType().InvokeMember("ActiveExplorer", BindingFlags.GetProperty, null, applicationObject, null);

oCommandBars = (CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, oActiveExplorer, null);
}

// Set up a custom button on the "Standard" commandbar.
try
{
oStandardBar = oCommandBars["Standard"];
}

catch (System.Exception)
{
oStandardBar = oCommandBars["Database"];
}

/****************/
/****************/
/****************/
/****************/


if (outlookSelection.Count > 0)
{
object omissing = System.Reflection.Missing.Value;
selectedItem = outlookSelection[1];
if (selectedItem is Outlook.MailItem)
{
if (messageClass == "IPM.Note")
{
selectedmsg = (selectedItem as Outlook.MailItem);

selectedmsg.Read += new Outlook.ItemEvents_10_ReadEventHandler(Read_Mail);
selectedmsg.Open += new Outlook.ItemEvents_10_OpenEventHandler(Open_Mail);


Word.Document document = (Word.Document)i.WordEditor;
if (mxcrm == true && document.Kind.ToString().Equals("wdDocumentEmail") && this.applicationObject.ActiveExplorer().Application.Name.Equals("Outlook"))
addsendbutton();
}


}

}
}


private void Open_Mail(ref bool cancel)
{
CLogger.WriteLog(ELogLevel.INFO, "Open_Mail - Begin");
CommandBarControls controls = oStandardBar.Controls;
//remove old menus...

foreach (CommandBarControl control in controls)
{
String caption = control.Caption;
if (caption.EndsWith("MxCRM") || caption.EndsWith("Send and Upload to CRM"))
{
control.Delete(null);
}
}

try
{
addpopupandbutton();
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show("Exception= " + ex.Message);
}
CLogger.WriteLog(ELogLevel.INFO, "Open_Mail - End");
}



private void Read_Mail()
{
CLogger.WriteLog(ELogLevel.INFO, "Read_Mail - Begin");
CommandBarControls controls = oStandardBar.Controls;

//remove old menus...
foreach (CommandBarControl control in controls)
{
String caption = control.Caption;
if (caption.EndsWith("MxCRM"))
{
control.Delete(null);
}
}

CLogger.WriteLog(ELogLevel.INFO, "Read_Mail - End");

}

public CommandBars oCommandBars;
public CommandBar oStandardBar;//at class level


When I remove the part of the code surrounded by the stars /****************/, the new inspector gets fired. the same problem appears if I put the star code in openmail or read mail, then the open and read dont fire anymore. the part surrounded by /****************/ is important to add the button on the commandbar of the mailitem.

Any idea what I am missing here or doing wrong? I am very new to this field.

Thanks a lot,
Nc

Submitted via EggHeadCafe - Software Developer Portal of Choice
Simple .NET HEX PixelColor Utility
http://www.eggheadcafe.com/tutorial...f52bc1/simple-net-hex-pixelcolor-utility.aspx
 
K

Ken Slovak

I have no idea why you're accessing Explorer commandbars in NewInspector(),
and if Office 2007 or higher is involved you need to set up to use the
ribbon, unless you like the lack of discoverability in the AddIns tab.

In general you get what's called a weak object reference in NewInspector().
It really shouldn't be used except for checking .CurrentItem.Class or
MessageClass, or checking the item type. Where you get a strong object
reference is in the first Inspector.Activate() event. I always add
commandbar UI to an Inspector in that event handler.

So, why are you accessing the Explorer commandbars?




Nad Cc said:
Hi Ken,

Thank you for your quick answer and patience. the new inspector is firing
but I try to add a button through this newinspector handler and the code
contains commandbars, the new inspector stops firing:

here's my code:


private void Inspectors_NewInspector(Outlook.Inspector i)
{
System.Windows.Forms.MessageBox.Show("inspector");
string messageClass = "";

if (i.CurrentItem is Outlook.MailItem)
{
mitem = i.CurrentItem as Outlook.MailItem;
messageClass = mitem.MessageClass;
}

Outlook.Selection outlookSelection =
applicationObject.ActiveExplorer().Selection;

/****************/
/****************/
/****************/
/****************/
try
{
oCommandBars = i.CommandBars;
}

catch (System.Exception)
{
// Outlook has the CommandBars collection on the
Explorer object.
object oActiveExplorer;
oActiveExplorer =
applicationObject.GetType().InvokeMember("ActiveExplorer",
BindingFlags.GetProperty, null, applicationObject, null);

oCommandBars =
(CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars",
BindingFlags.GetProperty, null, oActiveExplorer, null);
}

// Set up a custom button on the "Standard" commandbar.
try
{
oStandardBar = oCommandBars["Standard"];
}

catch (System.Exception)
{
oStandardBar = oCommandBars["Database"];
}

/****************/
/****************/
/****************/
/****************/


if (outlookSelection.Count > 0)
{
object omissing = System.Reflection.Missing.Value;
selectedItem = outlookSelection[1];
if (selectedItem is Outlook.MailItem)
{
if (messageClass == "IPM.Note")
{
selectedmsg = (selectedItem as
Outlook.MailItem);

selectedmsg.Read += new
Outlook.ItemEvents_10_ReadEventHandler(Read_Mail);
selectedmsg.Open += new Outlook.ItemEvents_10_OpenEventHandler(Open_Mail);


Word.Document document =
(Word.Document)i.WordEditor;
if (mxcrm == true &&
document.Kind.ToString().Equals("wdDocumentEmail") &&
this.applicationObject.ActiveExplorer().Application.Name.Equals("Outlook"))
addsendbutton();
}


}

}
}


private void Open_Mail(ref bool cancel)
{
CLogger.WriteLog(ELogLevel.INFO, "Open_Mail - Begin");
CommandBarControls controls = oStandardBar.Controls;
//remove old menus...

foreach (CommandBarControl control in controls)
{
String caption = control.Caption;
if (caption.EndsWith("MxCRM") || caption.EndsWith("Send and
Upload to CRM"))
{
control.Delete(null);
}
}

try
{
addpopupandbutton();
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show("Exception= " +
ex.Message);
}
CLogger.WriteLog(ELogLevel.INFO, "Open_Mail - End");
}



private void Read_Mail()
{
CLogger.WriteLog(ELogLevel.INFO, "Read_Mail - Begin");
CommandBarControls controls = oStandardBar.Controls;

//remove old menus...
foreach (CommandBarControl control in controls)
{
String caption = control.Caption;
if (caption.EndsWith("MxCRM"))
{
control.Delete(null);
}
}

CLogger.WriteLog(ELogLevel.INFO, "Read_Mail - End");

}

public CommandBars oCommandBars;
public CommandBar oStandardBar;//at class level


When I remove the part of the code surrounded by the stars
/****************/, the new inspector gets fired. the same problem appears
if I put the star code in openmail or read mail, then the open and read
dont fire anymore. the part surrounded by /****************/ is important
to add the button on the commandbar of the mailitem.

Any idea what I am missing here or doing wrong? I am very new to this
field.

Thanks a lot,
Nc

Submitted via EggHeadCafe - Software Developer Portal of Choice
Simple .NET HEX PixelColor Utility
http://www.eggheadcafe.com/tutorial...f52bc1/simple-net-hex-pixelcolor-utility.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top