I have following C++ function signature in my Warper.dll file
extern "C" DLLEXPORTED unsigned char* UpdateWarp
(int warperId, int x, int y, int *xRet, int *yRet, int *width, int *height, int* scanWidth);
C++ function
unsigned char* UpdateWarp(int warperId, int x, int y,
int *xRet, int *yRet, int *width, int *height, int* scanWidth)
{
if(xRet && yRet && width && height && scanWidth)
{
Warper* warper = getMapItem<Warper*>(m_warpers, warperId);
if (warper)
{
WarpedImage* warpedImg = warper->UpdateWarp(Point(x, y));
*xRet = warpedImg->Position.X;
*yRet = warpedImg->Position.Y;
*width = warpedImg->Image.Width;
*height = warpedImg->Image.Height;
*scanWidth = warpedImg->Image.ScanWidth;
m_warpedImages[warperId] = warpedImg;
return warpedImg->Image.Data;
}
}
return NULL;
}
in C# I have declared as
[DllImport("Warper.dll", EntryPoint = "UpdateWarp")]
private static extern IntPtr UpdateWarp(int warperId, int x, int y,
ref int xRet, ref int yRet, ref int width, ref int height, ref int scanWidth);
and calling as
IntPtr ptrRawData = UpdateWarp(m_iWarperId, pt.X, pt.Y, ref x, ref y, ref w, ref h, ref iScanWidth);
when executing the code, it gives error AccessViolationException was unhandled both in Debug and Release mode. Error is in passing the values to function I think not returning the value. What can be the reason.