Group:  Microsoft Outlook ยป microsoft.public.outlook.program_addins
Thread: AddIn crashes Outlook 2007

Geek News

AddIn crashes Outlook 2007
Charles Sinclair 5/30/2006 2:09:02 PM
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?

Re: AddIn crashes Outlook 2007
"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> 5/30/2006 7:03:09 PM
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

"Charles Sinclair" <CharlesSinclair[ at ]discussions.microsoft.com> wrote in
message news:2EA56BBA-5D5D-4067-B178-7A92898CBDEE[ at ]microsoft.com...
[Quoted Text]
>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?
>


Re: AddIn crashes Outlook 2007
Charles Sinclair 5/31/2006 1:22:02 PM
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"
}

Re: AddIn crashes Outlook 2007
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 5/31/2006 3:16:20 PM
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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Charles Sinclair" <CharlesSinclair[ at ]discussions.microsoft.com> wrote in
message news:094766E8-35E6-45FD-BB43-2101EB3A72BA[ at ]microsoft.com...
[Quoted Text]
> 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"
> }
>

Re: AddIn crashes Outlook 2007
Charles Sinclair 6/1/2006 5:43:02 PM
Many thanks for your input. I'll certainly give this a try.

"Ken Slovak - [MVP - Outlook]" wrote:

[Quoted Text]
> 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.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "Charles Sinclair" <CharlesSinclair[ at ]discussions.microsoft.com> wrote in
> message news:094766E8-35E6-45FD-BB43-2101EB3A72BA[ at ]microsoft.com...
> > 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"
> > }
> >
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net