Ask a questionAsk a question
 

AnswerSaving Toolbar Positions in Outlook 2007

  • Tuesday, January 08, 2008 7:21 AMbrownap Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    I have a need to save and restore a custom toolbar's position in Outlook 2007 (with VSTO for Visual Studio 2008). Doesn't seem like a complicated task and I've had it working with VSTO 2005 and Outlook 2003.

    I found the following article on MSDN:

    How to: Maintain Position Information for Custom Toolbars between Outlook Sessions

    This has a full code listing, and I am getting an error accessing the CommandBar instance on ThisAddIn_Shutdown. Any property access on the CommandBar at this point is throwing the exception:

    System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A01A8

    Look up this HRESULT value and you can see that it means "Object Required".

    To me, this means that the CommandBar has already been cleaned up and is no longer accessible, but ThisAddIn_Shutdown is supposedly the first user code to be run before a shutdown occurs. If I can't save the toolbar state here, where is the best place to do it?

    Any help explaining this (and hopefully a solution/workaround) is much appreciated.

    Cheers,
    Adrian.

Answers

  • Monday, January 14, 2008 6:43 AMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

     brownap wrote:

    I would still like to know why it is behaving differently

     

    Hi Adrian,

     

    There is a famouse problem related to COM reference counting in Outlook 2003. To resolve that problem, Outlook 2007 try to make improvements about object lifetime and memory management. This is why you see difference between Outlook 2003 and Outlook 2007.

    I cannot give a better explanation than Andrew's. Please refer the following thread to know more information:

    http://forums.microsoft.com/msdn/rss.aspx?postid=1752347&forumid=16&siteid=1

    As you already found, the walkaround is to use Close event. Thanks for your sharing solution after finding it.

     

     

    Thanks

    Ji

  • Thursday, January 10, 2008 12:20 AMbrownap Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I would still like to know why it is behaving differently, but I have got a workaround for anyone interested.

    I am now listening to the Close event of the main Explorer window, and this appears to be behaving okay. It is called before the Shutdown event and the CommandBar object is still accessible.

    Cheers,
    Adrian.

All Replies

  • Tuesday, January 08, 2008 7:24 AMbrownap Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I just re-read that article I mentioned above and it talks specifically about Office 2003, so fine: no guarentees with 2007. But why should it work differently in 2007?

    Cheers,
    Adrian.
  • Thursday, January 10, 2008 12:20 AMbrownap Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I would still like to know why it is behaving differently, but I have got a workaround for anyone interested.

    I am now listening to the Close event of the main Explorer window, and this appears to be behaving okay. It is called before the Shutdown event and the CommandBar object is still accessible.

    Cheers,
    Adrian.
  • Monday, January 14, 2008 6:43 AMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

     brownap wrote:

    I would still like to know why it is behaving differently

     

    Hi Adrian,

     

    There is a famouse problem related to COM reference counting in Outlook 2003. To resolve that problem, Outlook 2007 try to make improvements about object lifetime and memory management. This is why you see difference between Outlook 2003 and Outlook 2007.

    I cannot give a better explanation than Andrew's. Please refer the following thread to know more information:

    http://forums.microsoft.com/msdn/rss.aspx?postid=1752347&forumid=16&siteid=1

    As you already found, the walkaround is to use Close event. Thanks for your sharing solution after finding it.

     

     

    Thanks

    Ji

  • Wednesday, July 02, 2008 2:39 AMTizza Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    This is all well & good.  Why doesn't Microsoft just get its act together and remember where the user has positioned the toolbar?  Instead us developers have to do their work for them...