PC Review


Reply
Thread Tools Rate Thread

Button throws error when image is added if there's no popup object

 
 
Andrew
Guest
Posts: n/a
 
      29th Jan 2009
Hello All,

I have an Add-in developed for Outlook 2003. Before this change I was adding
an image to the ".Picture" property of the button after initially adding the
button to a popup object. Everything worked fine, however, I decided the
popup object wasn't needed when there was only one associated for a toolbar.
The buttons where I removed the popup object throws following error when its
been created:
"
Error HRESULT E_FAIL has been returned from a call to a COM component".

the other buttons that have a popup, work fine. The image being added is
the same everywhere.

This is the class where I create and assign the image to a global variable:

Public Class clsScaryFace
Inherits System.Windows.Forms.AxHost

Public Sub New()
MyBase.New("59EE46BA-677D-4d20-BF10-8D8067CB8B32")
End Sub

Public Sub GetScaryFace()
Dim scaryFaceImage As Bitmap = Nothing
'Dim scaryFaceMask As Bitmap = Nothing
Try
scaryFaceImage = My.Resources.Scaryface.scaryface
'scaryFaceMask = My.Resources.Scaryface.scary_mask

If (Exists(scaryFaceImage)) Then
g_imgScaryFace = Convert(scaryFaceImage)
'g_imgScaryFaceMask = Convert(scaryFaceMask)
End If

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
scaryFaceImage = Nothing
'scaryFaceMask = Nothing
End Try
End Sub

Private Function Convert(ByVal Image As System.Drawing.Image) As
stdole.IPictureDisp
Convert = CType(GetIPictureDispFromPicture(Image),
stdole.IPictureDisp)
End Function
End Class

This is where I add the button:
m_butOldEmailSyncToCS =
CType(m_OldEmailCSToolBar.Controls.Add(MsoControlType.msoControlButton, , , ,
Temporary:=True), Office.CommandBarButton)

This is where I set the properties after which it blows up when attempting
to assign the g_imgScaryFace

With m_butOldEmailSyncToCS
.Caption = "Save to CS"
.Visible = True
.Enabled = True
.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption
.Picture = g_imgScaryFace
End With

Anyone has any ideas what's going wrong?

Regards,
 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      29th Jan 2009
Is m_OldEmailCSToolBar still being used and is it a valid object? You can
only add buttons to a CommandBar or CommandBarPopup object, although the
CommandBarPopup buttons are actually being added to the
CommandBarPopup.CommandBar object.

Does it blow up when you set the Picture property? Is this an Explorer or
Inspector button?

For WordMail Inspectors you cannot use the Picture property, you must use
the old PasteFace method with an image put on the clipboard. That's because
Picture takes an IPictureDisp object, which cannot be passed across process
boundaries. As WordMail is Word subclassed by Outlook it runs in its own
separate process and attempting to use Picture there tries to pass the
IPictureDisp object across process boundaries. That forces an exception.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Andrew" <(E-Mail Removed)> wrote in message
news:2EDCE898-DFE0-4A8B-8E50-(E-Mail Removed)...
> Hello All,
>
> I have an Add-in developed for Outlook 2003. Before this change I was
> adding
> an image to the ".Picture" property of the button after initially adding
> the
> button to a popup object. Everything worked fine, however, I decided the
> popup object wasn't needed when there was only one associated for a
> toolbar.
> The buttons where I removed the popup object throws following error when
> its
> been created:
> "
> Error HRESULT E_FAIL has been returned from a call to a COM component".
>
> the other buttons that have a popup, work fine. The image being added is
> the same everywhere.
>
> This is the class where I create and assign the image to a global
> variable:
>
> Public Class clsScaryFace
> Inherits System.Windows.Forms.AxHost
>
> Public Sub New()
> MyBase.New("59EE46BA-677D-4d20-BF10-8D8067CB8B32")
> End Sub
>
> Public Sub GetScaryFace()
> Dim scaryFaceImage As Bitmap = Nothing
> 'Dim scaryFaceMask As Bitmap = Nothing
> Try
> scaryFaceImage = My.Resources.Scaryface.scaryface
> 'scaryFaceMask = My.Resources.Scaryface.scary_mask
>
> If (Exists(scaryFaceImage)) Then
> g_imgScaryFace = Convert(scaryFaceImage)
> 'g_imgScaryFaceMask = Convert(scaryFaceMask)
> End If
>
> Catch ex As Exception
> MessageBox.Show(ex.Message)
> Finally
> scaryFaceImage = Nothing
> 'scaryFaceMask = Nothing
> End Try
> End Sub
>
> Private Function Convert(ByVal Image As System.Drawing.Image) As
> stdole.IPictureDisp
> Convert = CType(GetIPictureDispFromPicture(Image),
> stdole.IPictureDisp)
> End Function
> End Class
>
> This is where I add the button:
> m_butOldEmailSyncToCS =
> CType(m_OldEmailCSToolBar.Controls.Add(MsoControlType.msoControlButton, ,
> , ,
> Temporary:=True), Office.CommandBarButton)
>
> This is where I set the properties after which it blows up when attempting
> to assign the g_imgScaryFace
>
> With m_butOldEmailSyncToCS
> .Caption = "Save to CS"
> .Visible = True
> .Enabled = True
> .Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption
> .Picture = g_imgScaryFace
> End With
>
> Anyone has any ideas what's going wrong?
>
> Regards,


 
Reply With Quote
 
Andrew
Guest
Posts: n/a
 
      29th Jan 2009
Thanks for the response,

m_OldEmailCSToolBar is a global variable in the wrapper class for the
inspector. Yes, it is an Inspector Object, its an existing email item that
was opened, so No "WordMail."

Yes, it blows up on the when I set the Picture property. I've stepped
through the code and all the objects are valid. As I mentioned earlier, it
works fine when I create a "CommandBarPopup," add the popup to the
"m_OldEmailCSToolBar" and then add the button to the "CommandBarPopup." Now
that I'm leaving out the "CommandBarPopup," its blowing up.

As a note: the same code works flawlessly in 2007 version of the Outlook
Add-in.

Help

"Ken Slovak - [MVP - Outlook]" wrote:

> Is m_OldEmailCSToolBar still being used and is it a valid object? You can
> only add buttons to a CommandBar or CommandBarPopup object, although the
> CommandBarPopup buttons are actually being added to the
> CommandBarPopup.CommandBar object.
>
> Does it blow up when you set the Picture property? Is this an Explorer or
> Inspector button?
>
> For WordMail Inspectors you cannot use the Picture property, you must use
> the old PasteFace method with an image put on the clipboard. That's because
> Picture takes an IPictureDisp object, which cannot be passed across process
> boundaries. As WordMail is Word subclassed by Outlook it runs in its own
> separate process and attempting to use Picture there tries to pass the
> IPictureDisp object across process boundaries. That forces an exception.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Andrew" <(E-Mail Removed)> wrote in message
> news:2EDCE898-DFE0-4A8B-8E50-(E-Mail Removed)...
> > Hello All,
> >
> > I have an Add-in developed for Outlook 2003. Before this change I was
> > adding
> > an image to the ".Picture" property of the button after initially adding
> > the
> > button to a popup object. Everything worked fine, however, I decided the
> > popup object wasn't needed when there was only one associated for a
> > toolbar.
> > The buttons where I removed the popup object throws following error when
> > its
> > been created:
> > "
> > Error HRESULT E_FAIL has been returned from a call to a COM component".
> >
> > the other buttons that have a popup, work fine. The image being added is
> > the same everywhere.
> >
> > This is the class where I create and assign the image to a global
> > variable:
> >
> > Public Class clsScaryFace
> > Inherits System.Windows.Forms.AxHost
> >
> > Public Sub New()
> > MyBase.New("59EE46BA-677D-4d20-BF10-8D8067CB8B32")
> > End Sub
> >
> > Public Sub GetScaryFace()
> > Dim scaryFaceImage As Bitmap = Nothing
> > 'Dim scaryFaceMask As Bitmap = Nothing
> > Try
> > scaryFaceImage = My.Resources.Scaryface.scaryface
> > 'scaryFaceMask = My.Resources.Scaryface.scary_mask
> >
> > If (Exists(scaryFaceImage)) Then
> > g_imgScaryFace = Convert(scaryFaceImage)
> > 'g_imgScaryFaceMask = Convert(scaryFaceMask)
> > End If
> >
> > Catch ex As Exception
> > MessageBox.Show(ex.Message)
> > Finally
> > scaryFaceImage = Nothing
> > 'scaryFaceMask = Nothing
> > End Try
> > End Sub
> >
> > Private Function Convert(ByVal Image As System.Drawing.Image) As
> > stdole.IPictureDisp
> > Convert = CType(GetIPictureDispFromPicture(Image),
> > stdole.IPictureDisp)
> > End Function
> > End Class
> >
> > This is where I add the button:
> > m_butOldEmailSyncToCS =
> > CType(m_OldEmailCSToolBar.Controls.Add(MsoControlType.msoControlButton, ,
> > , ,
> > Temporary:=True), Office.CommandBarButton)
> >
> > This is where I set the properties after which it blows up when attempting
> > to assign the g_imgScaryFace
> >
> > With m_butOldEmailSyncToCS
> > .Caption = "Save to CS"
> > .Visible = True
> > .Enabled = True
> > .Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption
> > .Picture = g_imgScaryFace
> > End With
> >
> > Anyone has any ideas what's going wrong?
> >
> > Regards,

>
>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      30th Jan 2009
You didn't answer my question, is m_OldEmailCSToolBar a CommandBar object?

So the code blows up on Outlook 2003 when you set .Picture. If you comment
out adding the image using .Picture everything's OK?

My guess is that you are actually in WordMail and that's the cause of the
error. Do you actually test for Inspector.IsWordMail() in your code?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Andrew" <(E-Mail Removed)> wrote in message
news:3017E83A-0429-4964-9340-(E-Mail Removed)...
> Thanks for the response,
>
> m_OldEmailCSToolBar is a global variable in the wrapper class for the
> inspector. Yes, it is an Inspector Object, its an existing email item that
> was opened, so No "WordMail."
>
> Yes, it blows up on the when I set the Picture property. I've stepped
> through the code and all the objects are valid. As I mentioned earlier, it
> works fine when I create a "CommandBarPopup," add the popup to the
> "m_OldEmailCSToolBar" and then add the button to the "CommandBarPopup."
> Now
> that I'm leaving out the "CommandBarPopup," its blowing up.
>
> As a note: the same code works flawlessly in 2007 version of the Outlook
> Add-in.
>
> Help


 
Reply With Quote
 
Andrew
Guest
Posts: n/a
 
      30th Jan 2009
Yes "m_OldEmailCSToolBar" is a commandbar object and it is valid at the time
i'm adding the buttons.

Yes I also check the Inspector.IsWordMail() property, because i've noticed
the issues associated with it.

Yes, the code works fine when I comment out the .Picture assignment.

"Ken Slovak - [MVP - Outlook]" wrote:

> You didn't answer my question, is m_OldEmailCSToolBar a CommandBar object?
>
> So the code blows up on Outlook 2003 when you set .Picture. If you comment
> out adding the image using .Picture everything's OK?
>
> My guess is that you are actually in WordMail and that's the cause of the
> error. Do you actually test for Inspector.IsWordMail() in your code?
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Andrew" <(E-Mail Removed)> wrote in message
> news:3017E83A-0429-4964-9340-(E-Mail Removed)...
> > Thanks for the response,
> >
> > m_OldEmailCSToolBar is a global variable in the wrapper class for the
> > inspector. Yes, it is an Inspector Object, its an existing email item that
> > was opened, so No "WordMail."
> >
> > Yes, it blows up on the when I set the Picture property. I've stepped
> > through the code and all the objects are valid. As I mentioned earlier, it
> > works fine when I create a "CommandBarPopup," add the popup to the
> > "m_OldEmailCSToolBar" and then add the button to the "CommandBarPopup."
> > Now
> > that I'm leaving out the "CommandBarPopup," its blowing up.
> >
> > As a note: the same code works flawlessly in 2007 version of the Outlook
> > Add-in.
> >
> > Help

>
>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      30th Jan 2009
Well, the only reasons that I know of why setting Picture would cause an
exception is if you pass it something other than an IPictureDisp object, or
if you pass the IPictureDisp object across process boundaries (WordMail 2003
or earlier).

What happens if you put a BMP image on the clipboard, and use PasteFace
instead of setting Picture?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Andrew" <(E-Mail Removed)> wrote in message
news:FCC0F8FD-B404-4EF6-B79F-(E-Mail Removed)...
> Yes "m_OldEmailCSToolBar" is a commandbar object and it is valid at the
> time
> i'm adding the buttons.
>
> Yes I also check the Inspector.IsWordMail() property, because i've noticed
> the issues associated with it.
>
> Yes, the code works fine when I comment out the .Picture assignment.


 
Reply With Quote
 
Andrew
Guest
Posts: n/a
 
      30th Jan 2009

"What happens if you put a BMP image on the clipboard, and use PasteFace
instead of setting Picture?"

Haven't tried that, will attempt it to see.
"Ken Slovak - [MVP - Outlook]" wrote:

> Well, the only reasons that I know of why setting Picture would cause an
> exception is if you pass it something other than an IPictureDisp object, or
> if you pass the IPictureDisp object across process boundaries (WordMail 2003
> or earlier).
>
> What happens if you put a BMP image on the clipboard, and use PasteFace
> instead of setting Picture?
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Andrew" <(E-Mail Removed)> wrote in message
> news:FCC0F8FD-B404-4EF6-B79F-(E-Mail Removed)...
> > Yes "m_OldEmailCSToolBar" is a commandbar object and it is valid at the
> > time
> > i'm adding the buttons.
> >
> > Yes I also check the Inspector.IsWordMail() property, because i've noticed
> > the issues associated with it.
> >
> > Yes, the code works fine when I comment out the .Picture assignment.

>
>

 
Reply With Quote
 
Hichem S
Guest
Posts: n/a
 
      4th Feb 2009
As Ken said you are probably passing the IPictureDisp object across process
boundaries which is not possible. you have no choice that using PasteFace,
but you won't be able to make the image transparent.
Actually you can but it's really complex..I saw something, but I don't
remember where, that enables you to make the image transparent...

Hichem


"Andrew" wrote:

>
> "What happens if you put a BMP image on the clipboard, and use PasteFace
> instead of setting Picture?"
>
> Haven't tried that, will attempt it to see.
> "Ken Slovak - [MVP - Outlook]" wrote:
>
> > Well, the only reasons that I know of why setting Picture would cause an
> > exception is if you pass it something other than an IPictureDisp object, or
> > if you pass the IPictureDisp object across process boundaries (WordMail 2003
> > or earlier).
> >
> > What happens if you put a BMP image on the clipboard, and use PasteFace
> > instead of setting Picture?
> >
> > --
> > Ken Slovak
> > [MVP - Outlook]
> > http://www.slovaktech.com
> > Author: Professional Programming Outlook 2007.
> > Reminder Manager, Extended Reminders, Attachment Options.
> > http://www.slovaktech.com/products.htm
> >
> >
> > "Andrew" <(E-Mail Removed)> wrote in message
> > news:FCC0F8FD-B404-4EF6-B79F-(E-Mail Removed)...
> > > Yes "m_OldEmailCSToolBar" is a commandbar object and it is valid at the
> > > time
> > > i'm adding the buttons.
> > >
> > > Yes I also check the Inspector.IsWordMail() property, because i've noticed
> > > the issues associated with it.
> > >
> > > Yes, the code works fine when I comment out the .Picture assignment.

> >
> >

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      5th Feb 2009
It takes a whole lot of complex Win32 API type code to mask the image on the
clipboard when you have to use PasteFace. I believe there's a KB article for
it, but as I recall it didn't cover all bases and take care of everything
that I ended up having to do.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Hichem S" <(E-Mail Removed)> wrote in message
news:CB4FF991-76B4-41B0-A889-(E-Mail Removed)...
> As Ken said you are probably passing the IPictureDisp object across
> process
> boundaries which is not possible. you have no choice that using PasteFace,
> but you won't be able to make the image transparent.
> Actually you can but it's really complex..I saw something, but I don't
> remember where, that enables you to make the image transparent...
>
> Hichem


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selection.Copy throws an Object Required error =?Utf-8?B?dGhlMDBzbm9vcHk=?= Microsoft Excel Programming 2 13th Aug 2007 06:20 PM
onclick button event throws compiler error wardy1975@gmail.com Microsoft ASP .NET 3 17th Mar 2006 08:08 PM
Dynamically added user control throws object not set andyrich_1@hotmail.com Microsoft ASP .NET 1 3rd Jan 2006 01:58 PM
__doPostBack throws object expected error Kavitha N via DotNetMonster.com Microsoft VB .NET 0 1st Mar 2005 09:24 AM
image button and popup message? Craig Buchanan Microsoft ASP .NET 1 17th Mar 2004 05:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:46 PM.