111,119
社区成员
发帖
与我相关
我的任务
分享public IntPtr PointArrayToIntPtr(Point[] points)
{
if (points == null || points.Length == 0)
return IntPtr.Zero;
int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(Point));
IntPtr lpoints = System.Runtime.InteropServices.Marshal.AllocHGlobal(size * points.Length);
IntPtr tmp = lpoints;
for (int i = 0; i < points.Length; i++, tmp += size)
{
System.Runtime.InteropServices.Marshal.StructureToPtr(points[i], tmp, false);
}
return lpoints;
}
Point[] point = new Point[10];
fixed(Point* p = point)
{
IntPtr ptr = (IntPtr)p;
//......
}
或者这样
Point[] point = new Point[10];
GCHandle handle = GCHandle.Alloc(point, GCHandleType.Pinned);
IntPtr ptr = handle.AddrOfPinnedObject();
//......
handle.Free();