FieldOffset on 64bit OS

N

not_a_commie

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("User32.dll", SetLastError = true)]
public static extern uint SendInput(uint nInputs, INPUT[] pInputs,
int cbSize);

[StructLayout(LayoutKind.Sequential)]
public struct MOUSEINPUT
{
public int dx;
public int dy;
public uint mouseData;
public uint dwFlags;
public uint time;
public IntPtr dwExtraInfo;
}

[StructLayout(LayoutKind.Sequential)]
public struct KEYBDINPUT
{
public ushort wVk;
public ushort wScan;
public uint dwFlags;
public uint time;
public IntPtr dwExtraInfo;
}

[StructLayout(LayoutKind.Sequential)]
public struct HARDWAREINPUT
{
public uint uMsg;
public ushort wParamL;
public ushort wParamH;
}

[StructLayout(LayoutKind.Explicit)]
public struct INPUT
{
[FieldOffset(0)]
public int type;
[FieldOffset(4)]
public MOUSEINPUT mi;
[FieldOffset(4)]
public KEYBDINPUT ki;
[FieldOffset(4)]
public HARDWAREINPUT hi;
}
 
D

developerzero

                [DllImport("User32.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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top