Inventor Customization

Inventor Customization

Reply
Contributor
marin_israel
Posts: 22
Registered: ‎08-24-2012
Message 1 of 9 (1,544 Views)
Accepted Solution

Convert IPictureDisp To System.Drawing.Image

1544 Views, 8 Replies
09-19-2012 01:11 PM

Hi alll,

 

I have some annoying warning : 'Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported within 32 bit processes only. To repair this, I search on this forum and I  found this link:

 

http://modthemachine.typepad.com/my_weblog/2012/02/bitmaps-without-vb6-icontoipicture.html

 

I fix 50% of my warning qith this class... but I want to display the thumbnail of my part on a form and this class do only ImageToIPictureDisp and not IPictureDispToImage.

 

Anyone have an idea to do this?

 

Thanks

Israel Marin

Sherbrooke,Qc

-------------------------------------
Israël Marin
Programmeur | Programmer
Logiflex
Valued Mentor
JohanLarsson
Posts: 425
Registered: ‎06-14-2005
Message 2 of 9 (1,532 Views)

Re: Convert IPictureDisp To System.Drawing.Image

09-20-2012 03:28 AM in reply to: marin_israel

Is this of any help?

http://blogs.msdn.com/b/andreww/archive/2007/07/30/converting-between-ipicturedisp-and-system-drawin...

-------------------------------------------------------------------------
Inventor Professional 2012 SP1 (25 seats with subscription)
Windows 7 64 bit
Lenovo D20, 12 GB RAM, Intel Xeon X5687 3.6 GHz, SSD
Quadro 4000, driver 8.17.12.9573, dual monitors
SpacePilot, driver version 6.15.3 Firmware 3.12
Valued Mentor
JohanLarsson
Posts: 425
Registered: ‎06-14-2005
Message 3 of 9 (1,531 Views)

Re: Convert IPictureDisp To System.Drawing.Image

09-20-2012 03:39 AM in reply to: JohanLarsson

This type of conversions are suitable to implement as Extension methods:

public static stdole.IPictureDisp ImageToPictureDisp(this Image image)

 

-------------------------------------------------------------------------
Inventor Professional 2012 SP1 (25 seats with subscription)
Windows 7 64 bit
Lenovo D20, 12 GB RAM, Intel Xeon X5687 3.6 GHz, SSD
Quadro 4000, driver 8.17.12.9573, dual monitors
SpacePilot, driver version 6.15.3 Firmware 3.12
ADN Support Specialist
xiaodong.liang
Posts: 1,271
Registered: ‎06-12-2011
Message 4 of 9 (1,518 Views)

Re: Convert IPictureDisp To System.Drawing.Image

09-23-2012 11:23 PM in reply to: marin_israel

on the basis of the comment of 



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Contributor
marin_israel
Posts: 22
Registered: ‎08-24-2012
Message 5 of 9 (1,503 Views)

Re: Convert IPictureDisp To System.Drawing.Image

09-25-2012 09:04 AM in reply to: xiaodong.liang

Hi guys, thanks for your replies.

 

I checked your link, but I'm able to do this operation.

 

My question is only to stop having the warning :

"Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported within 32 bit processes only"

 

Ths link I posted before on this topic is the answer but just for "ImageToIPictureDisp" but I have to do the inverse.

 

Thanks again!

Israel Marin

Sherbrooke, Qc, CAN

-------------------------------------
Israël Marin
Programmeur | Programmer
Logiflex
ADN Support Specialist
xiaodong.liang
Posts: 1,271
Registered: ‎06-12-2011
Message 6 of 9 (1,469 Views)

Re: Convert IPictureDisp To System.Drawing.Image

10-10-2012 02:54 AM in reply to: marin_israel

for the warining "Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported within 32 bit processes only", the MSDN link http://go.microsoft.com/fwlink/?linkid=160862' provides several solutions, you can fix this problem using anyone of them. (I copied them below for your convenience)

 

Actually the warning message only appears if the target version of the .NET framework is set to 4. So you must be using 4.0. Inventor 2012 is designed to use.net 3.5. I would suggest you to use .net 3.5 too if you are using Inventor 2012. Thus that warning will be gone and the old code works without problem.

 

As to the second solution, we also have a sample code for achieving conversion from Icon to IPictureDisp, this should work under .Net 4.0. The sample is enclosed in the bottom of this post. So you can use it to replace the Microsoft.VisualBasic.Compatibility.dll.

 

As to the third solution. It says you can just ignore that warning if you use VS2010 as that warning has no impact on your application, its title says "supported within 32 bit processes only" though.

 

Personally, I would suggest using the first solution.

 

 

Public NotInheritable Class PictureDispConverter
        <DllImport("OleAut32.dll", EntryPoint:="OleCreatePictureIndirect", ExactSpelling:=True, PreserveSig:=False)> _
        Private Shared Function OleCreatePictureIndirect( _
            <MarshalAs(UnmanagedType.AsAny)> ByVal picdesc As Object, _
            ByRef iid As Guid, _
            <MarshalAs(UnmanagedType.Bool)> ByVal fOwn As Boolean) As stdole.IPictureDisp
        End Function

        Shared iPictureDispGuid As Guid = GetType(stdole.IPictureDisp).GUID

        Private NotInheritable Class PICTDESC
            Private Sub New()
            End Sub

            'Picture Types
            Public Const PICTYPE_UNINITIALIZED As Short = -1
            Public Const PICTYPE_NONE As Short = 0
            Public Const PICTYPE_BITMAP As Short = 1
            Public Const PICTYPE_METAFILE As Short = 2
            Public Const PICTYPE_ICON As Short = 3
            Public Const PICTYPE_ENHMETAFILE As Short = 4

            <StructLayout(LayoutKind.Sequential)> _
            Public Class Icon
                Friend cbSizeOfStruct As Integer = Marshal.SizeOf(GetType(PICTDESC.Icon))
                Friend picType As Integer = PICTDESC.PICTYPE_ICON
                Friend hicon As IntPtr = IntPtr.Zero
                Friend unused1 As Integer
                Friend unused2 As Integer

                Friend Sub New(ByVal icon As System.Drawing.Icon)
                    Me.hicon = icon.ToBitmap().GetHicon()
                End Sub
            End Class

            <StructLayout(LayoutKind.Sequential)> _
            Public Class Bitmap
                Friend cbSizeOfStruct As Integer = Marshal.SizeOf(GetType(PICTDESC.Bitmap))
                Friend picType As Integer = PICTDESC.PICTYPE_BITMAP
                Friend hbitmap As IntPtr = IntPtr.Zero
                Friend hpal As IntPtr = IntPtr.Zero
                Friend unused As Integer

                Friend Sub New(ByVal bitmap As System.Drawing.Bitmap)
                    Me.hbitmap = bitmap.GetHbitmap()
                End Sub
            End Class
        End Class

        Public Shared Function ToIPictureDisp(ByVal icon As System.Drawing.Icon) As stdole.IPictureDisp
            Dim pictIcon As New PICTDESC.Icon(icon)
            Return OleCreatePictureIndirect(pictIcon, iPictureDispGuid, True)
        End Function

        Public Shared Function ToIPictureDisp(ByVal bmp As System.Drawing.Bitmap) As stdole.IPictureDisp
            Dim pictBmp As New PICTDESC.Bitmap(bmp)
            Return OleCreatePictureIndirect(pictBmp, iPictureDispGuid, True)
        End Function
    End Class

 

 



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Contributor
marin_israel
Posts: 22
Registered: ‎08-24-2012
Message 7 of 9 (1,457 Views)

Re: Convert IPictureDisp To System.Drawing.Image

10-10-2012 05:36 AM in reply to: xiaodong.liang

Thanks for the 3 ways to fix the warning...

 

1-I use Inventor 2013, who supported only framework4.

 

2-As I say in previous post, I use this sample code but it's a one way converter. I can convert BMP to IPicture, but no, IPicture to BMP... because I want to show preview of ASM in a thumbnail.

 

3-I know I can ignore the warning but it's annoying. I have about 50 warnings...

 

 

 

 

-------------------------------------
Israël Marin
Programmeur | Programmer
Logiflex
ADN Support Specialist
xiaodong.liang
Posts: 1,271
Registered: ‎06-12-2011
Message 8 of 9 (1,436 Views)

Re: Convert IPictureDisp To System.Drawing.Image

10-16-2012 03:05 AM in reply to: marin_israel

about converting IPicture to Bitmap, probably this link is helpful to you:

 

http://blogs.msdn.com/b/andreww/archive/2007/07/30/converting-between-ipicturedisp-and-system-drawin...

 

If you just want to use the ability directly without implementing yourself, you could use the InventorViewControlLib Inventor provides. The SDK sample is a demo.

  SDK\DeveloperTools\Samples\VCSharp.NET\Standalone Applications\ApprenticeServer\FileDisplay



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Contributor
marin_israel
Posts: 22
Registered: ‎08-24-2012
Message 9 of 9 (1,427 Views)

Re: Convert IPictureDisp To System.Drawing.Image

10-16-2012 05:10 AM in reply to: xiaodong.liang

Thanks you Xiaodong!!

 

This link resolved my problem. With the AxHost, I can converted the Ipicture to Image!!

 

Israel Marin

Sherbrooke, Qc,CA

-------------------------------------
Israël Marin
Programmeur | Programmer
Logiflex
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.