对 PInvoke 函数的调用...使堆栈不平衡
A call to PInvoke function ... has unbalanced the stack
每次我调用函数 mouse_event 我都会得到错误
A call to PInvoke function 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.
const int MOUSEEVENTF_LEFTDOWN = 0x02;
const int MOUSEEVENTF_LEFTUP = 0x04;
const int MOUSEEVENTF_RIGHTDOWN = 0x08;
const int MOUSEEVENTF_RIGHTUP = 0x10;
[System.Runtime.InteropServices.DllImport("user32.dll", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
switch (mouseAction)
{
case ENUMMouseAction.LEFTDOWN:
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
break;
case ENUMMouseAction.LEFTUP:
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
break;
case ENUMMouseAction.RIGHTDOWN:
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
break;
case ENUMMouseAction.RIGHTUP:
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
break;
}
我已经尝试了所有可用的 CallingConventions,none 似乎有效,如有任何帮助,我们将不胜感激,
提前致谢。
两个错误:
- 调用约定应为
Stdcall
。
- 参数类型全部错误。前四个参数为
uint
,最后一个参数为UIntPtr
.
阅读文档时需要小心。可以在这里找到:https://msdn.microsoft.com/en-us/library/windows/desktop/ms646260.aspx
每次我调用函数 mouse_event 我都会得到错误
A call to PInvoke function 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.
const int MOUSEEVENTF_LEFTDOWN = 0x02;
const int MOUSEEVENTF_LEFTUP = 0x04;
const int MOUSEEVENTF_RIGHTDOWN = 0x08;
const int MOUSEEVENTF_RIGHTUP = 0x10;
[System.Runtime.InteropServices.DllImport("user32.dll", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
switch (mouseAction)
{
case ENUMMouseAction.LEFTDOWN:
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
break;
case ENUMMouseAction.LEFTUP:
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
break;
case ENUMMouseAction.RIGHTDOWN:
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
break;
case ENUMMouseAction.RIGHTUP:
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
break;
}
我已经尝试了所有可用的 CallingConventions,none 似乎有效,如有任何帮助,我们将不胜感激,
提前致谢。
两个错误:
- 调用约定应为
Stdcall
。 - 参数类型全部错误。前四个参数为
uint
,最后一个参数为UIntPtr
.
阅读文档时需要小心。可以在这里找到:https://msdn.microsoft.com/en-us/library/windows/desktop/ms646260.aspx