在c#中包装返回指针的C ++函数

时间:2016-11-11 15:42:53

标签: c# c++ wrapper

我有以下C ++函数,我将在c#中创建包装函数:

byte* FunctionReturnVectorPoint()
{
   return vectorPoint;
}

我试过了:

[DllImport("DLL_NAME.dll", CallingConvention = CallingConvention.ThisCall)]
unsafe public static extern byte*[] FunctionReturnVectorPoint();

但它不起作用。

您有什么建议吗?

1 个答案:

答案 0 :(得分:1)

解决:

[DllImport("DLL_NAME.dll", CallingConvention = CallingConvention.ThisCall)]
public static extern IntPtr FunctionReturnVectorPoint();

以这种方式调用函数:

IntPtr tempPoint = FunctionReturnVectorPoint();
byte[] vector= new byte[dimensionVector];
Marshal.Copy(tempPoint , vector, 0, dimensionVector);