See the question and my original answer on StackOverflow

In C#, long is a keyword for .NET's System.Int64, which represents a 64-bit signed integer.

In C++, long's size can vary but it's often a 32-bit signed integer (check your compiler).

So if your C++ long's size is indeed 32-bit, you must use C#'s int (or .NET System.Int32) otherwise you'll get an offset mismatch in the structure and anything can and will happen.

PS: .NET Marshal.SizeOf, Marshal.OffsetOff and C++ sizeof, offsetof can be used also to compare overall structures offsets and sizes.