在 c# 中包装 C++ 函数即 returns 指针
wrap C ++ function in c # that returns pointer
我有以下 C++ 函数,我将在 C# 中创建包装函数:
byte* FunctionReturnVectorPoint()
{
return vectorPoint;
}
我试过了:
[DllImport("DLL_NAME.dll", CallingConvention = CallingConvention.ThisCall)]
unsafe public static extern byte*[] FunctionReturnVectorPoint();
但它不起作用。
你有什么建议吗?
已解决:
[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);
我有以下 C++ 函数,我将在 C# 中创建包装函数:
byte* FunctionReturnVectorPoint()
{
return vectorPoint;
}
我试过了:
[DllImport("DLL_NAME.dll", CallingConvention = CallingConvention.ThisCall)]
unsafe public static extern byte*[] FunctionReturnVectorPoint();
但它不起作用。
你有什么建议吗?
已解决:
[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);