私はC#クラスを持っています:
namespace Models
{
[StructLayout(LayoutKind.Explicit, Size = 120, CharSet = CharSet.Unicode)]
public struct DynamicState
{
[FieldOffset(0)]
public double[] Position;
[FieldOffset(24)]
public double[] Velocity;
[FieldOffset(48)]
public double[] Acceleration;
[FieldOffset(72)]
public double[] Attitude;
[FieldOffset(96)]
public double[] AngularVelocity;
}
}
およびC++/ CLIメソッド:
Models::DynamicState SomeClassClr::DoSomething(Models::DynamicState ds)
{
int struct_size = Marshal::SizeOf(ds);
System::IntPtr ptr = Marshal::AllocHGlobal(struct_size);
DynamicStateStruct ds_struct;
struct_size = sizeof(ds_struct);
Marshal::StructureToPtr(ds, ptr, false);
ds_struct = *(DynamicStateStruct*)ptr.ToPointer();
Models::DynamicState returnVal;
mpSomeClass->doSomething(ds_struct);
return returnVal;
}
ここで、DynamicStateStructはネイティブC++クラスです。
struct DynamicStateStruct
{
double mPosition[3];
double mVelocity[3];
double mAcceleration[3];
double mAttitude[3];
double mAngularVelocity[3];
};
ネイティブC++で構造体()を復元するとds_struct
、正しい値が得られません。不足しているアイデアはありますか?