I am attempting to port some code from an old C program into C#, and I
have run into a roadblock with generating a checksum for each of the
structures, and where the checksum is the last field in the structure.
In C, the code simply casts the structure as an int* and then performs
the calculations on all fields prior to and excluding the checksum field
itself, at which point the resulting value is placed in the field.
The only way that I can see of achieving this would be to use
interop/Marshal to marshal the structure into an IntPtr and then marshal
it out again as an int[] and ignore the last element. This seems an
expensive and convoluted method - is there a better one?
-ken
have run into a roadblock with generating a checksum for each of the
structures, and where the checksum is the last field in the structure.
In C, the code simply casts the structure as an int* and then performs
the calculations on all fields prior to and excluding the checksum field
itself, at which point the resulting value is placed in the field.
The only way that I can see of achieving this would be to use
interop/Marshal to marshal the structure into an IntPtr and then marshal
it out again as an int[] and ignore the last element. This seems an
expensive and convoluted method - is there a better one?
-ken