加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C# – PInvokeStackImbalance在一个记录良好的函数中检测到?

发布时间:2020-12-15 06:49:00 所属栏目:百科 来源:网络整理
导读:这是我的ClickMouse()函数的代码: [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 con
这是我的ClickMouse()函数的代码:
[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);

    }

由于某些原因,当我的程序来到这个代码,它会抛出这个错误信息:

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.

请帮忙?

解决方法

看起来你的DllImport声明是错误的.特别是使用Int64(longs),而不是UInt32.

以下是PInvoke参考的一些细节:
http://www.pinvoke.net/default.aspx/user32.mouse_event

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读