Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have created interop dll for labview VI's.
I am using interop dll in .NET environment.
The method signature is:
public static void ReconstructRawData(byte COMPort, double[] FlowValuesFullScaleFlow, double[] TemperaturesC, ErrorCluster errorin, byte Gastype, bool ValueFormatrealunitsFalse, out ushort GasDensity, out double[,] RawData, out ushort MaxFlow, out ushort GasID, out ErrorCluster errorout);

I am calling as shown below:
byte bComPort = byte.Parse("1");
byte bGasType = byte.Parse("6");
bool blnValueFromatFalse = false;
ushort GasDensity = 0;
double[,] RawData = new double[100, 100];
//double[][] RawData = null;
ushort MaxFlow = 0;
ushort GasID = 0;
ErrorCluster ErrorIn = new ErrorCluster();
double[] dblFlowValue = new double[2];
dblFlowValue[0] = 20;
dblFlowValue[1] = 50;
double[] dblTempValue = new double[2];
dblTempValue[0] = 10;
dblTempValue[2]= 20;


But I am getting memory error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt"

Stack Trace:at System.Runtime.InteropServices.Marshal.ReadInt32(IntPtr ptr, Int32 ofs)
at System.Runtime.InteropServices.Marshal.ReadIntPtr(IntPtr ptr)
at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalArrayOut(Type arrayType, IntPtr data)
at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalOutputArray(IntPtr entryPointDataSpace, Type arrayType, Int32 terminalIndex)


Now how to send RawData(multidimentional array) to an method of interop dll?
Posted
Updated 2-Sep-10 2:37am
v3

1 solution

I've barely used labview and never used interop with it. So excuse me if I'm not a good help.

There are a couple of problems involved here.

1- By using out double[,] I'm guessing you want to get a memory block, reserved in the labview VI. This is a problem by it self. Memory blocks cannot be moved freely between managed and unmanaged code.
As you say you want to "send" a bi dimensional array to labview. You might want to try to leave no attribute (out nor ref) to the array parameter.

2- Parameters passed to "native" libraries are usually subjected to Marshalling, there is currently no implementation for a Marshalling a multi dimensional array, at least that I know of, I had to build my own some years ago.

I guess lab view should have definition for Custom Marshallers or you'll have to build your own:
http://msdn.microsoft.com/en-us/library/d3cxf9f0(v=VS.90).aspx[^]
link above has been fixed, the "x" at the very end was missing. Upss!!

Give me some Labview API references and I'll give it another look.

Good luck!!
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900