Calling FORTRAN dll from C# and assigning values to array of structures

前端 未结 1 1614
执笔经年
执笔经年 2020-12-10 08:42

I can pass a C# struct into FORTRAN just fine. I can even pass an array of a C# struct as an array of TYPE() in FOR

相关标签:
1条回答
  • 2020-12-10 09:31

    I have done this in the past using a pointer, not an array. I think that your structures are being copied for the P/Invoke call:

    [DllImport("mathlib.dll")]
    static extern void TEST_REF(ValueRef* t, int n);
    

    You will need to pin your array before calling the method.

    fixed (ValueRef* pointer = t)
    {
      TEST_REF(pointer, n);
    }
    

    Edit: Based on the comments the solution is to declare the external as

    [DllImport("mathlib.dll")]
    static extern void TEST_REF([Out] ValueRef[] t, int n);
    

    Here is a MSDN reference on Marshaling of arrays, and how they default to [In].

    0 讨论(0)
提交回复
热议问题