08-14-2010 03:57 PM
I'm working with the Test Stand API in .NET and trying to call some legacy code written in CVI and I've hit a wall.
One of the functions I'm calling has a CAObjHandle parameter that is being used to retrieve test limits:
TS_PropertyGetValNumber (limitsHandle, NULL, "Limits.High" , 0, &highLimit);
I've created a PropertyObject in .NET containing these values, but when I try to call the native function passing a reference to the PropertyObject directly calling TS_PropertyGetValNumber results in an error.
[DllImport("LegacyTest.dll", CallingConvention = CallingConvention.StdCall)]
public static extern void power_up([MarshalAs(UnmanagedType.LPArray, SizeConst = 10)] double[] measurements,
ref PropertyObject limitsHandle);
PropertyObject po =BuildLimitsPropertyObject();
power_up(meas, ref po);
Has anyone here been successful with this or something similar? Any ideas on what to try next?
Solved! Go to Solution.
08-16-2010 08:59 AM
A CVI CAObjHandle is an integer that is a handle to a COM interface pointer. You cannot automatically convert a .NET COM pointer to a CAObjHandle using COM interop. I would first consider rewriting the CVI code in .NET. If that's not an option, you could try calling the CVI function CA_CreateObjHandleFromInterface to create the handle and then use CA_DiscardObjHandle to release it after the function call. Both of these functions are in cviauto.dll.
08-16-2010 12:41 PM
Thanks, calling CA_CreateObjHandleFromIDispatch and passing in the .NET PropertyObject worked perfectly.