gpt4 book ai didi

C#——在记录良好的函数上检测到 PInvokeStackImbalance?

转载 作者:太空狗 更新时间:2023-10-29 17:33:41 28 4
gpt4 key购买 nike

这是我的 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, 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(长整数),而不是 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);

关于C#——在记录良好的函数上检测到 PInvokeStackImbalance?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2943883/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com