adding Icon to outlook AddOn ToolBar?

Hi,

I have problem to add Icon to outlook add-on toolbar.
I'm using visual studio 2005 SE and outlook 2003 with the following code.
when I try to assign the image to the button it crash with:
{"Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"}

any idea why?
the same code working on outlook 2007...

Thanks, Tom
CommandBars cmdbrs = tInspector.CommandBars;

            try
            {
                toolbarButton = (CommandBarButton)cmdbrs["Standard"].Controls.Add(1, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                toolbarButton.Caption = "Test";
                toolbarButton.Style = MsoButtonStyle.msoButtonIconAndCaption;
                toolbarButton.TooltipText = "Publish";
                toolbarButton.Visible = true;
                toolbarButton.Picture = getImage();
                toolbarButton.Mask = getImage();
                toolbarButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(OnToolbarButtonClick);
            }

private stdole.IPictureDisp getImage()
        {
            stdole.IPictureDisp tempImage = null;
            try
            {

                System.Drawing.Icon newIcon =
                    Properties.Resources.logo;

                ImageList newImageList = new ImageList();
                newImageList.Images.Add(newIcon);
                tempImage = ConvertImage.Convert(newImageList.Images[0]);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return tempImage;
        }

    sealed public class ConvertImage : System.Windows.Forms.AxHost
    {
        private ConvertImage()
            : base(null)
        {
        }
        public static stdole.IPictureDisp Convert
            (System.Drawing.Image image)
        {
            return (stdole.IPictureDisp)System.
                Windows.Forms.AxHost
                .GetIPictureDispFromPicture(image);
        }
    }

Open in new window

LVL 1
TomDromiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TomDromiAuthor Commented:
Thank,

Most of these pages just repeat my code...

Any Other Idea of the exception?

Thanks, Tom
0
Miguel OzSoftware EngineerCommented:
Tom:
are you using this in the main thread context?
The code above does not work in a thread, it gets unexpected behaviour including a crash.
0
TomDromiAuthor Commented:
finally, I use the faceId property  to place an Icon from the built-in library.
I used a temp function to make 1000 button with all the available icons and I choose the one most appropriate.

Thanks for the advices.

Tom
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.