Aracılığıyla paylaş


How ActiveSync can affect your Outlook Add-ins

If you develop / use Outlook Add-ins for quite some time you'll run into this fairly common issue with ActiveSync (or any other application that uses Outlook Automation). Users who use PDAs / SmartPhones that run Microsoft Windows Mobile use ActiveSync to synchronize their Outlook information with the mobile device. ActiveSync for this reason starts up Outlook using Outlook Automation (in pure dev language - creates an Outlook.Application object) - Outlook being a Singleton application (only one thread of Outlook.exe runs at any given point in time) if Outlook.exe is already running, ActiveSync uses the current running thread to fetch the Outlook info required to sync with the mobile device.

However, if Outlook isn’t running when ActiveSync is started then ActiveSync creates a new Outlook.exe process - It still does load your Add-ins, however, without the Outlook UI (This is true for all versions of Outlook XP SP3 and above - see https://support.microsoft.com/?id=329098). Since no UI is present the Explorer count at this point would be Zero and a call to the ActiveExplorer() method of the Application class would return a null.

This is fairly important and something that you should always keep in mind when you develop an Outlook Add-in. Always check if the Explorer count is greater than Zero before you make a call to ActiveExplorer. If the count is indeed Zero (which means Outlook has started by Outlook Automation and not using the UI) handle your application gracefully.

A fairly common scenario where developers hit upon is that they try to add buttons to a toolbar on the Explorer - which don’t seem to appear when ActiveSync is started before Outlook. This is because most of the time developers try to add buttons using the ActiveExplorer in the OnConnection event. Since the ActiveExplorer will return a null when there is no Outlook UI - no buttons are added (this can also lead someone to believe that the Addin is not loading though it’s not in the Disabled Items either).

The way you can fix this is by not adding the buttons to the Explorer in the OnConnection event but instead to trap the NewExplorer event, get hold of the Explorer object in this event handler and wire up its Activate event and then add the buttons in the Activate Event instead. Additionally, note that the Activate event fires every time your Explorer object receives focus - so you must check if the buttons already exist on the Explorer before you add them to avoid the buttons being added multiple times.

Comments

  • Anonymous
    August 26, 2005
    Now if only ActiveSync would let go of Outlook! I fail to understand why ActiveSync keeps Outlook running AFTER I disconnect my device (an MPx220 in this case).

    This leads to all sorts of problems, from failed backups ('cause the PST is open) to inappropriate mail delivery (Outlook is actively pulling from my POP3 server, so my MPx220 never gets a chance to download any email).

    I used Micrologics "ActiveSync Toggle", but that's far from ideal.

  • Anonymous
    August 27, 2005
    ToodM,

    Much agreed. Why is it that I often get at least 2 instances of Outlook.exe in the Task Manager? Why doesn't Activesync let go of it when I disconnect. This has been around for all versions of ActiveSync I can remember, even the dev preview of 4.0 I am running, although it seems to happen less frequently.

    Sorry to vent Mohammed...I appreciated your post

  • Anonymous
    August 27, 2005
    hmmm... thats odd - I just tried it out with ActiveSync 4.0 (connected to my WM5 device - though my build might be different from yours) and a fully patched Outlook 2003 and ActiveSync seemed to let go of Outlook - there could be a ton of reasons for Outlook not shutting down properly (http://www.slipstick.com/problems/close.htm has a good list of them). Which version/build of Outlook and ActiveSync are you guys using?
    -Mohammed

  • Anonymous
    November 11, 2005
    How could you be running ActiveSync 4.0? According to Microsoft, version 3.8 is the current version?

  • Anonymous
    June 14, 2006
    The problem is that even if you check the Explorer count before loading up your add-in, the OnConnection will not fire again once Outlook starts via automation.

    What if you do not want to load your add-in if no UI exists.

  • Anonymous
    August 07, 2006
    I tried to follow these steps, but I cannot get the events to fire.
    I put MessageBoxes into both NewExplorer and Connect_ExplorerEvents_10_Event_Activate eventhandlers, and don't get either of then.

    How can I subscribe succesfully to those events?

    TIA,
    Alex

  • Anonymous
    July 17, 2007
    The comment has been removed

  • Anonymous
    January 21, 2009
    PingBack from http://www.keyongtech.com/1768879-activesync-causing-addin-not-to

  • Anonymous
    October 16, 2011
    The comment has been removed