C# - PInvokeStackImbalance上有据可查的功能检测到? [英] C# -- PInvokeStackImbalance detected on a well documented function?

查看:469
本文介绍了C# - PInvokeStackImbalance上有据可查的功能检测到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的ClickMouse()函数的代码:

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检测消息:!一个调用的PInvoke函数
'WindowsFormsApplication1 WindowsFormsApplication1.Form1 :: mouse_event'
已经失衡堆栈。这可能是因为托管的PInvoke
签名不非托管的目标签名匹配。检查
调用约定和的PInvoke签名匹配
的非托管的目标签名的参数。

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(多头)的,而不是UInt32的

Looks like your DllImport declaration is wrong. In particular the use of Int64 (longs), instead of UInt32.

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

Here's some detail from the PInvoke reference:
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);

这篇关于C# - PInvokeStackImbalance上有据可查的功能检测到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆