المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : SendInput Parameter error



C# Programming
05-13-2009, 05:40 PM
Billy reports error 87, "The parameter is incorrect" on my x64 machine.

public struct INPUT
{
public int type;
public MOUSEINPUT mi;
}
public struct MOUSEINPUT
{
public int dx;
public int dy;
public int mouseData;
public int dwFlags;
public int time;
public int dwExtraInfo;
} [DllImport("User32.dll", SetLastError = true)]
public static extern int SendInput(int nInputs, ref INPUT pInputs, int cbSize);
...
input.type = INPUT_MOUSE;
input.mi.dx = 0;
input.mi.dy = 0;
input.mi.mouseData = 0;
input.mi.time = 0;
input.mi.dwFlags = 0;
input.mi.dwExtraInfo = 0;

SetForegroundWindow(hWndC);

RECT textWindowRect = new RECT();
GetWindowRect(hWndC.ToInt32(), ref textWindowRect);
// Put Cursor on 1st line of the text box
input.mi.dwFlags = (MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_ABSOLUTE);
input.mi.dx = textWindowRect.right - 30;
input.mi.dy = textWindowRect.top + 2;
resSendInput = SendInput(1, ref input, Marshal.SizeOf(input));
if (resSendInput == 0)
{
string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
MessageBox.Show(errorMessage);
}

The error occurs on this SendInput. I know that the dx and dy calculations are correct cuz the following statement works if i substitute it for the SendInput:

SetCursorPos(textWindowRect.right - 30, textWindowRect.top + 2);

This is mi at time of error message:
mi {MyBuddy.Form1.MOUSEINPUT} MyBuddy.Form1.MOUSEINPUT
dwExtraInfo 0 int
dwFlags 32770 int
dx 251 int
dy 526 int
mouseData 0 int
time 0 int


The whole idea of running 32-bit code on a 64-bit machine boggles my mind. After messing with this for about 20 hours ... I'm getting a headache!