• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    Posts: 25
    Registered: ‎11-01-2006
    Accepted Solution

    Another DWGThumbnail post

    1270 Views, 7 Replies
    04-29-2011 08:13 AM

    Sorry - but I just can't get this thing to work (DWGThumbnail).  I have read everything I could find.

     

    Here is my problem in a nutshell:  I am creating a Windows forms application that includes the AutoCAD DWG Thumbnail OCX control on the form.  I can't get this to work on a Windows 7 64bit machine. 

     

    On my develpment machine (which is Windows Vista 32 bit), I created a small Winform app, added the COM AutoCAD Thumbnail OCX reference (DWGTHUMBNAIL.OCX) version 2.0.

     

    Then placed this control on my form.  Visual Studio then adds the references to the project: Interop.DWGTHUMBNAILLib.dll and AxInterop.DWGTHUMBNAILLib.dll.  I set them to 'Copy Local'.  So far so good.

     

    I run the project in debug mode and it starts and runs fine (on the development machine).

     

    I publish the app using ClickOnce (how I have deployed many apps).

     

    Install the app on the Win7 64 bit machine and get: 'Exception from HRESULT: 0x80040154 REGDB_E_CLASSNOTREG...'

     

    I have tried copying Both DLL's and registering them with Regsvr32, I have tried using Regasm, every which way!

     

    Is this the correct version of the DWG Thumbnail control?

    Why can't Autodesk make a .Net assembly of it???

     

    Note - I am not a member of ADN, so I can't get any stuff there.

     

    Help!!! :smileysad:

     

    Please use plain text.
    Contributor
    Posts: 25
    Registered: ‎11-01-2006

    Re: Another DWGThumbnail post

    04-29-2011 08:45 AM in reply to: jshipley

    What about 3rd party options?  Are there any out there?  I'd be willing to pay for a reliable, stable .Net AutoCAD thumbnail control.  This seems harder than it should be...

     

    Thanks

    Please use plain text.
    Distinguished Contributor
    Posts: 112
    Registered: ‎04-22-2009

    Re: Another DWGThumbnail post

    04-29-2011 10:01 AM in reply to: jshipley

    Hi there please look at the attached class file.

     

    This should help you. More info about this class can be found at the swamp.

     

    http://www.theswamp.org/index.php#2

     

    Kind regards,

     

    Irvin

    Please use plain text.
    Contributor
    Posts: 25
    Registered: ‎11-01-2006

    Re: Another DWGThumbnail post

    04-29-2011 10:08 AM in reply to: Irvin

    Thanks - I have not registered at TheSwamp yet, but the class file looks good, do you possibly have it in VB?

     

    Please use plain text.
    Distinguished Contributor
    Posts: 112
    Registered: ‎04-22-2009

    Re: Another DWGThumbnail post

    04-29-2011 10:15 AM in reply to: jshipley
    Imports System
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Imports System.IO
    Imports System.Runtime.InteropServices
    Imports System.Windows.Forms
    
    Class acThumbnailReader
    
    	<StructLayout(LayoutKind.Sequential)> _
    	Private Structure BITMAPINFOHEADER
    		Public biSize As Integer
    		Public biWidth As Integer
    		Public biHeight As Integer
    		Public biPlanes As Short
    		Public biBitCount As Short
    		Public biCompression As Integer
    		Public biSizeImage As Integer
    		Public biXPelsPerMeter As Integer
    		Public biYPelsPerMeter As Integer
    		Public biClrUsed As Integer
    		Public biClrImportant As Integer
    	End Structure
    
    	<StructLayout(LayoutKind.Sequential)> _
    	Private Structure IMGREC
    		Public bytType As Byte
    		Public lngStart As Integer
    		Public lngLen As Integer
    	End Structure
    
    	<StructLayout(LayoutKind.Sequential)> _
    	Private Structure RGBQUAD
    		Public rgbBlue As Byte
    		Public rgbGreen As Byte
    		Public rgbRed As Byte
    		Public rgbReserved As Byte
    	End Structure
    
    	Public Shared Function GetThumbnail(strFile As String) As Bitmap
    		Return GetThumbnail(strFile, True, False, "")
    	End Function
    
    	Public Shared Function GetThumbnail(strFile As String, boolRetainBackColor As Boolean) As Bitmap
    		Return GetThumbnail(strFile, boolRetainBackColor, False, "")
    	End Function
    
    	Public Shared Function GetThumbnail(strFile As String, boolRetainBackColor As Boolean, boolSaveToFile As Boolean) As Bitmap
    		Return GetThumbnail(strFile, boolRetainBackColor, boolSaveToFile, "")
    	End Function
    
    	Public Shared Function GetThumbnail(strFile As String, boolRetainBackColor As Boolean, boolSaveToFile As Boolean, strSaveName As String) As Bitmap
    		Dim bmp As New Bitmap(1, 1, PixelFormat.Format8bppIndexed)
    		Dim bytCnt As Byte
    		Dim bytBMPBuff As Byte()
    		Dim lngImgLoc As Integer
    		Dim fs As FileStream = Nothing
    		Dim br As BinaryReader = Nothing
    		Dim lngCurLoc As Integer
    		Dim lngY As Integer
    		Dim lngX As Integer
    		Dim lngColor As Integer
    		Dim lngCnt As Integer
    		Dim intCnt As Short
    		Dim udtRec As IMGREC
    		Dim udtColors As RGBQUAD()
    		Dim udtColor As RGBQUAD
    		Dim udtHeader As BITMAPINFOHEADER
    		Dim intRed As Short
    		Dim intGreen As Short
    		Dim intBlue As Short
    		Try
    			If File.Exists(strFile) Then
    				fs = File.OpenRead(strFile)
    				br = New BinaryReader(fs)
    				fs.Seek(13, SeekOrigin.Begin)
    				lngImgLoc = br.ReadInt32()
    				fs.Seek(lngImgLoc + 17, SeekOrigin.Begin)
    				lngCurLoc = lngImgLoc + 17
    				fs.Seek(lngCurLoc + 3, SeekOrigin.Begin)
    				bytCnt = br.ReadByte()
    				If bytCnt > 1 Then
    					For intCnt = 0 To bytCnt - 1
    						udtRec.bytType = br.ReadByte()
    						udtRec.lngStart = br.ReadInt32()
    						udtRec.lngLen = br.ReadInt32()
    						If udtRec.bytType = 2 Then
    							fs.Seek(udtRec.lngStart, SeekOrigin.Begin)
    							udtHeader.biSize = br.ReadInt32()
    							udtHeader.biWidth = br.ReadInt32()
    							udtHeader.biHeight = br.ReadInt32()
    							udtHeader.biPlanes = br.ReadInt16()
    							udtHeader.biBitCount = br.ReadInt16()
    							udtHeader.biCompression = br.ReadInt32()
    							udtHeader.biSizeImage = br.ReadInt32()
    							udtHeader.biXPelsPerMeter = br.ReadInt32()
    							udtHeader.biYPelsPerMeter = br.ReadInt32()
    							udtHeader.biClrUsed = br.ReadInt32()
    							udtHeader.biClrImportant = br.ReadInt32()
    							bytBMPBuff = New Byte(udtRec.lngLen) {}
    							If udtHeader.biBitCount = 8 Then
    								udtColors = New RGBQUAD(255) {}
    								For count As Integer = 0 To 255
    									udtColors(count).rgbBlue = br.ReadByte()
    									udtColors(count).rgbGreen = br.ReadByte()
    									udtColors(count).rgbRed = br.ReadByte()
    									udtColors(count).rgbReserved = br.ReadByte()
    								Next
    								fs.Seek(udtRec.lngStart - 1, SeekOrigin.Begin)
    								For count As Integer = 0 To udtRec.lngLen
    									bytBMPBuff(count) = br.ReadByte()
    								Next
    								bmp = New Bitmap(udtHeader.biWidth, udtHeader.biHeight)
    								lngCnt = 0
    								For lngY = 1 To udtHeader.biHeight
    									For lngX = udtHeader.biWidth To 1 Step -1
    										lngColor = bytBMPBuff(bytBMPBuff.GetUpperBound(0) - lngCnt)
    										udtColor = udtColors(lngColor)
    										intRed = Convert.ToInt16(udtColor.rgbRed)
    										intGreen = Convert.ToInt16(udtColor.rgbGreen)
    										intBlue = Convert.ToInt16(udtColor.rgbBlue)
    										lngColor = ColorTranslator.ToOle(Color.FromArgb(intRed, intGreen, intBlue))
    										If boolRetainBackColor = False Then
    											If lngColor = ColorTranslator.ToOle(Color.Black) Then
    												lngColor = ColorTranslator.ToOle(Color.White)
    											Else
    												If lngColor = ColorTranslator.ToOle(Color.White) Then
    													lngColor = ColorTranslator.ToOle(Color.Black)
    												End If
    											End If
    										End If
    										bmp.SetPixel(lngX - 1, lngY - 1, ColorTranslator.FromOle(lngColor))
    										lngCnt += 1
    									Next
    								Next
    							End If
    							GoTo Exit_Here
    						Else
    							If udtRec.bytType = 3 Then
    								GoTo Exit_Here
    							End If
    						End If
    					Next
    				End If
    			End If
    		Catch ex As Exception
    			MessageBox.Show(ex.Message.ToString())
    			GoTo Exit_Here
    		End Try
    		Exit_Here:
    		If br IsNot Nothing Then
    			br.Close()
    			fs.Close()
    			fs.Dispose()
    		End If
    		If boolSaveToFile = True Then
    			If strSaveName = "" Then
    				Dim fName As String
    				fName = [String].Concat(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()), ".bmp")
    				bmp.Save(fName)
    			Else
    				bmp.Save(strSaveName)
    			End If
    		End If
    		Return bmp
    	End Function
    End Class

     

    Please use plain text.
    Contributor
    Posts: 25
    Registered: ‎11-01-2006

    Re: Another DWGThumbnail post

    04-29-2011 10:33 AM in reply to: Irvin

    THANK YOU!!!!  :smileyhappy:

    That works great.  I removed the DwgThumbnail references and control, created the acThumbnailReader class, used it on my form, published it, and it works on the 64bit system.

    Thanks again.

    Jim

    Please use plain text.
    Distinguished Contributor
    Posts: 112
    Registered: ‎04-22-2009

    Re: Another DWGThumbnail post

    04-29-2011 01:20 PM in reply to: jshipley

    Glad to help you with your problem.

     

    But thanks go out to the original programmers.

     

    Kind regards,

     

    Irvin

    Please use plain text.
    Contributor
    Posts: 17
    Registered: ‎10-16-2006

    Re: Another DWGThumbnail post

    01-07-2013 10:15 PM in reply to: jshipley

    Can you explain how you used the class? (broad steps, if you can tell)

    Does it work on 32 bit m/c too?

    Regards

    Shreenivas Potnis

     

    Please use plain text.