From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
05-15-2006 11:41 AM
An unhandled exception of type 'InvalidActiveXStateException' occurred in nationalinstruments.axcwimaqcontrolslib.interop.dll
vision.MatchPattern(Image, Template, MatchPatternOptions, PatternMatchReport, SearchRect);Does anyone have experience with this error? My next option is to start from one of the examples, which would hopefully result in a working program.
05-16-2006 12:17 PM
05-24-2007 01:25 AM
hi..
the 'InvalidActiveXStateException' on the title of this thread caught my attention. i am using VS .NET 2003, to develop a simple application :capture image and perform color matching.however, in my LearnColor function call, im getting an unhandled exception , 'InvalidActiveXStateException' occurred in nationalinstruments.axcwimaqcontrolslib.interop.dll..i have no idea wat this means..because i am not using any windows form controls in my application.i m not sure what could be causing this...
i didnt create the application from scratch,i kinda started working from the examples..i know for sure that my grab function is working..so wat could be causing this?
please help...
thanks
05-25-2007 02:00 PM
05-27-2007 09:16 PM
hi jasper,
yup,the example works fine.i tried it..actually,at first i tried to work from using this example..but then i switched to color matching instead of color pattern matching..and it worked fine when i developed a windows application. wat im trying to do now is call this application(as a dll) from a console application. the program halts at :
IMAQVision.LearnColor(myImage, ColInfo, ViewRect) and i get the message : An unhandled exception of type 'InvalidActiveXStateException' occurred in nationalinstruments.axcwimaqcontrolslib.interop.dll
all i can guess is there's some NI Vision control that cant be recognised or handled by a console.but i can figure out wat could it be..
i will be so grateful for any help ..thank you
05-27-2007 10:11 PM
05-29-2007 02:41 AM
05-29-2007 09:15 AM
The CLR proxy DLL is known as the Runtime Callable Wrapper (RCW) and contains a .NET version of the COM type library. It defines all objects and interfaces found in the original COM type library and the classes that implement the interfaces. Visual Studio .NET names this DLL Interop.ID.dll, where ID is the name of the type library. In your case, the name is Interop.CWIMAQControlsLib.dll. The Interop prefix denotes that the RCW incorporates services from the Interop layer, which controls marshalling and interoperability between COM and the .NET Framework.
The Windows Form proxy DLL provides a .NET control that calls the RCW. This DLL defines the properties, methods, and events you can set, call, and handle programmatically. Visual Studio names this DLL AxInterop.ID.dll, where ID is the name of the type library. In your case, the name is AxInterop.CWIMAQControlsLib.dll. The Ax prefix denotes that the wrapper classes inherit from the AxHost class to expose the ActiveX control as a Windows Forms control.
Note. The References section in the Solution Explorer will show names like AxCWIMAQControlsLib and CWIMAQControlsLib.
05-29-2007 09:40 AM - edited 05-29-2007 09:40 AM
Continued from previous post....
Now, I have called .NET assemblies that contained COM components in them from a Console Application without problems before so I know it can be done. One thing you have to be careful up is making sure what type of apartment model those COM components are in. Typically, COM runs under the STA model (single threaded apartment) so you would need to put the statement [STATHREAD] right before your Main method is called. Of course, usually you will get an error message saying that the control can't be instantiated because the current thread isn't in a single-threaded apartment.
Now as far as the InvalidStateException, as the name mentions, that exception is thrown when the ActiveX control is referenced while in an invalid state. Usually this comes from calling the public properties and methods of the ActiveX control before the referenced ActiveX control has been instantiated and initialized.
Based on that, my question to you might be how you are exactly calling the Windows Application from the Console Application? Did you include the System.Windows.Forms namespace and then using the Application class to instantiate a new form (thus this would instantiate the CWIMAQVision control)?
Continued on next post....
Message Edited by Jonathan N on 05-29-2007 09:40 AM
05-29-2007 09:41 AM
Continued from previous post...
So you would say something like:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new myWindowsApp.Form1());
}
}
}
Or does your program work when calling several methods of your Windows App but then stop when it gets to a method that uses that LearnColor method?
Anyway, just some thoughts. Also, some references I use for .NET/COM interop are Understanding COM Interop, Understanding Classic COM Interoperability With .NET Applications, and MSDN's main Interoperability page.
Hope this helps! Any of your Vision/IMAQ specific questions, I leave to the Vision/IMAQ engineers to answer.
Best Regards,