title: C# bitmap comparison (PinvokeStackimbalance exception)
body: <p>I'm trying to compare two images using:</p>
  
  <pre><code>       [DllImport("msvcrt.dll")]
  private static extern int memcmp(IntPtr b1, IntPtr b2, long count);
  
  public static bool CompareMemCmp(Bitmap b1, Bitmap b2)
  {
      if ((b1 == null) != (b2 == null)) return false;
      if (b1.Size != b2.Size) return false;
  
      var bd1 = b1.LockBits(new Rectangle(new Point(0, 0), b1.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
      var bd2 = b2.LockBits(new Rectangle(new Point(0, 0), b2.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
  
      try
      {
          IntPtr bd1scan0 = bd1.Scan0;
          IntPtr bd2scan0 = bd2.Scan0;
  
          int stride = bd1.Stride;
          int len = stride * b1.Height;
  
          return memcmp(bd1scan0, bd2scan0, len) == 0;
      }
      finally
      {
          b1.UnlockBits(bd1);
          b2.UnlockBits(bd2);
      }
  }
  </code></pre>
  
  <p>I'm using the CompareMemCmp() like this (on_click event):</p>
  
  <pre><code>        Bitmap img1 = new Bitmap(@"C:\1\1.png");
          Bitmap img2 = new Bitmap(@"C:\1\2.png");
  
          if (CompareMemCmp(img1, img2) == true)
          { textBox1.Text = "Same"; }
          else { textBox1.Text = "Different"; }
  </code></pre>
  
  <p>Unfortunately an exception is thrown:</p>
  
  <pre><code>return memcmp(bd1scan0, bd2scan0, len) == 0;
  </code></pre>
  
  <p><strong>PinvokeStackimbalance</strong>
  "A call to PInvoke function 'TextRecognition!TextRecognition.Form1::memcmp' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."</p>
  
  <p><strong>what might be the problem?</strong> I've already tried different methods to solve this problem..</p>