> 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"
> > }
> >
>
>