- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all, hoping someone has run into this or something similar before. I have been working on an addin, off and on for the last year or so. Yesterday afternoon, everything was fine. I was building, deploying and debugging and everything was fine.
Then, suddenly, none of my UI was visible. I dug in and found out that there was an exception being thrown in the below code.
ButtonDefinition = commandManager.ControlDefinitions.AddButtonDefinition(
DisplayName,
InternalName,
Classification,
ClientId,
Description,
ToolTipText,
standardIconPict,
largeIconPict,
ButtonDisplay
);
// EXCEPTION THROWN ON ABOVE STATEMENT
// System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
The above code is called from a base class for ButtonCommands so it is used in a lot of places, not just this project. Most of the items are just properties, the exception being the IPictureDisp parameters.
I suspected that these were the issue so changed the values for the icons to null and now the buttons loaded, but of course had no icons for the buttons.
My normal procedure is to store the png's for the buttons as embedded resources. The base class loads the embedded resource in as a bitmap object and then passes it to the converter to get the IPictureDisp.
The converter is probably pretty familiar as it came from a blog post from ex-ADN Phillipe L which is below.
public class PngConverterOle
{
[DllImport("OleAut32.dll", EntryPoint = "OleCreatePictureIndirect", ExactSpelling = true, PreserveSig = false)]
private static extern stdole.IPictureDisp OleCreatePictureIndirect([MarshalAs(UnmanagedType.AsAny)] object picdesc, ref Guid iid, [MarshalAs(UnmanagedType.Bool)] bool fOwn);
static Guid iPictureDispGuid = typeof(stdole.IPictureDisp).GUID;
private static class PICTDESC
{
//Picture Types
public const short PICTYPE_UNINITIALIZED = -1;
public const short PICTYPE_NONE = 0;
public const short PICTYPE_BITMAP = 1;
public const short PICTYPE_METAFILE = 2;
public const short PICTYPE_ICON = 3;
public const short PICTYPE_ENHMETAFILE = 4;
[StructLayout(LayoutKind.Sequential)]
public class Bitmap
{
internal int cbSizeOfStruct = Marshal.SizeOf(typeof(PICTDESC.Bitmap));
internal int picType = PICTDESC.PICTYPE_BITMAP;
internal IntPtr hbitmap = IntPtr.Zero;
internal IntPtr hpal = IntPtr.Zero;
internal int unused;
internal Bitmap(System.Drawing.Bitmap bitmap)
{
this.hbitmap = bitmap.GetHbitmap();
}
}
}
public static stdole.IPictureDisp ToIPictureDisp(System.Drawing.Bitmap bmp)
{
PICTDESC.Bitmap pictBmp = new PICTDESC.Bitmap(bmp);
var result = PngConverterOle.OleCreatePictureIndirect(pictBmp, ref iPictureDispGuid, false);
return result;
}
}
The crazy thing is that this code hasn't changed since summer 2021 and the icons haven't changed since before that.
Things I have tried:
- updated Inventor
- tried different versions of Autodesk.Inventor.interop
- tried using AxHost to do the conversion (doesn't work in MTA thread apartment)
- verified that png's are loading and correct size
- tried Inventor 2019, 2021 and 2022
- rebooted (desperation)
I am going to try and uninstall and re-install the different Inventor versions, but in the meantime, wanted to get this out there in case someone has see this before.
Thanks all!
Solved! Go to Solution.