![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hello guys..
I have an issue with one of the apps that connects to Outlook to retrieve calendar information. It is a windows app that displays calendar and recent mail items. Here is the sample code using Microsoft.Office.Interop.Outlook; public class OutlookSource { private Application outlookApp; private NameSpace outlookNS; public void OutlookSource { outlookApp = new Application(); outlookNS = outlookApp.GetNamespace("MAPI"); //do some work here } } What above code does is that it launches outlook in the background. When users actually launch outlook, the ThisApplication_Startup event does not get fired. None of the plugins get activated. Is there a workaround for this? Sanjay |
Ads |
#2
|
|||
|
|||
![]()
Startup event gets fired when when the first app launches Outlook. When user
double clicks on the Outlook icon on the desktop, the already running instance of Outlook simply displays a new Explorer. I suspect the reason why your code does not work is because you always assume on startup that there is at least one explorer visible where you can add your buttons (which is not the case obviously)and you do not trap the Application.Explorers.NewExplorer event. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Sanjay" wrote in message oups.com... Hello guys.. I have an issue with one of the apps that connects to Outlook to retrieve calendar information. It is a windows app that displays calendar and recent mail items. Here is the sample code using Microsoft.Office.Interop.Outlook; public class OutlookSource { private Application outlookApp; private NameSpace outlookNS; public void OutlookSource { outlookApp = new Application(); outlookNS = outlookApp.GetNamespace("MAPI"); //do some work here } } What above code does is that it launches outlook in the background. When users actually launch outlook, the ThisApplication_Startup event does not get fired. None of the plugins get activated. Is there a workaround for this? Sanjay |
#3
|
|||
|
|||
![]()
Dmitry,
Thanks for your quick response... It seems the application_startup event is not fired when the first app is launched. This app establishes a mapi session and reads email from the default profile. Then when user launches Outlook, the Application_startup event in the VSTO plugin is fired. Then when the user closes outlook, Application_Shutdown event is fired. Then when the user restarts it, the application_startup event is ignored. I am using VS2005 + VSTO + C# + Outlook 2003 SP2 (11.8030.8107). Is there a way around this issue? Sanjay On Jan 26, 12:15 pm, "Dmitry Streblechenko" wrote: Startup event gets fired when when the first app launches Outlook. When user double clicks on the Outlook icon on the desktop, the already running instance of Outlook simply displays a new Explorer. I suspect the reason why your code does not work is because you always assume on startup that there is at least one explorer visible where you can add your buttons (which is not the case obviously)and you do not trap the Application.Explorers.NewExplorer event. Dmitry Streblechenko (MVP)http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Sanjay" wrote in ooglegroups.com... Hello guys.. I have an issue with one of the apps that connects to Outlook to retrieve calendar information. It is a windows app that displays calendar and recent mail items. Here is the sample code using Microsoft.Office.Interop.Outlook; public class OutlookSource { private Application outlookApp; private NameSpace outlookNS; public void OutlookSource { outlookApp = new Application(); outlookNS = outlookApp.GetNamespace("MAPI"); //do some work here } } What above code does is that it launches outlook in the background. When users actually launch outlook, the ThisApplication_Startup event does not get fired. None of the plugins get activated. Is there a workaround for this? Sanjay- Hide quoted text -- Show quoted text - |
#4
|
|||
|
|||
![]()
VSTO uses the StartupComplete event to fire its startup event. If other code
is holding Outlook open you won't get a new StartupComplete event and therefore the VSTO addin won't start up again. There are workarounds that can be used from VB.NET or C# shared addins but none that I know of for VSTO addins. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Sanjay" wrote in message oups.com... Dmitry, Thanks for your quick response... It seems the application_startup event is not fired when the first app is launched. This app establishes a mapi session and reads email from the default profile. Then when user launches Outlook, the Application_startup event in the VSTO plugin is fired. Then when the user closes outlook, Application_Shutdown event is fired. Then when the user restarts it, the application_startup event is ignored. I am using VS2005 + VSTO + C# + Outlook 2003 SP2 (11.8030.8107). Is there a way around this issue? Sanjay |
#5
|
|||
|
|||
![]()
Ken,
Thanks for your response.. I am assuming you are talking about using the ID2Extensibility interface.. Can you please send me the workaround for that? I may have to change the code to use the shard addin's instead of vsto.. Sanjay On Jan 26, 2:15 pm, "Ken Slovak - [MVP - Outlook]" wrote: VSTO uses the StartupComplete event to fire its startup event. If other code is holding Outlook open you won't get a new StartupComplete event and therefore the VSTO addin won't start up again. There are workarounds that can be used from VB.NET or C# shared addins but none that I know of for VSTO addins. -- Ken Slovak [MVP - Outlook]http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm "Sanjay" wrote in ooglegroups.com... Dmitry, Thanks for your quick response... It seems the application_startup event is not fired when the first app is launched. This app establishes a mapi session and reads email from the default profile. Then when user launches Outlook, the Application_startup event in the VSTO plugin is fired. Then when the user closes outlook, Application_Shutdown event is fired. Then when the user restarts it, the application_startup event is ignored. I am using VS2005 + VSTO + C# + Outlook 2003 SP2 (11.8030.8107). Is there a way around this issue? Sanjay- Hide quoted text -- Show quoted text - |
#6
|
|||
|
|||
![]()
I use something like this, the code is from a C# addin template for Outlook
2007, but you can just ignore the Office 2007 specific stuff. It's a partial copy of the code in my Connect.cs class: namespace CSAddinTemplate { using System; using Extensibility; using System.Runtime.InteropServices; using System.Reflection; using System.Windows.Forms; using Outlook = Microsoft.Office.Interop.Outlook; using Office = Microsoft.Office.Core; using Microsoft.Vbe.Interop.Forms; using stdole; using System.Drawing; using System.Text; using System.Diagnostics; /// summary /// The object for implementing an Add-in. /// /summary /// see also class='IDTExtensibility2' / [GuidAttribute("B0B9C466-B680-49B6-B7E2-3EC9C9F46334"), ProgId("CSAddinTemplate.Connect")] public class Connect : Object, Extensibility.IDTExtensibility2, Office.IRibbonExtensibility, Office.ICustomTaskPaneConsumer, Outlook.FormRegionStartup { #region Module_level_declarations public static string m_ProgID = ""; // start of COM objects private object applicationObject = null; public Outlook.Application m_Outlook = null; private Outlook.NameSpace m_NameSpace = null; private Office.COMAddIn addInInstance = null; // Event-aware references to Explorers collection & ActiveExplorer private Outlook.Explorers m_Explorers = null; private Outlook.ExplorersClass m_ExplorersClass = null; private Outlook.Explorer m_Explorer = null; private Outlook.ExplorerClass m_ExplorerClass = null; // Event-aware references to Inspectors collection & ActiveInspector private Outlook.Inspectors m_InspectorClasss = null; private Outlook.InspectorsClass m_InspectorClasssClass = null; private Outlook.Inspector m_Inspector = null; private Outlook.InspectorClass m_InspectorClass = null; // end of COM objects // Explorer Wrapper Collection private System.Collections.SortedList m_ExplWrap = null; // Inspector Wrapper Collection private System.Collections.SortedList m_InspWrap = null; private int m_WrapperID = 0; private int m_OutlookVersion = 0; //Initialization flags private bool m_Teardown = false; private bool m_Init = false; //Ribbon UI object private Office.IRibbonUI m_Ribbon; //CTP objects private Office.ICTPFactory m_CTP; private Office.CustomTaskPane CTP; private const string CTP_PROGID = "CSAddinTemplate.EmailTaskPane"; private const string CTP_EXPL_PROGID = "CSAddinTemplate.CustomTaskPane"; private const string CTP_TITLE = "CS Config"; private const string CTP_EXPL_TITLE = "CS WEB"; // Form Region declarations // use the value in the name tag in the Region XML private const string TIME_TRAVEL_FORM_REGION = "TimeTravel"; private Outlook.FormRegion m_FormRegion; private TimeTravelFormRegionWrapper m_RegionWrap; #endregion /// summary /// Implements the constructor for the Add-in object. /// Place your initialization code within this method. /// /summary public Connect() { } #region Startup_Shutdown /// summary /// Implements the OnConnection method of the IDTExtensibility2 interface. /// Receives notification that the Add-in is being loaded. /// /summary /// param term='application' /// Root object of the host application. /// /param /// param term='connectMode' /// Describes how the Add-in is being loaded. /// /param /// param term='addInInst' /// Object representing this Add-in. /// /param /// seealso class='IDTExtensibility2' / public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom) { applicationObject = application; System.Windows.Forms.Application.EnableVisualStyle s(); try { addInInstance = (Office.COMAddIn)addInInst; } catch { addInInstance = null; } if (addInInstance != null) { //set module level reference to COMAddIn object try { m_Outlook = (Outlook.Application)application; m_NameSpace = m_Outlook.GetNamespace("MAPI"); //event-aware reference to Explorers collection //use NewExplorer event to watch for UI creation m_Explorers = m_Outlook.Explorers; try { //put ProgID in a module level variable m_ProgID = addInInstance.ProgId; //addInInstance.Object = Me addInInstance.GetType().InvokeMember("Object",Bind ingFlags.Public | BindingFlags.SetProperty, null, addInInst, new object[] { this }); m_Teardown = false; //Are we starting with UI? if (m_Explorers.Count 0) { m_Explorer = m_Outlook.Explorers[1]; //we have UI - initialize base class InitHandler(); if (m_Init == true) { // allot space initially for 15 open Explorers at a time m_ExplWrap = new System.Collections.SortedList(15); OutExpl adder = new OutExpl(); m_WrapperID = adder.AddExpl(m_Explorer, m_WrapperID, ref m_ExplWrap); adder = null; // allot space initially for 15 open Inspectors at a time m_InspWrap = new System.Collections.SortedList(15); } m_InspectorClasss = m_Outlook.Inspectors; m_Outlook.OptionsPagesAdd += new Microsoft.Office.Interop.Outlook.ApplicationEvents _11_OptionsPagesAddEventHandler(m_objOutlook_Optio nsPagesAdd); m_NameSpace.OptionsPagesAdd += new Microsoft.Office.Interop.Outlook.NameSpaceEvents_O ptionsPagesAddEventHandler(m_NameSpace_OptionsPage sAdd); m_Explorers.NewExplorer += new Microsoft.Office.Interop.Outlook.ExplorersEvents_N ewExplorerEventHandler(m_Explorers_NewExplorer); m_ExplorerClass = (Outlook.ExplorerClass)m_Explorer; m_ExplorerClass.ExplorerEvents_Event_Close += new Microsoft.Office.Interop.Outlook.ExplorerEvents_Cl oseEventHandler(m_Explorer_Close); m_InspectorClasss.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_ NewInspectorEventHandler(m_InspectorClasss_NewInsp ector); } else { //do nothing //monitor Explorers collection (in this module) //if NewExplorer event is raised then we have UI } } catch (Exception ex) { MessageBox.Show(ex.Message); TearDown(); } } catch (Exception ex) { MessageBox.Show(ex.Message); TearDown(); } } else TearDown(); } /// summary /// Implements the OnDisconnection method of the IDTExtensibility2 interface. /// Receives notification that the Add-in is being unloaded. /// /summary /// param term='disconnectMode' /// Describes how the Add-in is being unloaded. /// /param /// param term='custom' /// Array of parameters that are host application specific. /// /param /// seealso class='IDTExtensibility2' / public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom) { if (m_Teardown == false) TearDown(); } /// summary /// Implements the OnAddInsUpdate method of the IDTExtensibility2 interface. /// Receives notification that the collection of Add-ins has changed. /// /summary /// param term='custom' /// Array of parameters that are host application specific. /// /param /// seealso class='IDTExtensibility2' / public void OnAddInsUpdate(ref System.Array custom) { } /// summary /// Implements the OnStartupComplete method of the IDTExtensibility2 interface. /// Receives notification that the host application has completed loading. /// /summary /// param term='custom' /// Array of parameters that are host application specific. /// /param /// seealso class='IDTExtensibility2' / public void OnStartupComplete(ref System.Array custom) { // uncomment for an Explorer task pane //if (m_CTP != null) //{ // try // { // CTP = m_CTP.CreateCTP(CTP_EXPL_PROGID, CTP_EXPL_TITLE, m_Explorer); // CTP.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositi onRestrictNoChange; // CTP.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight; // CTP.Visible = true; // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } //} } /// summary /// Implements the OnBeginShutdown method of the IDTExtensibility2 interface. /// Receives notification that the host application is being unloaded. /// /summary /// param term='custom' /// Array of parameters that are host application specific. /// /param /// seealso class='IDTExtensibility2' / public void OnBeginShutdown(ref System.Array custom) { } #endregion #region utility_procedures public void InitHandler() { string sVerLeft2 = ""; string sVersion = ""; //************************************************** ****** sVersion = m_Outlook.Version; sVerLeft2 = sVersion.Substring(0, 2); switch( sVerLeft2) { case "10": m_OutlookVersion = 10; break; case "11": m_OutlookVersion = 11; break; case "12": m_OutlookVersion = 12; break; default: if ((sVerLeft2.Substring(0 , 1)) == "9") { m_OutlookVersion = 9; } else { m_OutlookVersion = 0; } break; } //set initialization flag m_Init = true; } private void TearDown() { if (m_Teardown == false) { try { if (m_ExplWrap != null) { m_ExplWrap.Clear(); m_ExplWrap = null; } if (m_InspWrap != null) { m_InspWrap.Clear(); m_InspWrap = null; } // remove the event handlers if (m_Explorers != null) { m_Explorers.NewExplorer -= new Microsoft.Office.Interop.Outlook.ExplorersEvents_N ewExplorerEventHandler(m_Explorers_NewExplorer); } if (m_InspectorClasss != null) { m_InspectorClasss.NewInspector -= new Microsoft.Office.Interop.Outlook.InspectorsEvents_ NewInspectorEventHandler(m_InspectorClasss_NewInsp ector); } //release Ribbon reference m_Ribbon = null; //release CTP references m_CTP = null; CTP = null; //release form region reference m_FormRegion = null; //release reference to Outlook objects if (m_Explorer != null) m_Explorer = null; if (m_Explorers != null) m_Explorers = null; if (m_InspectorClasss != null) m_InspectorClasss = null; if (m_Inspector != null) m_Inspector = null; if (m_ExplorersClass != null) m_ExplorersClass = null; if (m_ExplorerClass != null) m_ExplorerClass = null; if (m_InspectorClasssClass != null) m_InspectorClasssClass = null; if (m_InspectorClass != null) m_InspectorClass = null; if (m_NameSpace != null) m_NameSpace = null; if (m_Outlook != null) m_Outlook = null; if (applicationObject != null) applicationObject = null; if (addInInstance != null) addInInstance = null; m_Teardown = true; m_Init = false; GC.Collect(); GC.WaitForPendingFinalizers(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } #endregion #region explorer_related_events // NewExplorer event will be raised if there is UI private void m_Explorers_NewExplorer(Microsoft.Office.Interop.O utlook.Explorer Explorer) { //assign ActiveExplorer m_Explorer = Explorer; if (m_Init == false) { //we didn't have UI before - initialize add-in objects InitHandler(); } if (m_Init == true) { OutExpl adder = new OutExpl(); m_WrapperID = adder.AddExpl(Explorer, m_WrapperID, ref m_ExplWrap); adder = null; } } // Monitor Explorer_Close to see when UI "disappears" private void m_Explorer_Close() { //release current reference m_Explorer = null; try { m_Explorer = m_Outlook.ActiveExplorer(); } catch { if (m_Outlook.Inspectors.Count == 0) { //release add-in objects if (m_Teardown == false) TearDown(); } } } #endregion #region inspector_related_events private void m_InspectorClasss_NewInspector(Microsoft.Office.In terop.Outlook.Inspector Inspector) { //No handling of Inspectors for Notes, they are brain dead // set up to get the Class property of the item in the Inspector object item = Inspector.CurrentItem; Type _type; _type = item.GetType(); object[] _args = new Object[] { }; // dummy argument array Outlook.OlObjectClass _class = Outlook.OlObjectClass.olNote; try // try to get the Class using reflection { _class = (Outlook.OlObjectClass)_type.InvokeMember("Class", BindingFlags.Public | BindingFlags.GetField | BindingFlags.GetProperty, null, item, _args); } catch (Exception ex) { MessageBox.Show(ex.Message); _class = Outlook.OlObjectClass.olNote; } if (_class != Outlook.OlObjectClass.olNote) { m_Inspector = Inspector; try { m_InspectorClass = (Outlook.InspectorClass)m_Inspector; m_InspectorClass.InspectorEvents_Event_Close += new Microsoft.Office.Interop.Outlook.InspectorEvents_C loseEventHandler(molInspector_Close); OutInsp adder = new OutInsp(); switch (_class) { case Outlook.OlObjectClass.olMail: CTP = m_CTP.CreateCTP(CTP_PROGID, CTP_TITLE, Inspector); CTP.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositi onRestrictNoChange; CTP.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight; CTP.Visible = false; break; case Outlook.OlObjectClass.olAppointment: m_RegionWrap = new TimeTravelFormRegionWrapper(); break; default: { break; } } // m_RegionWrap and m_Ribbon are dummies, filled in when Ribbon_OnLoad and BeforeFormRegionShow fire m_WrapperID = adder.AddInsp(Inspector, m_WrapperID, _class, ref m_InspWrap, CTP, m_RegionWrap, m_Ribbon); adder = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } private void molInspector_Close() { m_Inspector = null; try { m_Inspector = m_Outlook.ActiveInspector(); } catch { if (m_Inspector == null) { if (m_Outlook.Explorers.Count == 0) { if (m_Teardown == false) { TearDown(); } } } } } #endregion -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Sanjay" wrote in message ups.com... Ken, Thanks for your response.. I am assuming you are talking about using the ID2Extensibility interface.. Can you please send me the workaround for that? I may have to change the code to use the shard addin's instead of vsto.. Sanjay |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
vsto 2003 suddenly cannot debug outlook add-in | craig spareway | Add-ins for Outlook | 0 | November 25th 06 01:35 AM |
VSTO Outlook 2003 - problem with actions | Eddie | Add-ins for Outlook | 4 | November 6th 06 05:00 PM |
Outlook 2003 and VSTO questions | Christie | Add-ins for Outlook | 0 | November 3rd 06 07:19 AM |
VSTO - Market Share of Outlook 2003 (Pro)? | Tadwick | Add-ins for Outlook | 0 | July 30th 06 05:14 AM |
VSTO Backwards compatibility with Outlook 2003 / 2007 | abcomp | Add-ins for Outlook | 1 | July 19th 06 04:14 PM |