I'm trying to return from my native c++ code to c# code a struct with field of other struct but have an error : Method's type signature is not PInvoke compatible.
this is my c++ code:
namespace path
{
struct Vector3
{
public:
float x;
float y;
float z;
};
struct PointState
{
public:
Vector3 position_;
bool reformation;
};
}
Here my api functions:
extern "C"
{
PATHFINDER_API void SetupGraph(const char * json);
PATHFINDER_API path::Vector3 CheckReturn();
PATHFINDER_API path::PointState CheckStruct();
}
And this is my C# struct code:
[StructLayout(LayoutKind.Sequential)]
public struct Vector3
{
public float x;
public float y;
public float z;
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct PointState
{
[MarshalAs(UnmanagedType.LPStruct)]
public Vector3 position_;
public bool reformation;
};
and Pinvoke DLLImport:
[DllImport("path", CallingConvention = CallingConvention.Cdecl, ExactSpelling = false, EntryPoint = "CheckStruct")]
private static extern PointState CheckStruct();
public PointState CheckReturn2()
{
return CheckStruct();
}
Pls, what i'm doing wrong? I can't find answer by myself.
PointState.