I used this code manually to simulate a mouse click on a system using code.
using System; using System.Windows.Forms; using System.Runtime.InteropServices; public class Form1 : Form { [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); private const int MOUSEEVENTF_LEFTDOWN = 0x02; private const int MOUSEEVENTF_LEFTUP = 0x04; private const int MOUSEEVENTF_RIGHTDOWN = 0x08; private const int MOUSEEVENTF_RIGHTUP = 0x10; public Form1() { } public void DoMouseClick() {
But now I am using VS 2010 and Windows 7, and I am getting an error while executing this code now
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
So, any suggestions for this ...
The error I am encountering is:
PInvokeStackImbalance detected
Calling PInvoke 'ClickingApp! ClickingApp.Form1 :: mouse_event 'has an unbalanced stack. This is likely due to the fact that the PInvoke managed signature does not match the unmanaged target signature. Verify that the calling agreement and PInvoke signature settings match the target unmanaged signature.
Mobin source share