title: C# Clicking on a certain point on the screen
body: <p>I am trying to perform a mouse click through c#. I used the mouse_event function to do it.</p>
  
  <pre><code>private const int MOUSEEVENTF_LEFTDOWN = 0x02;
  private const int MOUSEEVENTF_LEFTUP = 0x04;
  [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
  public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
  </code></pre>
  
  <p>I tried two methods : </p>
  
  <p>Moving the mouse to the point and clicking it : </p>
  
  <pre><code>Cursor.Position = new Point(100, 100);
  mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
  </code></pre>
  
  <p>Passing the x, y of the desired click to the function : </p>
  
  <pre><code>mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP,100, 100, 0, 0);
  </code></pre>
  
  <p>Either way, I'm this weird error : </p>
  
  <p>Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'C:\Users\or\Documents\Visual Studio 2010\Projects\ProjectName\ProjectName\bin\Debug\ProjectName.vshost.exe'.
  Additional Information: A call to PInvoke function 'ProjectName!ProjectName.MainForm::mouse_event' 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>Any ideas on a solution?</p>