如何将double [,]参数传递给互操作dll方法? [英] How to pass double[,] parameter to an interop dll method?

查看:114
本文介绍了如何将double [,]参数传递给互操作dll方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为labview VI创建了interop dll.
我在.NET环境中使用interop dll.
方法签名为:
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 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;



但是我收到内存错误尝试读取或写入受保护的内存.这通常表明其他内存已损坏"

堆栈跟踪:位于 System.Runtime.InteropServices.Marshal.ReadInt32(IntPtr ptr,Int32 ofs)
在System.Runtime.InteropServices.Marshal.ReadIntPtr(IntPtr ptr)中
在NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalArrayOut(Type arrayType,IntPtr data)
在NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalOutputArray(IntPtr entryPointDataSpace,Type arrayType,Int32 terminalIndex)


现在如何将RawData(多维数组)发送到互操作dll的方法?



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?

推荐答案

我几乎没有使用过labview,也从未使用过interop.如果我帮不上忙,请原谅.

这里涉及几个问题.

1-我猜想通过使用out double[,]来获取一个在labview VI中保留的内存块.这本身就是一个问题.内存块不能在托管代码和非托管代码之间自由移动.
如您所说,您想发送"一个二维数组到labview.您可能想尝试不给array参数保留任何属性(out或ref).

2-传递给本机"库的参数通常要进行编组,目前尚无编组多维数组的实现,至少据我所知,几年前我必须构建自己的多维数组.

我想实验室视图应该为自定义编组定义,否则您将必须构建自己的编组:
http://msdn.microsoft.com/en-us/library/d3cxf9f0 (v = VS.90).aspx [
给我一些Labview API参考,我会再看一下.

祝你好运!
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!!


这篇关于如何将double [,]参数传递给互操作dll方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆