Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SendInput Parameter error

SendInput Parameter error

Scheduled Pinned Locked Moved C#
help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IceWater42
    wrote on last edited by
    #1

    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!

    L 1 Reply Last reply
    0
    • I IceWater42

      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!

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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.


      I 1 Reply Last reply
      0
      • L Luc Pattyn

        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.


        I Offline
        I Offline
        IceWater42
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups