PlatformInvoke SendInput method

Hi,

For my bachelor project I need a simple PlatformInvoke on the SendInput function, from the Windows API. The problem is, I don't know if I did it correctly, since all other PlatformInvokes work, but this one returns 0 (error). The only thing I need it for is to simulate the scroll-wheel on the mouse...If there's another way, plz let me know...

This is what I've got at this point:

[DllImport("user32.dll")]
unsafe internal static extern uint SendInput(uint nInputs, IntPtr inputs, int cbSize);

[StructLayout(LayoutKind.Explicit)]
internal struct INPUT {
[FieldOffset(0)]
public ulong type;

// Union
[FieldOffset(8)]
public MOUSEINPUT mi;
[FieldOffset(8)]
public KEYBDINPUT ki;
[FieldOffset(8)]
public HARDWAREINPUT hi;
}

[StructLayout(LayoutKind.Sequential)]
internal struct MOUSEINPUT {
public long dx;
public long dy;
public ulong mouseData;
public ulong dwFlags;
public ulong time;
public ulong dwExtraInfo;
}

I tried this with an array instead of an IntPtr too, but that also didn't work. The union thing is the other thing I am not sure I implemented correctly.

Thanks in advance for ANY help on this subject...
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories