Icons does not appear in a CommandBar : Catastrophic failure throw

H

Hichem S

I am using outlook 2003. When creating a new mail with WordEditor enabled, an
exception is thrown. I tried to debug and the exception gets thrown (see
code below) when I try to set the picture/mask property of a button.
My buttons are created by my outlook add-in with my word add-in disabled.
If I disable the outlook add-in and enable the word one, the buttons
creation is successful.
Thank you for your help...

Here is how I create my menubar and button :

CommandBar menuBar = context.GetCommandBars().ActiveMenuBar;

int controlCount = menuBar.Controls.Count;
// Add the menu two positions before the last one which is
"Help" (before Help and Windows menus).
CommandBarPopup rootMenu = (CommandBarPopup) menuBar.Controls.Add(
MsoControlType.msoControlPopup, Missing.Value,
Missing.Value, controlCount - 1, true);
if (rootMenu == null)
{
return null;
}
rootMenu.Caption = "ProductNameMenu";
rootMenu.Tag = NAME_MENU_BAR;
rootMenu.DescriptionText = "ProductName";
rootMenu.OLEUsage = MsoControlOLEUsage.msoControlOLEUsageClient;
rootMenu.TooltipText = "ProductName";
rootMenu.Visible = true;
rootMenu.Enabled = true;
return AddMenuButtons(context, rootMenu);



CommandBarButton myButton = (CommandBarButton)
rootMenu.Controls.Add(MsoControlType.msoControlButton, Missing.Value,
Missing.Value, Missing.Value, true);
myButton .Caption = "Caption";
myButton .Style = MsoButtonStyle.msoButtonAutomatic;
myButton .TooltipText = context.GetButtonSuperTip();
myButton .DescriptionText = context.GetButtonSuperTip();
myButton .OLEUsage = MsoControlOLEUsage.msoControlOLEUsageClient;
myButton .Picture = AxHelper.GetIPictureDispFromImage(BitmapAddDocument);
myButton .Mask = AxHelper.GetIPictureDispFromImage(BitmapAddDocumentMask);
myButton .Visible = true;
myButton .Enabled = true;


// This the class that helps to implement GetIPictureDispFromImage

public class AxHelper : AxHost
{
private AxHelper()
: base(null){}

public static IPictureDisp GetIPictureDispFromImage(Image image)
{
return (IPictureDisp)GetIPictureDispFromPicture(image);
}


public new static IPicture GetIPictureFromPicture(Image image)
{
return GetIPictureFromPicture(image);
}
}
 
K

Ken Slovak - [MVP - Outlook]

When using WordMail you cannot use the Picture/Mask properties.

WordMail is a subclassed version of msword.exe used by Outlook as the email
editor. As such it runs in the Word process space and not in the Outlook
process space. Picture and Mask take IPictureDisp objects, which cannot be
passed across process boundaries, therefore the exceptions.

For WordMail 2003 you must use the clipboard and the PasteFace() method of
the button to add an image. Therefore any masking you do must be done on the
clipboard image.

See if that solves your problem.
 
K

Ken Slovak - [MVP - Outlook]

What specific issue, masking an image? No, I don't have sample code for
that. I don't know if there are any samples in C# for that at
www.outlookcode.com, but you can take a look there.
 
K

Ken Slovak - [MVP - Outlook]

That sort of thing is what you need to mask the image. As I said before you
cannot use the Mask or Picture properties from an out-of-process call.

The example you cite isn't C++, it's VB 6 code. It just uses a lot of Win32
API calls.

To use that code you'd need to translate it into C# or VB.NET and take
especial care with the memory management and release calls so you don't leak
handles.
 
H

Hichem S

Anyway...
You said : "WordMail is a subclassed version of msword.exe used by Outlook
as the email editor. As such it runs in the Word process space and not in the
Outlook
process space. Picture and Mask take IPictureDisp objects, which cannot be
passed across process boundaries, therefore the exceptions."


In this example
myButton .Picture = AxHelper.GetIPictureDispFromImage(BitmapAddDocument);
Is executed in the word process and BitmapAddDocument is a resource file
that will be called from the word process.
As I said, my object oriented implementation let me, depending on the
specific add-in application run the same "code". The code shown earlier will
be called from an outlook context as well as from word context but obviously
with different instances.
So when it comes to run wordEditor for a new mail, this code will be called
in word context to create buttons in word context.
I don't see why this then does not work!?
Thank you very much
 
K

Ken Slovak - [MVP - Outlook]

No matter how you try to avoid it, you are still going to run in an out of
process space if your code is running in an Outlook addin.

You would have to run all Word code in a Word addin (completely separate) to
avoid that, and then you'd have to figure out how to get the Word code to
execute what you want from the Outlook code.

The example is Word code, not Outlook code.
 
H

Hichem S

Don't you think that maybe wordmail is actually a simplistic version of word
process and that is why it's not able to handle everything word can! that's
why we have to workaround and find another solution to the problem we have
already a solution for!
Too much particular case. Is that possible?
The example is Word code, not Outlook code.
NB : the code I was talking about is the one shown in my first question in
this thread.
 
K

Ken Slovak - [MVP - Outlook]

No I don't think that's possible. I know that WordMail in Outlook 2003 and
earlier is a subclassing of msword.exe, which is not the case in Outlook
2007 where a special word dll is used for the editor.

Just accept it, for WordMail 2003 and earlier you cannot use Mask and
Picture from Outlook code. Period. It's documented all over the Internet.
Believe me or not, but that's the way things are.
 
H

Hichem S

Yes I know. we were just discussing the reason why it's not working in 2003.
My question now is how can I copy multiple images simultaneously to the
clipboard? In fact, I am creating mutliple buttons when opening a new mail in
outlook. I suppose then that when switching context (from outlook to word by
creating a new mail item) I will only be able to copy one image to the
clipboard!
thanks
 
K

Ken Slovak - [MVP - Outlook]

You follow the type of coding that the VB code in that KB article showed to
create transparency where you want it in an image for the first button. You
then use the PasteFace() method to put that image on the button.

You then clear the clipboard, and repeat the process for the next button
image, etc. You can do unlimited numbers of button images that way.

Of course you also have to take into consideration saving the existing
clipboard contents if any before you start the process and restore the
contents after you are finished so the user still has the same clipboard
contents.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top