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:
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?
Solved! Go to Solution.
Is this of any help?
This type of conversions are suitable to implement as Extension methods:
public static stdole.IPictureDisp ImageToPictureDisp(this Image image)
on the basis of the comment of JohanLarsson, I'd like to suggest you take a look at the blog below. It contains more codes.
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.
Sherbrooke, Qc, CAN
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
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...
about converting IPicture to Bitmap, probably this link is helpful to you:
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.
Thanks you Xiaodong!!
This link resolved my problem. With the AxHost, I can converted the Ipicture to Image!!