System.OverflowException:“算术运算导致溢出。”
一 问题描述
在C#获取C++传回来的指针解析结构体时出现这个异常。
二 原因及解决办法
因为平台不同,所需要定义的Inptr数据类型不一样。
修改如下:
//X86下
dcArr[0] = (AlgorithmAdapter.DetectColor.ColorDetectResult)System.Runtime.InteropServices.Marshal.PtrToStructure((IntPtr)((UInt32)intPtrRes), typeof(AlgorithmAdapter.DetectColor.ColorDetectResult));
/
/X64下
dcArr[0] = (AlgorithmAdapter.DetectColor.ColorDetectResult)System.Runtime.InteropServices.Marshal.PtrToStructure((IntPtr)((UInt64)intPtrRes), typeof(AlgorithmAdapter.DetectColor.ColorDetectResult));