【发布时间】:2016-02-23 12:00:07
【问题描述】:
我正在尝试在我的 c# 项目中包含一个外部 C++ 库。 这是我要使用的函数原型:
unsigned char* heatmap_render_default_to(const heatmap_t* h, unsigned char* colorbuf)
这个函数正在为 colorbuf 分配内存:
colorbuf = (unsigned char*)malloc(h->w*h->h * 4);
Pinvoke:
[DllImport(DLL, EntryPoint = "heatmap_render_default_to", CallingConvention = CallingConvention.Cdecl)]
public static extern byte[] Render_default_to(IntPtr h, byte[] colorbuf);
我尝试在 main 方法中使用这个函数来测试库:
var colourbuf = new byte[w * h * 4];
fixed (byte* colourbufPtr = colourbuf)
HeatMapWrapper.NativeMethods.Render_default_to(hmPtr, colourbuf);
当我尝试这个时,我得到一个分段错误异常。 有人可以帮我解决这个问题吗?
【问题讨论】:
-
这个问题与您之前的问题stackoverflow.com/q/35564802/993547 和stackoverflow.com/q/35517164/993547 有何不同?