日期:2014-05-17  浏览次数:20964 次

c# 调用c++ dll 返回值为数组指针
如果c++dll的函数返回值为 数组指针,c#这边我需要怎么定义函数,怎么接收呢?
c++:_declspec (dllexport) float* WINAPI shuju(float pv1[],float pv2[],float pv3[],float pv4[])

------解决方案--------------------
C# code

[DllImport("sqlite3.dll", EntryPoint = "sqlite3_open",CallingConvention=CallingConvention.Cdecl)]
public static extern IntPtr shuju(float[] pv1,float[] pv2,float[] pv3,float[] pv4);

------解决方案--------------------
先试试2楼的办法吧。
------解决方案--------------------
"这个方法我试过,但是 InPre inpre=shuju(a,b,c,d);
console.write(inpre);
好像得出的是八位的地址,我该怎么得出我想要的数值呢?"

使用这个:Marshal.Copy 方法 (IntPtr, Single[], Int32, Int32)
将数据从非托管内存指针复制到托管单精度浮点数组。 

public static void Copy (
IntPtr source,
float[] destination,
int startIndex,
int length
)