Ok I've been trying to marshall a data structure that has this equivalent in C/C++ format:
Struct ResultsRecord
{
int LengthOutMD; // this contains the size for the arrays below.
float *OutMD;
float *OutAxialLoad;
float *OutNormalForce
}
This is the function that is contained in the unmanaged code inside a dll file:
typedef int (cdecl *ReadResultsTnDAnalysis) (wchar_t* ResultFileName, struct ResultsRecord* TnDResultsRecord);
Now here is my solution which does not work for now: because I can not find an easy way to marshall a pointer to the initial value of the array: the size of the arrays are unknown a priori.
public class APIforEngine
{
[DllImport("TnDAnalysisDLL.dll", EntryPoint = "ReadResultsTnDAnalysis", CallingConvention = CallingConvention.Cdecl
public static extern int ReadResultsTnDAnalysis(string resultFileName,
ref TnDResultsRecord tnDResultsRecord);, CharSet = CharSet.Auto)]
}
[StructLayout(LayoutKind.Sequential), Serializable]
public struct TnDResultsRecord
{
public int LengthOutMD;
[MarshalAs(UnmanagedType.LPArray)]
public float[] OutMD;
[MarshalAs(UnmanagedType.LPArray)]
public float[] OutAxialLoad;
[MarshalAs(UnmanagedType.LPArray)]
public float[] OutNormalForce;
}
Your help is well appreciated.
Right now I am thinking about consuming the dll in an intermediate C++ project transform the data into something easily read by C# and consume it in my C# solution. Even this route I will have to see if it is really feasible because for one I don't know how to consume it. in native c++ or use CLR? and if I use CLR do I use InterOpServices namespace classes or consume it using header file.