You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

26 line
684 B

  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Security2
  4. {
  5. internal static class IntPtrExtensions
  6. {
  7. public static IntPtr Increment(this IntPtr ptr, int cbSize)
  8. {
  9. return new IntPtr(ptr.ToInt64() + cbSize);
  10. }
  11. public static IntPtr Increment<T>(this IntPtr ptr)
  12. {
  13. return ptr.Increment(Marshal.SizeOf(typeof(T)));
  14. }
  15. public static T ElementAt<T>(this IntPtr ptr, int index)
  16. {
  17. var offset = Marshal.SizeOf(typeof(T)) * index;
  18. var offsetPtr = ptr.Increment(offset);
  19. return (T)Marshal.PtrToStructure(offsetPtr, typeof(T));
  20. }
  21. }
  22. }