我在Warper.dll文件中有以下C ++函数签名
extern "C" DLLEXPORTED unsigned char* UpdateWarp
(int warperId, int x, int y, int *xRet, int *yRet, int *width, int *height, int* scanWidth);
C ++函数
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;
}
在C#中我声明为
[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);
并呼叫为
IntPtr ptrRawData = UpdateWarp(m_iWarperId, pt.X, pt.Y, ref x, ref y, ref w, ref h, ref iScanWidth);
执行代码时,它在Debug和Release模式下都会出现 AccessViolationException未处理错误。错误是将值传递给函数我认为不返回值。 可能是什么原因。