473,504 Members | 13,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("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;
}
Nov 3 '08 #1
2 3510
On Mon, 03 Nov 2008 13:54:07 -0800, not_a_commie <no********@gmail.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
Nov 4 '08 #2
On Nov 3, 1:54*pm, not_a_commie <notacom...@gmail.comwrote:
* * * * * * * * [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
Nov 4 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3223
by: Christian McArdle | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.os.ms-windows.programmer.64bit This is a formal Request For Discussion (RFD) to create comp.os.ms-windows.programmer.64bit as an unmoderated...
4
13891
by: Chua Wen Ching | last post by:
Hi there, I had a union in C: typedef union TagMessage { struct { unsigned char avalue; unsigned char bvalue; } a;
11
13274
by: Vijay Chegu | last post by:
I have built a 64bit ATL COM dll. When i register the dll on IA64 windows Enterprise server 2003, i get following error. DllRegisterServer in mydll.dll failed. Return code was : 0x80020009 ...
4
5898
by: Danny Mavromatis | last post by:
I'm trying to set up a structure using unions (fieldoffset) and I'm running into a problem. When I try to setup a union of data array or message type, I get the following error: ...
3
2493
by: Frank Uray | last post by:
Hi all I have written a WindowsService in C# 2005. I am running this service on a 64bit Windows Server 2003 and I like to run some Interop.Excel within this service. It seams that Interop...
4
5711
by: mike | last post by:
I have found that orig tested 64 bit on our 64bit windows 2003 server...about 1 year ago...and company decided to use sql 32 bit on the 64bit os my question and any information is very welcome ...
2
2982
by: Steve Richter | last post by:
I have a struct that uses LayoutKind.Explicit to redefine bytes within the struct: public struct PointerStoredValue { public int LayoutId; public int HeapId ;
1
1944
by: GaryDean | last post by:
We have been developing all of our .net applications on 32 bit windows using 32 bit SQL Server. We are being asked to now deploy to servers running 64bit windows and 64bit SQL Server. Are there...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.