AddIn crashes Outlook 2007

C

Charles Sinclair

I have an AddIn that works fine on Outlook 2000, 2002 and 2003, but crashes
Outlook 2007 Beta 2. I am using VC++ 6 with #import. The AddIn places a
single toolbar with a single button on an Inspector window. With Outlook
2007, it randomly crashes when the Inspector is closed. It appears to be
something to do with CommandButton events. If I remove the call to
DispEventAdvise for the button, the crash goes away. The Open/Close Inspector
event handling appears to work fine.

Perhaps related is that FindControl seems very unreliable. Sometimes it
works, sometimes it doesn't. I have tried manually enumerating the controls
on my toolbar, but this fails too, because CommandBarControlsPtr->Count
returns 0, even though I can see the button on the Inspector toolbar myself.
What is also odd is that this unreliability seems confined to the AddIn. The
same code as a separate EXE work OK.

Are any of these known Beta 2 issues? Or does anyone have any suggestions?
 
D

Dmitry Streblechenko

Do you unadvise your event sinks and release all the COM objects related to
the inspector (inspector, command bars, buttons, etc) when inspector closes?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
C

Charles Sinclair

Thank you for your reply.

<<Do you unadvise your event sinks and release all the COM objects related
to the inspector>>

Absolutely. I have double checked this and checked again now. The AddIn
works perfectly under Outlook 2003 and earlier. Those versions of Outlook
also exit cleanly, which perhaps suggests that no outstanding references to
Outlook COM objects are left open.

Regarding the FindControl issue, which I feel is related (because the common
theme seems to be custom toolbars), I said earlier that FindControl in the
AddIn was unreliable (sometime it finds the control and sometime it doesn't),
while identical code in a standalone EXE always found the control. I now
realize that this is due to a timing issue. The code that fails in the AddIn
gets executed during the OnNewInspector event handler. During this time it
seems that custom toolbar controls may or may not be available. Also, when I
fetch the correct toolbar to enumerate the controls myself, the Controls
count is sometimes zero, even though the control exists.

When the toolbar button does exist but FindControl returns NULL, then the
Add method of the Controls collection will always return an "invalid index"
error (which makes no sense to me).

Any suggestions would be appreciated. My feeling is that this is likely to
be an Outlook 2007 Beta 2 issue, since a) none of these issues happen with
Outlook 2003 and earlier and b) I would not expect a bug in an AddIn to crash
Outlook, given that all my event handlers are in try/catch blocks.

Office::CommandBarPtr cmdBar;
Office::CommandBarControlPtr button;
button = cmdBar->FindControl(vtMissing, 1L, tag); // This sometimes does not
work
if (button == NULL)
{
_variant_t vButtonType = (long) Office::msoControlButton;
button = cmdBar->Controls->Add(vButtonType); // This sometimes returns
"invalid index"
}
 
K

Ken Slovak - [MVP - Outlook]

Even with earlier versions of Outlook you might get that condition unless
you wait until the first Inspector.Activate event fires. I've had problems
with that, especially with WordMail in email Inspectors, even with Outlook
2003.

I use the first Activate event, create my buttons, use FindControl, etc.
then and set a flag that I've already done that so future activates don't
follow the same code path.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top