I am working on porting some C ++ code to managed .NET. I will need to save the C ++ code in its native form and try to use the IJW approach to it. I know that you can declare an unmanaged structure so that it is correctly bound to the .NET code, but the C ++ compiler does not seem to do this.
For example, I have this code (managed):
struct MyStruct
{
int some_int;
long some_long;
};
public ref class Class1
{
static MyStruct GetMyStruct()
{
MyStruct x = { 1, 1 };
return x;
}
};
It compiles, but when I look at it with a reflector, the code looks like this:
public class Class1
{
private static unsafe MyStruct GetMyStruct()
{
MyStruct x;
*((int*) &x) = 1;
*((int*) (&x + 4)) = 1;
return x;
}
}
[StructLayout(LayoutKind.Sequential, Size=8), NativeCppClass,
MiscellaneousBits(0x41), DebugInfoInPDB]
internal struct
{
}
Basically, no fields in MyStruct are visible to .NET. Is there a way to tell the C ++ compiler to generate?
, , . , , .NET framework. . , ++ , .NET , :
[StructLayout(LayoutKind::Sequential, blablabla ... )]
struct MyStruct
{
[MarshalAs ....... ]
System::Int32 some_int;
[MarshalAs ....... ]
System::Int32 some_long;
};