NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

.NET Test Stand API and interop with CVI

Solved!
Go to solution

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("5042200.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void Initialize(ref int result, StringBuilder reportText,
            ref short errorOccurred, ref long errorCode, StringBuilder errorMessage);

 

[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?

 

0 Kudos
Message 1 of 3
(3,652 Views)
Solution
Accepted by topic author Phlamb

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.

0 Kudos
Message 2 of 3
(3,633 Views)

Thanks, calling CA_CreateObjHandleFromIDispatch and passing in the .NET PropertyObject worked perfectly.

 

 

0 Kudos
Message 3 of 3
(3,622 Views)