FieldOffset on 64bit OS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • not_a_commie

    FieldOffset on 64bit OS

    I've been using INPUT as declared below. However, I get warnings about
    this being incompatible with a 64bit OS. I have no 64bit OS to test
    on. However, is it true that the union in the INPUT declaration below
    would need to line on an 8byte boundary for a 64bit OS? And should I
    just do this with #if? #if 64bitosblah FieldOffset(8) #else
    FieldOffset(4)?

    [DllImport("User 32.dll", SetLastError = true)]
    public static extern uint SendInput(uint nInputs, INPUT[] pInputs,
    int cbSize);

    [StructLayout(La youtKind.Sequen tial)]
    public struct MOUSEINPUT
    {
    public int dx;
    public int dy;
    public uint mouseData;
    public uint dwFlags;
    public uint time;
    public IntPtr dwExtraInfo;
    }

    [StructLayout(La youtKind.Sequen tial)]
    public struct KEYBDINPUT
    {
    public ushort wVk;
    public ushort wScan;
    public uint dwFlags;
    public uint time;
    public IntPtr dwExtraInfo;
    }

    [StructLayout(La youtKind.Sequen tial)]
    public struct HARDWAREINPUT
    {
    public uint uMsg;
    public ushort wParamL;
    public ushort wParamH;
    }

    [StructLayout(La youtKind.Explic it)]
    public struct INPUT
    {
    [FieldOffset(0)]
    public int type;
    [FieldOffset(4)]
    public MOUSEINPUT mi;
    [FieldOffset(4)]
    public KEYBDINPUT ki;
    [FieldOffset(4)]
    public HARDWAREINPUT hi;
    }
  • Peter Duniho

    #2
    Re: FieldOffset on 64bit OS

    On Mon, 03 Nov 2008 13:54:07 -0800, not_a_commie <notacommie@gma il.com>
    wrote:
    I've been using INPUT as declared below. However, I get warnings about
    this being incompatible with a 64bit OS. I have no 64bit OS to test
    on. However, is it true that the union in the INPUT declaration below
    would need to line on an 8byte boundary for a 64bit OS?
    I don't know the exact answer. But it _could_. On Intel architecture,
    unaligned data simply produces severe speed problems. But on other
    architectures, it's actually mandatory that the data be aligned to the
    word size. 8-byte words have to be on a byte boundary that's a multiple
    of 8.

    ..NET _might_ enforce that, if it's trying to take into account those other
    architectures. Or, it might provide some sort of run-time support to hide
    alignment exceptions on hardware that requires aligned accesses.

    When you say "I get warnings", what kind of warnings? From whom do you
    get them? If it's the compiler actually emitting a warning, I think you
    should definitely take those seriously (and you should be more explicit
    about the warning in your question). If it's some random person telling
    you that, then you'll have to consider how reliable that person is, or
    perhaps do some Googling to see if you can turn additional information up.

    Pete

    Comment

    • developerzero

      #3
      Re: FieldOffset on 64bit OS

      On Nov 3, 1:54 pm, not_a_commie <notacom...@gma il.comwrote:
                      [DllImport("User 32.dll", SetLastError =true)]
                      public static extern uint SendInput(uint nInputs, INPUT[] pInputs,
      int cbSize);
      >
      Just an offhand thought, but it could be this reference to
      "User32.dll " which (based on its name) appears to be a 32-bit library,
      and thus wouldn't work on a 64-bit OS (just a thought).

      -Ryan

      Comment

      Working...