I spent many hours working with unmanaged code, and the platform is invoked in .NET. The code below shows what puzzles me how unmanaged data maps to a managed object in .NET.
In this example, I'm going to use the RECT structure:
C ++ RECT implementation (unmanaged Win32 API)
typedef struct _RECT { LONG left; LONG top; LONG right; LONG bottom; } RECT, *PRECT;
C # RECT Implementation (Managed .NET / C #)
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int left, top, right, bottom; }
Ok, so my C # equivalent should work, right? I mean, all variables are in the same order as the C ++ structure, and use the same variable names.
My assumption is that LayoutKind.Sequential means that unmanaged data is mapped to a managed object in the same sequence as in a C ++ structure. that is, data will be displayed, starting from the left, then the top, then the right, then from the bottom.
On this basis, I should be able to change my C # structure ...
C # RECT implementation (a bit clean)
[StructLayout(LayoutKind.Sequential)] public struct Rect //I've started by giving it a .NET compliant name { private int _left, _top, _right, _bottom;
So what happens if the variables are declared in the wrong order? Presumably this screws up the coordinates because they will no longer display on the right thing?
public struct RECT { public int top, right, bottom, left; }
Assuming it would look like this:
top = left
right = top
bottom = right
left = bottom
So my question is simple: I proceed with the assumption that I can change the managed structure in terms of the access specifier of each variable and even the name of the variable, but I can not change the order of the variables?