Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I'm running into a problem with an addin I am developing. I'm trying to override the icon of an assembly browser folder, for this I'm adding a ClientNodeResource. I have an image (bmp/icon both failed) that I want to use as the icon of the folder.
For testing purposed I am running the code from a forms application that hooks into Inventor.
This is the code I am using to add the resource.
var panes = assembly.BrowserPanes;
var clientNodeResources = panes.ClientNodeResources;
var resourceId = "TestResource";
var bmp = Properties.Resources.duplicate_bmp;
var pictureDisp = PictureDispConverter.ToIPictureDisp(bmp);
ClientNodeResource clientNodeResource;
try
{
clientNodeResource = clientNodeResources.ItemById(resourceId, 1);
}
catch (Exception ex)
{
clientNodeResource = clientNodeResources.Add(resourceId, 1, pictureDisp);
}
I'm using the following class to convert from bmp/icon to IPictureDisp. I have a feeling theres something wrong with the conversion. I can't find the LoadPicture(path) method that I see in examples.
Does anybody know why the Catastrophic Failure error is being thrown?
public sealed class PictureDispConverter
{
[DllImport("OleAut32.dll", EntryPoint = "OleCreatePictureIndirect", ExactSpelling = true, PreserveSig = false)]
private extern static stdole.IPictureDisp OleCreatePictureIndirect([MarshalAs(UnmanagedType.AsAny)] object picdesc, ref Guid iid, [MarshalAs(UnmanagedType.Bool)] bool fOwn);
private static Guid iPictureDispGuid = typeof(stdole.IPictureDisp).GUID;
private sealed class PICTDESC
{
private PICTDESC()
{
}
// Picture Types
public const short PICTYPE_BITMAP = 1;
public const short PICTYPE_ICON = 3;
[StructLayout(LayoutKind.Sequential)]
public class Icon
{
internal int cbSizeOfStruct = Marshal.SizeOf(typeof(PICTDESC.Icon));
internal int picType = PICTDESC.PICTYPE_ICON;
internal IntPtr hicon = IntPtr.Zero;
internal int unused1;
internal int unused2;
internal Icon(System.Drawing.Icon icon)
{
this.hicon = icon.ToBitmap().GetHicon();
}
}
[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.Icon icon)
{
PICTDESC.Icon pictIcon = new PICTDESC.Icon(icon);
return OleCreatePictureIndirect(pictIcon, ref iPictureDispGuid, true);
}
public static stdole.IPictureDisp ToIPictureDisp(System.Drawing.Bitmap bmp)
{
PICTDESC.Bitmap pictBmp = new PICTDESC.Bitmap(bmp);
return OleCreatePictureIndirect(pictBmp, ref iPictureDispGuid, true);
}
}
Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.
Free apps: Smart Leader | Part Visibility Utility | Mate Origins
Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro
Free apps: Smart Leader | Part Visibility Utility | Mate Origins
Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro
Solved! Go to Solution.