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
Solved! Go to Solution.
Solved by xiaodong_liang. Go to Solution.
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.
http://modthemachine.typepad.com/my_weblog/2010/06/accessing-thumbnail-images.html
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
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.
SDK\DeveloperTools\Samples\VCSharp.NET\Standalone Applications\ApprenticeServer\FileDisplay
Thanks you Xiaodong!!
This link resolved my problem. With the AxHost, I can converted the Ipicture to Image!!
Israel Marin
Sherbrooke, Qc,CA
For those who are unfamiliar or do not program in C# here is the VB interpretation:
Imports System.Windows.Forms
Imports System.Drawing
Imports Inventor
''' <summary>
''' This class performs the following conversion:
''' • Image to iPictureDisplay
''' • iPictureDisplay to Image
''' </summary>
''' <remarks>
''' You must Import the following namespaces.
''' • System.Drawing
''' • System.Windows.Forms
'''
''' Note:
''' If you are using WPF then you will need to add a reference to the "System.Windows.Forms" framework to your project.
''' </remarks>
Public NotInheritable Class IPictureDispConverter : Inherits AxHost
''' <summary>
''' This method is required to impliment the AxHost.
''' You do not need to modify this sub.
''' </summary>
Private Sub New()
MyBase.New("")
End Sub
''' <summary>
''' Converts a standard image to an IPictureDisp object.
''' </summary>
''' <param name="image">[Image] Image to convert to IPictureDisp</param>
''' <returns>[IPictureDisp] or Nothing on exception.</returns>
Public Shared Function ImageToPictureDisp(image As Image) As IPictureDisp
Try
Return DirectCast(GetIPictureDispFromPicture(image), IPictureDisp)
Catch ex As Exception
'Add error message or logging here if desired.
'Handle the conversion error by simply returning Nothing.
Return Nothing
End Try
End Function
''' <summary>
''' Converts an IPictureDisp object to a standard image file.
''' </summary>
''' <param name="pictureDisp">[IPictureDisp] IPictureDisp object to convert to image.</param>
''' <returns>[Image] or Nothing on exception.</returns>
Public Shared Function PictureDispToImage(pictureDisp As IPictureDisp) As Image
Try
Return GetPictureFromIPicture(pictureDisp)
Catch ex As Exception
'Add error message or logging here if desired.
'Handle the conversion error by simply returning Nothing.
Return Nothing
End Try
End Function
End Class
Below is a Visual Studio Item Template of the code.
So is it possible to easily use this code to make an exe I can use to export thumbnails as images (like bmp or jpg) so i can use them?
I currently have a 64 bit computer, so I'm pretty sure I can't use it directly.... Then again, all the documentation about this conversion is all over the place for someone who is only a hobbyist programmer.
I tried importing it into visual studio express as a module and added the inventor reference, but I still have like 6 errors - no reference to axhost or image, mostly.
The code above will work fine in 64 bit applications. I do it on 64 bit machines using WPF.
You'll need to create the code as a Class instead of a Module.
You can't inherit the AxHost in a module.
Inherit simply means you are merging all of an inheritable classes’ methods and properties into the current class.
The "Public NotInheritable Class IPictureDispConverter : Inherits AxHost" line states that the IPictureDispConverter class inherits from the AxHost class which is in the System.Windows.Forms namespace. If you are creating a WPF application then you will need to add a reference to the System.Windows.Forms namespace in your project.
Also the code should work fine in a 64 bit environment, but if not then it may be due to how your Configuration Manager is set up in your Visual Studio project; I usually target <Any CPU>. If you are still having issues after converting to a Class and adding the reference then I will explain in further detail.
This is an old problem. IPictureDisp can't do marshall to other exe application.
You should create macro
http://modthemachine.typepad.com/my_weblog/2010/06/accessing-thumbnail-images.html
and run the macro from your exe application.
But much better use AddIn. The AddIn have not problem with IPictureDisp.
Hi
I made this iLogic rule to get the thumbnail and save it as a jpg file:
I am trying to convert the Thumbnail from a iPictureDisp to a Image object
But i get this error mesage: Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
Can somebody help me out?
Can't find what you're looking for? Ask the community or share your knowledge.