I am trying to call the following C ++ function, which is wrapped in a DLL:
unsigned char * rectifyImage(unsigned char *pimg, int rows, int cols)
The import statement is as follows:
[DllImport("mex_rectify_image.dll")] unsafe public static extern IntPtr rectifyImage( byte[] data, int rows, int columns);
And my calling procedure is as follows:
byte[] imageData = new byte[img.Height * img.Width * 3];
However, I keep getting a runtime error:
The first random exception of type System.AccessViolationException occurred in xxx.dll An attempt to read or write protected memory. This often indicates that another memory is corrupted.
I'm just wondering if the error is to blame for how I march my data or in an imported DLL file ... does anyone have any ideas?
c # marshalling byte
Tim
source share