![]() |
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, |
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, |
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, |
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 :) |
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 :) |
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. |
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. |
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. |
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 |
All times are GMT +1. The time now is 12:31 PM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com