This is a mirror of official site: http://jasper-net.blogspot.com/

You don't need to ask me a question the compiler can answer more accurately

| Thursday, July 28, 2011
A customer reported having problems developing the correct p/invoke signature for the INPUT structure. "The code works on 32-bit machines, but on 64-bit machines, the call to Send­Input returns ERROR_INVALID_PARAMETER." The sample code included the lines

INPUT[] inputs = new INPUT[1];
inputs[0].type = INPUT_KEYBOARD;
...
int size = Marshal.SizeOf(inputs[0]);
if (!SendInput(1, ref inputs, size))
{
 Console.WriteLine("Failed with error {0}", GetLastError());
}

My response was simply, "I bet you are passing the wrong structure size. Note that on 64-bit Windows, the alignment of the inner structures is 8-byte rather than 4-byte. Write a C++ program that does the same thing and compare."

The customer decided to read only the first sentence of my reply, possibly the second, and ignore the third. "So what size should the INPUT structure be on 64-bit machines?"

There are a few ways you can go about finding out the size of a structure.

One method is to ask Raymond. This may work, but it makes Raymond rather grumpy since it demonstrates that you are lazy and just want the answer handed to you with no effort (or demonstration of understanding) on your part.

Read more: The old new thing
QR: 10190102.aspx

Posted via email from Jasper-net

0 comments: