I'm trying to include an external C++ library in my c# project. This is the prototype of the function that I want to use:
unsigned char* heatmap_render_default_to(const heatmap_t* h, unsigned char* colorbuf)
This function is allocating memory for 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);
I tried to use this function in a main method to test the library:
var colourbuf = new byte[w * h * 4];
fixed (byte* colourbufPtr = colourbuf)
HeatMapWrapper.NativeMethods.Render_default_to(hmPtr, colourbuf);
When I try this I'm getting a Segmentation fault exception. Could someone help me with this ?