CSharp -- PInvokeStackImbalance detected on a well documented function?
        Posted  
        
            by Aaron Hammond
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Aaron Hammond
        
        
        
        Published on 2010-05-31T13:40:09Z
        Indexed on 
            2010/05/31
            13:53 UTC
        
        
        Read the original article
        Hit count: 409
        
Here is my code for a ClickMouse() function:
    [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 long MOUSEEVENTF_LEFTDOWN = 0x02;
    private const long MOUSEEVENTF_LEFTUP = 0x04;
    private const long MOUSEEVENTF_RIGHTDOWN = 0x08;
    private const long MOUSEEVENTF_RIGHTUP = 0x10;
    private void ClickMouse()
    {
        long X = Cursor.Position.X;
        long Y = Cursor.Position.Y;
        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
    }
For some reason, when my program comes to this code, it throws this error message:
PInvokeStackImbalance was detected Message: A call to PInvoke function 'WindowsFormsApplication1!WindowsFormsApplication1.Form1::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.
Please help?
© Stack Overflow or respective owner