SendInput Parameter error
-
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!
-
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!
Hi, AFAIK there is a problem in your MOUSEINPUT struct: the extraInfo field is a pointer (IntPtr), not an int, and it takes 8B instead of 4B on X64. BTW: there are a lot of such errors on the web, even on www.pinvoke.net :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hi, AFAIK there is a problem in your MOUSEINPUT struct: the extraInfo field is a pointer (IntPtr), not an int, and it takes 8B instead of 4B on X64. BTW: there are a lot of such errors on the web, even on www.pinvoke.net :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
Thanks Luc. There is no question you are correct. I was aware of the 8b vs 4b difference. I guess what i don't understand is how 64-bit machines can run 32-bit DLLs. Why is it that the 32-bit DLL is not expecting 32-bit pointers? Sorry for delay in getting back here.