SendInput() inconsistency between 32/64 bit function equivalents

Discussion in 'Windows 64 Bit' started by Maksim, Aug 3, 2006.

  1. Maksim

    Maksim Guest

    In C#, I made a program which sends Alt+Print key conbination using
    SendInput() function. The function works on 32 bit WinXP. My executable
    compiled for x86 also works on WinXP 64 bit. But when I use "AnyCPU" platform
    target, SendInput() still sends the keys, but they are not processed. After
    that, my left mouse button simulates my right one, until I press the right
    button. I also tested Shift+Print and it works the same. Could it be a bug in
    WinXP 64? I believe 32 and 64 bit dll versions should be identical. Anybody
    knows how to fix this?
     
    Maksim, Aug 3, 2006
    #1
    1. Advertisements

  2. Maksim

    mabra Guest

    Hi !

    I am not a specialist on this, but made some similar things. Do do what
    you described, so far I remember correctly - you have to use PInvoke and
    the WIN32 API. Can you show your declarations please?

    The problem could stem from declaring pointer as integer instead of IntPtr.

    Just a thought,
    Manfred
     
    mabra, Aug 4, 2006
    #2
    1. Advertisements

  3. Maksim

    Maksim Guest

    At first that's what I thought, some wrong data type, but no I checked and
    rewrote all PInvoke stuff to match Win32 declaration exactly, here it is:

    // --------------------------->

    internal enum DeviceMessageType : uint
    {
    Mouse = 0,
    Keyboard = 1,
    }

    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    internal struct Point
    {
    public int X; // LONG
    public int Y; // LONG
    }

    [StructLayout(LayoutKind.Sequential)]
    internal struct MouseMessage // MOUSEINPUT
    {
    public Point Position; // LONG X, LONG Y
    public uint MouseData; // DWORD
    public uint Flags; // DWORD
    public uint TimeStamp; // DWORD
    public UIntPtr ExtraInfo; // ULONG_PTR
    }

    internal enum VirtualKey : int
    {
    PrintScreen = 0x2C,
    Shift = 0x10,
    Control = 0x11,
    Alt = 0x12
    }

    internal enum KeyEvent : uint // DWORD
    {
    KeyUp = 0x0002
    }

    [StructLayout(LayoutKind.Sequential)]
    internal struct KeyboardMessage // KEYBDINPUT
    {
    public ushort VirtualKey; // WORD
    public ushort ScanCode; // WORD
    public KeyEvent KeyEvent; // DWORD
    public uint TimeStamp; // DWORD
    public UIntPtr ExtraInfo; // ULONG_PTR
    }

    [StructLayout(LayoutKind.Explicit)]
    internal struct DeviceMessageInfo // INPUT
    {
    [FieldOffset(0)]
    public DeviceMessageType DeviceMessageType;

    [FieldOffset(4)]
    public MouseMessage MouseMessage;

    [FieldOffset(4)]
    public KeyboardMessage KeyboardMessage;

    public DeviceMessageInfo(DeviceMessageType DeviceMessageType)
    {
    this.DeviceMessageType = DeviceMessageType;
    this.MouseMessage = new MouseMessage();
    this.KeyboardMessage = new KeyboardMessage();
    }

    public static readonly int SizeOf =
    Marshal.SizeOf(typeof(DeviceMessageInfo));
    }

    [DllImport("User32.dll", EntryPoint = "SendInput", ExactSpelling = true)]
    public static extern uint Send(uint Count, [In] DeviceMessageInfo[]
    DeviceMessageInfo, int DeviceMessageInfoSize);

    // <---------------------------

    I really need to make it work on WinXP x64, so if you find anything wrong
    with it, let me know.
     
    Maksim, Aug 4, 2006
    #3
  4. Maksim

    mabra Guest

    Hi !

    I would just give the hint.

    Sorry, I have never dealed with this APIs, just made some "SendMessage"
    calls, which suceeds.

    Best regards,
    Manfred
     
    mabra, Aug 4, 2006
    #4
  5. Maksim

    Maksim Guest

    So anybody knows how to make SendInput() to work on WinXP x64?

     
    Maksim, Aug 6, 2006
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.