Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

PlatformInvoke SendInput method

ZeekfordZeekford Posts: 1Member
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.