A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

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



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 29th 09, 04:08 PM posted to microsoft.public.outlook.program_addins
Andrew
external usenet poster
 
Posts: 95
Default Button throws error when image is added if there's no popup object

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(MsoControlT ype.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.msoButtonIcon AndCaption
.Picture = g_imgScaryFace
End With

Anyone has any ideas what's going wrong?

Regards,
Ads
  #2  
Old January 29th 09, 07:09 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Button throws error when image is added if there's no popup object

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" wrote in message
...
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(MsoControlT ype.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.msoButtonIcon AndCaption
.Picture = g_imgScaryFace
End With

Anyone has any ideas what's going wrong?

Regards,


  #3  
Old January 29th 09, 07:31 PM posted to microsoft.public.outlook.program_addins
Andrew
external usenet poster
 
Posts: 95
Default Button throws error when image is added if there's no popup ob

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" wrote in message
...
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(MsoControlT ype.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.msoButtonIcon AndCaption
.Picture = g_imgScaryFace
End With

Anyone has any ideas what's going wrong?

Regards,



  #4  
Old January 30th 09, 02:53 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Button throws error when image is added if there's no popup ob

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" wrote in message
...
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


  #5  
Old January 30th 09, 03:47 PM posted to microsoft.public.outlook.program_addins
Andrew
external usenet poster
 
Posts: 95
Default Button throws error when image is added if there's no popup ob

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" wrote in message
...
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



  #6  
Old January 30th 09, 08:15 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Button throws error when image is added if there's no popup ob

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" wrote in message
...
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.


  #7  
Old January 30th 09, 09:34 PM posted to microsoft.public.outlook.program_addins
Andrew
external usenet poster
 
Posts: 95
Default Button throws error when image is added if there's no popup ob


"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" wrote in message
...
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.



  #8  
Old February 4th 09, 10:42 PM posted to microsoft.public.outlook.program_addins
Hichem S
external usenet poster
 
Posts: 13
Default Button throws error when image is added if there's no popup ob

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" wrote in message
...
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.



  #9  
Old February 5th 09, 12:09 AM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Button throws error when image is added if there's no popup ob

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" wrote in message
...
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


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Image added to CommandBar Buttons Andrew Add-ins for Outlook 2 November 26th 08 02:26 PM
Redemption Pickfolder at offline throws an error Bert_Bert[_2_] Add-ins for Outlook 2 October 29th 08 09:21 PM
Outlook 2007 throws constant Error - please HELP Snig Outlook - Installation 0 May 14th 07 02:04 PM
Image added in Signature shows as attachment Sivakumar Outlook - Using Forms 0 October 4th 06 06:40 AM
Help Add button Popup Robert Outlook and VBA 7 February 17th 06 03:16 PM


All times are GMT +1. The time now is 08:53 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.