none
Hiding Outlook inspector window when opening mailItem in Outlook 2003 RRS feed

  • Question

  • Hi all,

    I am developing an outlook addin with C#. In it, I want to display a web page in the default browser and stop the inspector from opening/displaying when a specific set of emails are opened. I have already posted a question previously regarding this, you can find the complete details of my requirements in the thread here.

    The basic summary is, when the user selects the specific mail item, I am setting the Open event handler. In the handler, I am opening the web page and set the cancel ref parameter to 'true' in order to cancel the process. However, when the "Use MS Office Word 2003 as email editor" option is selected, the inspector is still shown. On some machines it will close in a little, on others it won't. Remedy: capture the inspector being opened on the open new inspector event, and in the activate event, if the inspector's EditorType is olEditorWord, set the WindowState to olMinimized.

    During testing, this worked sufficiently. However, a user has now received an error while using my add-in. The error has been when trying to open a mail item (where the above sequence of code is run) and is the "MS Office Word: A fatal error has occurred in outlook. The data in your envelope has been lost, but your document is still available." I am unable to reproduce the error on my dev machine so far, but I do get a "MS Office Word has stopped working" error occasionally.  Also, I still haven't written off the possibility that this is caused by some other add-in/setting on the client's outlook/word.

    Could the client's error be due to forcefully minimizing the inspector? Is there a better way to achieve my requirement to hide/close the inspector when in word editor mode? For example, is there a way I could change the editor type? I would set it to be outlook in the SelectionChange event for my mail items and set it back to word when other mail items are selected by the user. Setting the Inspector's EditorType property does not seem to have an effect.

    Or if you can give me an idea on where to start in order to resolve the error (or prove that it's not my fault ☺)  it would be much appreciated!

    Thanks!

    Cheers,

    Thimila

    Wednesday, May 8, 2013 2:58 AM

Answers

  • Are you releasing your object references and removing your subscriptions to various events? I see no code for any of that.

    Ken Slovak MVP - Outlook

    Thursday, May 9, 2013 6:02 PM
    Moderator
  • I would remove the event handlers and all object references when the items are closed. It also wouldn't hurt to check if there is an Explorer before you set your Explorer reference in your startup code, but that's a side issue.

    Also, don't forget that for Outlook 2003 that when using WordMail you're using a subclassed instance of the actual Word.Application object. In Outlook 2007 and later it's always WordMail, but it's an instance of a Word DLL owned by Outlook and not a subclassed instance of the full Word.

    What that means is that in 2003 the WordMail application is running in a different process and different thread than Outlook and therefore your addin (which runs in-process with Outlook). If you were to use any Outlook objects/events/methods/properties in the context of the WordMail thread you need to synch the thread contexts.


    Ken Slovak MVP - Outlook

    Friday, May 10, 2013 2:28 PM
    Moderator

All replies

  • Hi,

    Could you please share your final code (relevant parts)?

    Thanks,
    Moshe

    Wednesday, May 8, 2013 6:00 AM
  • Hi Moshe,

    The code is almost the same as what I have posted on my previous thread. Only difference is I have created wrapper classes to handle multiple simultaneous explorers and inspectors. And I check the inspector's EditorType before minimizing it.

    private Microsoft.Office.Interop.Outlook.Inspectors _inspectors; private Microsoft.Office.Interop.Outlook.Explorer _currentExplorer; public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom) { _inspectors = application.Inspectors; _currentExplorer = application.ActiveExplorer(); _inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(this.Open_NewInspector); //add handler to explorer selectionChange event, fires when item is selected _currentExplorer.SelectionChange += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(this.OnSelectChange); }

    //-----This section in explorer wrapper----// public void OnSelectChange() { if(<selectedMailItem is the type I require>) { mailItem.Open += new Microsoft.Office.Interop.Outlook.ItemEvents_10_OpenEventHandler(mail_Edit); } } public void mail_Edit(ref bool cancel) { //Open URL cancel= true; } //-----------------------------------------//

    //-----This section in inspector wrapper----// private void Open_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector) { if(<check mail type to open inspector is my mail type>) { ((Microsoft.Office.Interop.Outlook.InspectorEvents_10_Event)newMailInspector).Activate += new Microsoft.Office.Interop.Outlook.InspectorEvents_10_ActivateEventHandler(InspectorActivate); } } private void InspectorActivate() { try { if (_inspector.EditorType == Microsoft.Office.Interop.Outlook.OlEditorType.olEditorWord) { if (newMailInspector.WindowState == Microsoft.Office.Interop.Outlook.OlWindowState.olMaximized || newMailInspector.WindowState == Microsoft.Office.Interop.Outlook.OlWindowState.olNormalWindow) newMailInspector.WindowState = Microsoft.Office.Interop.Outlook.OlWindowState.olMinimized; } } catch (System.Exception ex) { MessageBox.Show(ex.Message, "Activate"); } }


    Thanks,

    Thimila

    Wednesday, May 8, 2013 6:30 AM
  • --UPDATE--

    I removed all the Inspector controlling code from the add-in and ran it. Now only the mail open event handler remains in my code. Yet still when I open two mails that would return cancel=true successively , MS Word will crash stating:

    "Microsoft Office Word has stopped working"
    Problem Event Name: APPCRASH
    Exception Code: c0000005
    Exception Offset: 0021aebd

    Additional information about the problem:
      LCID: 1033
      Brand: Office11Crash
      skulcid: 1033

    Does anyone have any idea what could cause this? Any help will be greatly appreciated!

    Cheers,

    Thimila

    Thursday, May 9, 2013 6:29 AM
  • Are you releasing your object references and removing your subscriptions to various events? I see no code for any of that.

    Ken Slovak MVP - Outlook

    Thursday, May 9, 2013 6:02 PM
    Moderator
  • Hi Ken,

    Thanks for you reply. I am releasing the object references (using Marshal.ReleaseComObject) by handling the application.quit event. Do I need to remove the event handlers explicitly as well?

    Cheers,

    Thimila

    Friday, May 10, 2013 1:40 AM
  • I would remove the event handlers and all object references when the items are closed. It also wouldn't hurt to check if there is an Explorer before you set your Explorer reference in your startup code, but that's a side issue.

    Also, don't forget that for Outlook 2003 that when using WordMail you're using a subclassed instance of the actual Word.Application object. In Outlook 2007 and later it's always WordMail, but it's an instance of a Word DLL owned by Outlook and not a subclassed instance of the full Word.

    What that means is that in 2003 the WordMail application is running in a different process and different thread than Outlook and therefore your addin (which runs in-process with Outlook). If you were to use any Outlook objects/events/methods/properties in the context of the WordMail thread you need to synch the thread contexts.


    Ken Slovak MVP - Outlook

    Friday, May 10, 2013 2:28 PM
    Moderator
  • Hi Ken,

    Thanks for the pointers! I made sure that I am removing all the event handlers to COM objects (OOM and RDO) and it seems to have resolved the issue. Also, thanks for explaining to me how word mail works in Outlook 2003.

    Thanks again!

    Cheers,

    Thimila.

    Thursday, May 16, 2013 12:45 AM