错误似乎很常见,但这里是:
eCA1901 P/Invoke declarations should be portable As it is declared in your code, parameter 'dwExtraInfo' of P/Invoke 'NativeMethods.mouse_event(int, int, int, int, int)' will be 4 bytes wide on 64-bit platforms. This is not correct, as the actual native declaration of this API indicates it should be 8 bytes wide on 64-bit platforms. Consult the MSDN Platform SDK documentation for help determining what data type should be used instead of 'int'
这是代码行:
[System.Runtime.InteropServices.DllImport("user32.dll")]
internal static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
现在我尝试更改为 Uint 或与 64 位兼容的东西,或者可以在两者上使用的东西(品脱或其他东西,不记得名字)。
但是,如果我从 Int 更改为 Uint 或其他什么,它会破坏此代码:
if (click == "Left")
{
NativeMethods.mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, MousePosition.X, MousePosition.Y, MousePosition.X, MousePosition.Y);
}
if (click == "Right")
{
NativeMethods.mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, MousePosition.X, MousePosition.Y, MousePosition.X, MousePosition.Y);
}
if (down == "Left"+"True")
{
NativeMethods.mouse_event(MOUSEEVENTF_LEFTDOWN , MousePosition.X, MousePosition.Y, MousePosition.X, MousePosition.Y);
}
if (down == "Right"+"True")
{
NativeMethods.mouse_event(MOUSEEVENTF_RIGHTDOWN, MousePosition.X, MousePosition.Y, MousePosition.X, MousePosition.Y);
}
正如它所说(不能从int转换......)如果我在那里的所有东西上使用(uint),它似乎“工作”,但我不认为这是一个非常理想的方法。
这是 MouseEvent 代码:
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
还尝试将它们更改为 Uint。
现在我为什么要谈论 Uint 是因为我读到我应该把它改成那样。我不知道 Uint 与 Int 相比是什么。
所以如果有更好的方法,或者我做错了,请告诉。