COM Object Error

GrexD

Well-known member
Joined
Mar 5, 2008
Messages
95
Programming Experience
Beginner
I've only programmed a bit in VB.Net 2005 after 15 years of VB 2 through 6. The transition hasn't been too bad, but I really get stuck on some of the errors generated when trying to convert VB6 code to VB.Net. The paragraph below means nothing to me.

Unable to cast COM object of type 'System.__ComObject' to class type 'System.Drawing.Image'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

VB.NET:
        Dim w As Integer
        Dim h As Integer
		If Not img Is Nothing Then
			
			While (prcs.Filters.Count > 0)
				prcs.Filters.Remove(1)
			End While
			
			prcs.Filters.Add(prcs.FilterInfos("Scale").FilterID)
			
			prcs.Filters(1).Properties(1).let_Value(aspTiff.Width * 2)
			prcs.Filters(1).Properties(2).let_Value(aspTiff.Height * 2)
			
			thmb = prcs.Apply(img)
			
			If Not thmb Is Nothing Then
				If thmb.FrameCount = img.FrameCount Then
					thmb.ActiveFrame = img.ActiveFrame
				End If
				'UPGRADE_WARNING: Couldn't resolve default property of object w. Click for more: 
'ms-help://MS.VSCC.v80/dv_commoner/local/
redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				w = thmb.Width
				h = thmb.Height
'UPGRADE_WARNING: Couldn't resolve default 
property of object w. Click for more: 
'ms-help://MS.VSCC.v80/dv_commoner/local/
redirect.htm?keyword=
"6A50421D-15FE-4896-8A1B-2EC21E9037B2"'


                aspTiff.Picture = thmb.ARGBData.Picture(w, h)
            End If
		End If
		
		If img.FrameCount > 1 Then
			lblImgCount.Text = img.FrameCount & " pages in the fax."
			hscFrame.Minimum = 1
			hscFrame.Maximum = (img.FrameCount + hscFrame.LargeChange - 1)
			hscFrame.Value = img.ActiveFrame
			hscFrame.Visible = True
		Else
			hscFrame.Visible = False
			lblImgCount.Text = "One page in the fax."
		End If
The error happens on the line "aspTiff.Picture = thmb.ARGBData.Picture(w, h)"

aspTiff is a PictureBox
thmb is WIA.ImageFile (Windows Image Acquisition Library)

VB 2005 added several of the "UPGRADE_WARNING: Couldn't resolve default property of object w. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'"

The "Click for more" does nothing because they aren't really links. Very frustrating. The code worked perfectly in VB6. Any help is appreciated.

Greg
 
Last edited by a moderator:
Well the error message is pretty clear, System.Drawing.Image is a type in the framework and you have access to your image only through the interface that the COM component you are using has provided. I would hazard a guess and say that if you saved this image file to disk and then loaded it into your app as a valid System.Drawing.Image that should fix your problem.

Although I would hope there is a cleaner way... but i'll need to look into it.
 
Just out if interest I take it you are using the wiaaut.dll (Windows Image Aquisition Automation Library)? If so then by adding a reference to this in your project and using the .Net wrapper that gets generated for you to use it you should'nt have any problems.
 
Well the error message is pretty clear, System.Drawing.Image is a type in the framework and you have access to your image only through the interface that the COM component you are using has provided.

After reading that I'm reminded of the time I got a job at a TV station. On the second day I asked my boss how do I start run the emergency broadcast system test. His answer, "Oh, you just run the emergency broadcast system in test mode"

I would hazard a guess and say that if you saved this image file to disk and then loaded it into your app as a valid System.Drawing.Image that should fix your problem.

Although I would hope there is a cleaner way... but i'll need to look into it.

The image is already on the disk. It is trying to load the file for viewing.
 
Just out if interest I take it you are using the wiaaut.dll (Windows Image Aquisition Automation Library)? If so then by adding a reference to this in your project

Did that first thing even though I assumed it was added when the project was converted from VB6 by VS2005.

and using the .Net wrapper that gets generated for you to use it you should'nt have any problems.

You could be on to something here. Where might one look for the ".Net wrapper that gets generated". Like I said, .NET is a new animal to me.
 
The image is already on the disk. It is trying to load the file for viewing.

I ment if you save the file using the wiaaut.dll interface back to disk as a .jpg or .bmp then reload it using the image class. Again, not very clean but this doesn't seem to be well documented.
 
I ment if you save the file using the wiaaut.dll interface back to disk as a .jpg or .bmp then reload it using the image class. Again, not very clean but this doesn't seem to be well documented.

Well, thanks anyway. I don't think that will really solve anything. This code works in VB 6 exactly as it is written. Even if it did work. I need the image as a tif in its original format.
 
I guess I just don't understand what it is supposed to accomplish. I'm trying to load in the image off the disk and view the image in a picture box. You are suggesting that I save the image to disk and then load it to view. If I can't load it in the first place, what will I accomplish by trying to save it to disk.

I really do appreciate your help. Perhaps I didn't fully explain what i was doing. I think this COM Wrapper you mentioned could be the key. I'm researching that now.
 
When you use a COM component .Net automatically creates a wrapper so you can use the Interface provided. That's all.

I appreciate this, but it doesn't mean anything to me. As I said before, .Net is all very new to me. Instead of telling me to use the COM interface provider you might as well tell me to use the .Net Johnson Rod to configure my Whippet Flange.

I'll get it eventually, but right now I don't get it.
 
Whatever ARGBData.Picture returns it is not a .Net Image type. The suggested solution is for you to take what you have in ARGBData.Picture and save it to disk to a valid image format if the library you are using permits. Then you use Image.FromFile(filename) to load that to PictureBox.Image.

Try this also:
VB.NET:
picbox.Image = Compatibility.VB6.IPictureDispToImage(wia.ARGBData.Picture)
For Compatibility.VB6 you need to Add Reference to the .Net library Microsoft.VisualBasic.Compatibility.dll.
 
Whatever ARGBData.Picture returns it is not a .Net Image type. The suggested solution is for you to take what you have in ARGBData.Picture and save it to disk to a valid image format if the library you are using permits. Then you use Image.FromFile(filename) to load that to PictureBox.Image.

Try this also:
VB.NET:
picbox.Image = Compatibility.VB6.IPictureDispToImage(wia.ARGBData.Picture)
For Compatibility.VB6 you need to Add Reference to the .Net library Microsoft.VisualBasic.Compatibility.dll.


Thank you! English language words I can understand, and more importantly, solve the problem.

It works I can view the image!!!!
 
Back
Top