Preventing loading a Word add-in from Outlook

Add-in Express™ Support Service
That's what is more important than anything else

Preventing loading a Word add-in from Outlook
 
momsoft




Posts: 79
Joined: 2004-06-16
Hi,

I have been reported that my Word add-in is crashing when users are using Word as their Outlook email editor. I imagine that this is caused because the add-in is being started by Outlook.

How can determine if that is the case, and if so prevent launching a second instance of my add-in?

Thank you,

- Manuel Onate
Posted 15 Mar, 2007 08:58:47 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Manuel,

You can handle the OnWindowActivate event and turn off your command bar:


procedure TAddInModule.adxWordAppEvents1WindowActivate(ASender: TObject;
  const Doc: _Document; const Wn: Window);
var
  CmdBar: CommandBar;
begin
  try
    CmdBar := Doc.CommandBars.Item['Envelope'];
    if Assigned(CmdBar) and CmdBar.Visible then begin
      Doc.CommandBars.Item[adxCommandBar1.CommandBarName].Set_Visible(False);
    end
    else begin
      Doc.CommandBars.Item[adxCommandBar1.CommandBarName].Set_Visible(True);
    end;
    CmdBar := nil;
  except
    // not found
  end;
end;


P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.
Posted 15 Mar, 2007 10:05:34 Top
momsoft




Posts: 79
Joined: 2004-06-16
Dmitry,

Thank you for your answer. I'll take a look at it. I was thinking in not loading the add-in at all if the current instance of Word is not running stand-alone. I am thinking now that maybe my add-in could also have problems if Word is running inside a server application.

Regards,

- Manuel Onate
Posted 16 Mar, 2007 13:26:42 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Manuel,

I am thinking now that maybe my add-in could also have problems if Word is running inside a server application.


I think you can check the WordApp.Visible property in the OnAddinInitialize event handler in order to detect how Word was started, by the end-user or through OLE Automation.

Posted 19 Mar, 2007 05:30:58 Top
momsoft




Posts: 79
Joined: 2004-06-16
Hi Dmitry,

I have been investigating further the situation and it is not totally obvious.

When Word is started normally (launching winword.exe), the events generated are:

1)WordAppEvents.OnStartup
2)AddInModule.OnAddInInitialize
3)AddInModule.OnAddInStartupComplete
4)WordAppEvents.WindowActivate

But, when Word starts through OLE Automation (and possibly Outlook, unfortunately I can't test), the events are:

1) 2) 4)

But, if Word is already running, opening Word through OLE Automation, no event is generated.

Since I was placing the startup code on the OnAddInStartupComplete, I see that the error was caused by the AddInModule.OnAddInFinalize disposing of non initialized objects.

Therefore, the solution seems to be:

- Move the start-up code to the AddIniInitialize event.
- Check if Outlook is the host application on the WindowActivate event.
- Keep the clean-up code on the OnAddInFinalize.

But, I still need a way to know if the current window is an Ole Automation document.

Please, confirm that this analysis is correct, and what test could I use to check for the Ole Automation situation.

Thank you very much,

- Manuel Onate
Posted 26 Mar, 2007 03:17:59 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Manuel,

Please, confirm that this analysis is correct, and what test could I use to check for the Ole Automation situation.


Seems correct. You can try to examine the Container property of the Document interface.


Posted 26 Mar, 2007 07:20:11 Top
momsoft




Posts: 79
Joined: 2004-06-16
Dmitry,

This issue is proving to be much more difficult than I thought initially. As it seems, Word is not generating WindowActivate events when opening an embedded document. Therefore I think I will check on the OnClick events of the toolbar and ribbon buttons, and disable all buttons there. Then I can reenable them on the WindowActivate events which are being generated when a real Word window gets focus. (I believe this approach should definitely work).

Anyway, I think I have finally discovered what was causing the crashes in Word. It seems as if the ActiveForm I am using in my addin is not being created when Word is started through OLE Automation (and possibly Outlook).

The problem is that I don't see where can I place code to check for this situation and remedy it. It seems as if the crash happens before any of my own code is used. I know it because I am logging all the procedures and methods used by the Addin.

What do you think?

Thank you very much in advance,

- Manuel Onate
Posted 28 Mar, 2007 10:01:13 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Manuel,

Could you please send me your project (or some demo project with the same behavior) for testing? I will try to help.

Posted 29 Mar, 2007 06:20:33 Top