title: Issue with size of IntPtr
body: <p>Yesterday, I posted an issue regarding passing some int** and double** from C# to C++. <a href="https://stackoverflow.com/questions/20221747/how-to-import-a-c-function-with-int-and-double-parameters">How to import a C++ function with int** and double** parameters</a></p>
  <p>Fortunately, I got some good help. Here is my new code:</p>
  <pre><code>[DllImport(&quot;opendsp.dll&quot;, SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
  public unsafe static extern int SetAcquisitionPointerSynchronously(int* ID, int* BufferID, out IntPtr Pointer, out IntPtr Time, int NumberOfPointers);
  
  public unsafe int OpenDSP_SetAcquisitionPointerSynchronously(int[] IDs, int[] BufferID, ref int[] Pointer, ref double[] Time, int NumberOfPointers)
  {
      IntPtr fQueue = IntPtr.Zero;
      IntPtr fTime = IntPtr.Zero;
      int breturn = -1;
      fixed (int* fMeasurementId = IDs)
      fixed (int* fBufferID = BufferID)
  
      try
      {
          fQueue = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * Pointer.Length);
  
          fTime = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Double)) * Time.Length);
  
          breturn = SetAcquisitionPointerSynchronously(fMeasurementId, fBufferID, out fQueue, out fTime, NumberOfPointers);
  
          int size = Marshal.SizeOf(typeof(double));
          for (uint i = 0; i &lt; NumberOfPointers; i++)
              Time[i] = (double)Marshal.PtrToStructure(new IntPtr(fTime.ToInt32() + (size * i)), typeof(double));
  
          size = Marshal.SizeOf(typeof(int));
          for (uint i = 0; i &lt; NumberOfPointers; i++)
              Pointer[i] = (int)Marshal.PtrToStructure(new IntPtr(fQueue.ToInt32() + (size * i)), typeof(int));
  
          Marshal.FreeHGlobal(fQueue);
          Marshal.FreeHGlobal(fTime);
      }
      catch {
      }
  
      return breturn;
  }
  </code></pre>
  <p>When my two arrays Pointer and Time are of length 2, I don't have issues. But when I increase it to 4, then my code crashes. I debugged, and it seems that when it tries to access the 4th elements of Pointer, this one points to 0x00000 so it is not accessible.</p>
  <p>I have tried different things without success.</p>
  <p>How can I fix this?</p>