04-20-2009 05:42 AM
Hi, I want to load a .bmp file saved on my harddisk and show it in a CWIMAQViewer. I use C#.
My code:
NationalInstruments.CWIMAQControls.CWIMAQVisionClass objVision = new NationalInstruments.CWIMAQControls.CWIMAQVisionClass();
NationalInstruments.CWIMAQControls.CWIMAQImage myImageLoad = new NationalInstruments.CWIMAQControls.CWIMAQImage();
axCWIMAQViewer1.Attach(myImageLoad);
objVision.ReadImage(myImageLoad, sPath, axCWIMAQViewer1.Palette); //<<<< this throws an Exception
But the ReadImage() method throws the Exception:
"Fatal Error (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
What do i do wrong?
Solved! Go to Solution.
04-21-2009 02:44 PM
thesam -
If you don't care about the palette, I would call ReadImage() like so:
object missing = System.Type.Missing;
objVision.ReadImage(myImageLoad, sPath, missing);
Does that help?
Greg Stoll
Vision R&D
National Instruments
04-22-2009 01:41 AM
No, that does not help.
Also when i pass a null-object for the third parameter, it is the same behavior. The same exception is thrown. The StackTrace information of the exception is as follows:
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at NationalInstruments.CWIMAQControls.CWIMAQVisionClass.ReadImage(CWIMAQImage DestImage, String Path, Object ColorPalette)
I use the >>NationalInstruments.AxCWIMAQControlsLib.Interop.dll<< assembly in version 8.0.0.0
Are there any other assemblies this assembly depends on?
More ideas?
04-22-2009 10:12 AM
thesam -
there must be an example given after the installation of the Vision Development System which handles this issue. Have you checked it?
Regards, Jan
04-22-2009 10:37 AM
It seems that the problem is the assembly itself or the vision-class or something like that. Because when i call WriteImage() or DrawText() from the Vision-Class, the same error occurs.
I use Win2000, Visual Studio 2005, C#. I referenced only the assemblies >>NationalInstruments.AxCWIMAQControlsLib.Interop.dll<< and >>NationalInstruments.CWIMAQ1394.Interop.dll<< in my C# project.
All ideas are welcome...
@ Jan: What example do you mean?
04-22-2009 10:59 AM
thesam -
Can you post the code you're using for the cases where you're getting an exception?
Greg Stoll
Vision R&D
National Instruments
04-22-2009 11:11 AM
Hi Greg,
here is the code the exception occurs with DrawText():
NationalInstruments.CWIMAQControls.CWIMAQTextOptions objText = new NationalInstruments.CWIMAQControls.CWIMAQTextOptions();objText.FontName = "Arial";
objText.Size = 10;
NationalInstruments.CWIMAQControls.CWIMAQPointClass objPoint = new NationalInstruments.CWIMAQControls.CWIMAQPointClass();objPoint.X = 100;
objPoint.Y = 100;
int iWitdh = 0;NationalInstruments.CWIMAQControls.CWIMAQImage myImage2 = new NationalInstruments.CWIMAQControls.CWIMAQImage();NationalInstruments.CWIMAQControls.
AxCWIMAQVision objVision = new NationalInstruments.CWIMAQControls.AxCWIMAQVision();objVision.DrawText2(myImage, myImage2, objPoint, objText, "TEXT", ref iWitdh, false); // <<< EXCEPTION
and here the exception with ReadImage() again:
NationalInstruments.CWIMAQControls.CWIMAQVisionClass objVision = new NationalInstruments.CWIMAQControls.CWIMAQVisionClass();NationalInstruments.CWIMAQControls.CWIMAQImageClass myImageLoad = new NationalInstruments.CWIMAQControls.CWIMAQImageClass();
axCWIMAQViewer1.Attach(myImageLoad);
object missing = System.Type.Missing;
objVision.ReadImage(myImageLoad, @"C:\test.bmp", missing); // <<< EXCEPTION
04-27-2009 02:26 AM
I just tried the VB.NET example in "C:\Programme\National Instruments\Vision\Examples\MSVB.NET\1. Getting Started". There also the ReadImage() -Function is called. This example works fine.
Are there any other DLLs i have to reference in my C# project?
04-29-2009 09:40 AM
I found my mistake. I dynamically instantiated the Vision object with:
NationalInstruments.CWIMAQControls.CWIMAQVisionClass objVision = new NationalInstruments.CWIMAQControls.CWIMAQVisionClass();
That doen't work. I have to insert the Vision control "axCWIMAQVision1" in my form and work with that object:
axCWIMAQVision1.ReadImage(axCWIMAQViewer1.Image, sFileName, axCWIMAQViewer1.Palette);
08-04-2009 06:52 PM
I'm having the same problem, but I have no viewer or form - I'm working with a .NET assembly. The assembly is to read an image from the drive and perform some analysis on it - there's no UI. I am receiving the same error (to be expected as my code is the same). Here is my code:
CWIMAQVisionClass vision = new CWIMAQVisionClass();
CWIMAQImageClass image = new CWIMAQImageClass();
object missing = System.Type.Missing;vision.ReadImage(image, redLEDFileName, missing);
... Throws the exception, evertime.