IJW: managed proxy struct
See the question and my original answer on StackOverflowIf you want to define a public struct visible to .NET applications, from C++ managed code, here is a way to do it (note the 'public' and 'value' keywords):
[StructLayout(LayoutKind::Sequential)]
public value struct MyStruct
{
int some_int;
long some_long;
};
If you want an unmanaged struct to be moved between C# and C/C++, you'll have to declare it on both sides. Like this in C:
struct MyUnmanagedStruct
{
int some_int;
long some_long;
};
And like this, say, in C#, for example:
[StructLayout(LayoutKind.Sequential)]
struct MyUnmanagedStruct
{
public int some_int;
public long some_long; // Or as int (depends on 32/64 bitness)
};
You'll have to ensure the fields in .NET match the fields from C. You may want to use StructLayout attributes (notably Pack). See the two tutorials Structs Tutorial and How to: Marshal Structures Using PInvoke.