指针偏移
作者:互联网
public static void PtrMoveSize(ref IntPtr pData, int nLength) { if (IntPtr.Size == sizeof(Int64)) pData = new IntPtr(pData.ToInt64() + nLength); else pData = new IntPtr(pData.ToInt32() + nLength); }
//结构体转指针 public static IntPtr StructToIntPtr(Object obj1) { //得到结构体的大小 int size = Marshal.SizeOf(obj1); //分配结构体大小的内存空间 IntPtr structPtr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(obj1, structPtr, false); return structPtr; } public static IntPtr IntPtrToIntPtr(IntPtr hwdn, int nSize) { //分配结构体大小的内存空间 IntPtr structPtr = Marshal.AllocHGlobal(nSize); Marshal.StructureToPtr(hwdn, structPtr, false); return structPtr; }
标签:IntPtr,structPtr,int,pData,偏移,static,Marshal,指针 来源: https://www.cnblogs.com/yc1224/p/12022949.html