tags:

views:

21

answers:

1

Here is my code, as soon as I call mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, (long)0, (long)0); I recieve the PInvokeStackImbalance exception. Does someone knows why?

    [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);

    [DllImport("user32.dll")]
    internal extern static int SetCursorPos(int x, int y);

    private const long MOUSEEVENTF_LEFTDOWN = 0x02;
    private const long MOUSEEVENTF_LEFTUP = 0x04;
    private const long MOUSEEVENTF_RIGHTDOWN = 0x08;
    private const long MOUSEEVENTF_RIGHTUP = 0x10;

    public void dragTest()
    {
        long x = 400;
        long y = 400;

        SetCursorPos((int)x, (int)y);

        mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, (long)0, (long)0);

        x += 100;
        y += 100;

        SetCursorPos((int)x, (int)y);
        mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
    }
+1  A: 

Mouse event parameters should be uint according to PInvoke.Net and not long

[DllImport("user32.dll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData,
   UIntPtr dwExtraInfo);
Preet Sangha