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; }