[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

adding Icon to outlook AddOn ToolBar?

Posted on 2010-03-25
4
Medium Priority
?
728 Views
Last Modified: 2013-11-10
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

0
Comment
Question by:TomDromi
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 28664053
0
 
LVL 1

Author Comment

by:TomDromi
ID: 28679649
Thank,

Most of these pages just repeat my code...

Any Other Idea of the exception?

Thanks, Tom
0
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 28912046
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
 
LVL 1

Accepted Solution

by:
TomDromi earned 0 total points
ID: 29365981
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

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
MS Outlook undoubtedly is the most widely used email client.Its user-friendliness, cost effectiveness, and availability with Microsoft Office Suite make it the most popular email application.  Its compatibility with Microsoft applications like Exch…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question