Create CommandBarButtons on an email using WordEditor.

Hello,

When I create a custom toolbar in a new email window (just by clicking on the new email button and having the new inspector event trapped), I am having a problem when I am setting the .Picture property on the button. The code I have is as follows:

m_btnCreateInProj = (Office.CommandBarButton)m_commandBar.Controls.Add(Office.MsoControlType.msoControlButton, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
m_btnCreateInProj.Caption = TeamlookRes.TL_Inspector_BTN_CreateInProject;
m_btnCreateInProj.Visible =
true;
m_btnCreateInProj.Enabled =
true;
m_btnCreateInProj.TooltipText =
TeamlookRes.TL_Inspector_BTN_CreateInProject_Tooltip;
m_btnCreateInProj.Style = Microsoft.Office.Core.
MsoButtonStyle.msoButtonIconAndCaption;
//m_btnCreateInProj.Picture = ImageToPictureConverter.Convert(TeamlookRes.create_wi_project_16);
//m_btnCreateInProj.Mask = ImageToPictureConverter.Convert(TeamlookRes.create_wi_project_16mask);
m_btnCreateInProj.Click +=
new Office._CommandBarButtonEvents_ClickEventHandler(_CreateInProj_ClickEvent);

When I have the above lines enabled, I get an exception as follows:

System.Runtime.InteropServices.COMException was caught
Message="Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))" Source="office" ErrorCode=-2147418113
StackTrace:
at Microsoft.Office.Core._CommandBarButton.set_Picture(IPictureDisp ppdispPicture)
at TeamlookPro.TLInspectorWrapper._CreateToolbarButtons()

If I don't have the Picture and Mask properties set on the button, the toolbar loads fine, but without the images I need.

This only happens when I have Word as my email editor. If I change the option so Word is not the email editor, I do not get the exception and the images load correctly.

What do I have to do to get the button images to show when using Word as the email editor

Thanks!!
~Joe



Answer this question

Create CommandBarButtons on an email using WordEditor.

  • Alanu

    Joe,

    Sorry for the delay in answering you. The code in the article by Ken Slovak doesn't seem complete. I can't get it to compile by just cutting and pasting.

    But if you do get VB code to compile, then you can use a reflector to covert it to C# from the compiled assembly. I use the Lutz Roeder .Net Reflector http://www.aisto.com/roeder/dotnet/

    Peter


  • ssboyz

    Peter,

    I have been trying to get the sample provided in the KB article that Ken Slovak mentioned (http://support.microsoft.com/kb/288771/en-us) converted into C#, but am running into many problems in the interop between the C# managed code and calling the Native underlying code... (and it seems there are lots of defined variables in the VB code that aren't actually in the sample so getting it to C# is not straight forward in the least). I understand the concept of what the code is trying to accomplish, but the syntax, types, and values for the constants is difficult to massage.

    Since this is the published microsoft way of getting images on the toolbar buttons, has this code been written for the C# developers in mind

    Thanks in advance!
    ~Joe


  • Forgon

    Joe,

    What version of office are you using

    Can you send me a complete repro, and I will see if it runs on the version of office I'm using.

    Thanks,

    Peter


  • BMEMBERG

    Joe,

    Thanks for sending me the repro, it did repro for me. The following is a link to a thread which discusses the problem, which is also summarized below the link.

    http://groups.google.com/group/microsoft.public.developer.outlook.addins/browse_thread/thread/21de384d2ee4e35c/42167403254930ca#42167403254930ca

    Look in the KB for information about using PasteFace with masking for
    transparency. Another thing to consider is that in .NET code you're crossing
    process boundaries between COM applications and your .NET code. Mask and
    Picture use IPictureDisp and that can't cross process boundaries. WordMail
    is Word subclassed by Outlook and so the process boundaries are being
    crossed.

    --
    Ken Slovak
    [MVP - Outlook]

    I’ve also sent your repro to the Outlook group to see if there is a work around for the problem.

    Thanks,

    Peter


  • Kamii47

    I am using Outlook 2003 SP2. I'll follow up with you offline as I will send you an entire sample application to do it.

    Cheers,
    ~Joe


  • Create CommandBarButtons on an email using WordEditor.