PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook Program Addins
Outlook hangs with C# Add-in
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook Program Addins
Outlook hangs with C# Add-in
![]() |
Outlook hangs with C# Add-in |
|
|
Thread Tools |
Rating:
|
|
|
#1 |
|
Guest
Posts: n/a
|
Hi all,
I'm developing an Outlook 2000 addin using VS.Net 2003 and C#. I have used as an example that articles: http://support.microsoft.com/?kbid=302901 http://msdn.microsoft.com/library/d.../odc_dnscof.asp Here are some parts of the code: namespace IceDesktop { using System; using Office; using Extensibility; using System.Runtime.InteropServices; using Outlook; /// <summary> /// The object for implementing an Add-in. /// </summary> /// <seealso class='IDTExtensibility2' /> [GuidAttribute("6EA19D09-55E9-493D-8DF2-B910115C6BE0"), ProgId("IceDesktop.Connect")] public class Connect : Object, Extensibility.IDTExtensibility2 { public Connect() { } public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom) { applicationObject = (Outlook.Application)application; addInInstance = addInInst; } public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom) { applicationObject = null; } public void OnAddInsUpdate(ref System.Array custom) { } public void OnStartupComplete(ref System.Array custom) { Init.Start(); } public void OnBeginShutdown(ref System.Array custom) { OfficeUI.DeleteIceControls(); Init.Stop(); } public static Outlook.Application applicationObject; private object addInInstance; } } ------------------------------------------------------- using System; namespace IceDesktop { public class Init { public static void Start() { bool ttt = OfficeUI.OfficeUI.CreateIceButton(Connect.applicationObject.ActiveExplorer()) } ------------------------------------------------------- using System; using System.Reflection; using Office; using Outlook; using System.Windows.Forms; namespace IceDesktop { public class OfficeUI { private static IceBase oBase = new IceBase("OfficeUI"); private static Office.CommandBar IceBar; private static Office.CommandBarButton DefaultIceButton; public static String sIceBarName = "CWT"; public static String sIceDefaultTag = "IceDefaultButton"; public static String sIceToolsTag = "IceSelectButton"; public static String[] sIceButtonItemText = {"View", "Sync", "Options"}; public static bool CreateIceButton(Outlook.Explorer currExplorrer) { string sModname = "CreateIceButton"; //try to find if IceBar exists bool bBarExists = false; try { try { //it have to be that way, if bar does not exists, index generatex exeption IceBar = currExplorrer.CommandBars[sIceBarName]; } catch { if (IceBar != null) { try { IceBar.Delete(); } catch (System.Exception e) { oBase.Show(sModname, "Error: " + e.ToString()); } } } bBarExists = IceBar != null; if (!bBarExists) //there is no IceBar, so create it { try { //right now we assume, that standard bar is at the top also IceBar = (CommandBar)currExplorrer.CommandBars.Add (sIceBarName, MsoBarPosition.msoBarTop, Missing.Value, Missing.Value); //Try to possition after Standard Bar Office.CommandBar StdBar = currExplorrer.CommandBars["Standard"]; IceBar.RowIndex = StdBar.RowIndex; IceBar.Left = StdBar.Left + StdBar.Width; IceBar.Enabled = true; IceBar.Visible = true; bBarExists = true; oBase.Show(sModname, "IceBar created"); } catch (System.Exception e) { oBase.Show(sModname, "Error: " + e.ToString()); } } //Now try to add Default button if IceBar exists bBarExists = bBarExists && SetDefaultIceButton(IceBar); } catch (System.Exception e) { oBase.Show(sModname, "Error: " + e.ToString()); } return bBarExists; } private static bool SetDefaultIceButton(Office.CommandBar tIceBar) { string sModname = "SetDefaultIceButton"; bool butExists = false; try { DefaultIceButton = (Office.CommandBarButton)tIceBar.FindControl (MsoControlType.msoControlButton, Missing.Value, sIceDefaultTag, Missing.Value, Missing.Value); butExists = DefaultIceButton != null; if (!butExists) { //there is no default button, create it try { DefaultIceButton = (CommandBarButton)tIceBar.Controls.Add (MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, Missing.Value); DefaultIceButton.Caption = sIceButtonItemText[Globals.nDefaultAction]; DefaultIceButton.Tag = sIceDefaultTag; string fname = System.Environment.GetFolderPath (System.Environment.SpecialFolder.ProgramFiles) + "\\IceDesktop\\IceButton.ICO"; System.Drawing.Bitmap oPict = new System.Drawing.Bitmap(fname); Clipboard.SetDataObject(oPict); DefaultIceButton.PasteFace(); oPict.Dispose(); DefaultIceButton.Style = MsoButtonStyle.msoButtonIconAndCaption; DefaultIceButton.TooltipText = sIceBarName + " " + sIceButtonItemText[Globals.nDefaultAction]; DefaultIceButton.Visible = true; DefaultIceButton.Enabled = true; butExists = true; } catch (System.Exception e) { oBase.Show(sModname, "Error: " + e.ToString()); } } } catch (System.Exception e) { oBase.Show(sModname, "Error: " + e.ToString()); } return butExists; } -------------------------------- I use oBase just for displaying a MsgBox. So, the problem is, that when I run that it creates the commandbar and the button, but after that, if I try to close the outlook, it closes the explorer, but outlook process remains active in memory, and OnDisconnect or OnBeginShutdown methods are never invoked. I have noticed, that if I delete the commandbar by hand (Outlook/Tools/Customize), and uninstall/install add-in, the first opening of Outlook invokes add-in correctly, creates the commandbar and button, and if I close outlook now, it finishes as expected. But next time it hangs again. The same happens, if I run a new install of the add-in and clear outlook, but before I close it, I just open any menu, or of I click on my button. After such an action Outlook hangs again on shutdown. Please, excuse me for my English. If I haven't described something clearly, please ask for additional information. Hope someone out there have seen such a problem and would like to help me. Thanks in advance. Sunny |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 


