dotnet / pinvoke

A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
MIT License
2.12k stars 222 forks source link

Fix alignment of INPUT on 64-bit systems #310

Closed AArnott closed 7 years ago

AArnott commented 7 years ago

Bump version to 0.4 due to the breaking change.

Fixes #309

vbfox commented 7 years ago

(Native alignment rules are a pain in the ass, interesting to see that we can't avoid reproducing nested unions like that to get the same effect, I suspect quite a lot of pinvoke.net signatures erasing the unions are actually incorrect)

AArnott commented 7 years ago

Thank you for testing, @vbfox. If they're something you can share, it would be great to have in unit tests. In fact we might want to split our unit test project to enforce x86 and x64 testing and use a Shared Project so the tests are in both projects.

vbfox commented 7 years ago

My test was running the same code in cpp

int main()
{
    INPUT input;
    printf("hi=%i\n", (long long)&input.hi - (long long)&input);
    printf("mi=%i\n", (long long)&input.mi - (long long)&input);
    printf("ki=%i\n", (long long)&input.ki - (long long)&input);
    return 0;
}

And C#

unsafe void Main()
{
    INPUT input;
    Console.WriteLine("hi={0}", (long)&input.Inputs.hi - (long)&input);
    Console.WriteLine("mi={0}", (long)&input.Inputs.mi - (long)&input);
    Console.WriteLine("ki={0}", (long)&input.Inputs.ki - (long)&input);
}

In both x64 & x86 and checking that the result match. Being able to have unit tests that check that the value are correct in both x86 & x64 would be perfect regresion-wise.