C#调用动态链接库DLL报错
我的程序中有如下代码:
public Rectangle SetOutPutWindow(IntPtr m_pHandle, HV_RESOLUTION m_kResolotion, Rectangle m_OutPutWindow)//设置图像输出(Output)窗口
{
System.Diagnostics.Debug.Assert(m_pHandle != IntPtr.Zero);
IntPtr buffer = new IntPtr();
int size = 0;
HVSTATUS status = USBCameraAPI.HVGetDeviceInfo(m_pHandle, HV_DEVICE_INFO.DESC_RESOLUTION, buffer, ref size);
buffer = Marshal.AllocHGlobal(size);
status = USBCameraAPI.HVGetDeviceInfo(m_pHandle, HV_DEVICE_INFO.DESC_RESOLUTION, buffer, ref size);
USBCameraAPI.HV_VERIFY(status);
int[] type = new int[64];
Marshal.Copy(buffer, type, 0, 64);
Marshal.FreeHGlobal(buffer);
m_OutPutWindow.Width = type[(int)m_kResolotion*2];
m_OutPutWindow.Height = type[(int)m_kResolotion*2+1];
status = USBCameraAPI.HVSetOutputWindow(m_pHandle, m_OutPutWindow.X, m_OutPutWindow.Y, m_OutPutWindow.Width, m_OutPutWindow.Height);
USBCameraAPI.HV_VERIFY(status);
return m_OutPutWindow;
}
大部分测试没有报错,可有的时候我再次运行提示
Marshal.Copy(buffer, type, 0, 64);尝试读取或写入受保护的内存。这通常指示其他内存已损坏
这是什么原因呢,需要怎么解决,求大神,在线等!!!