Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass a dynamic structure from vb.net to Fortran DLL
    primarykey
    data
    text
    <p>I am having trouble passing structures or classes from vb.net to my Fortran DLL. In particular I would like to pass a structure or class which dynamic members (i.e. 1D arrays with dynamic memory allocation). I actually can pass fixed-size arrays but not dynamic ones. Any help will be highly appreciated!</p> <p>For instance if I have the following structure:</p> <pre><code>Module Module1 &lt;DllImport(DLL path, CallingConvention:=CallingConvention.StdCall)&gt; _ Sub sub1(ByRef ppkg As Ppkg) End Sub &lt;StructLayout(LayoutKind.Sequential)&gt; Structure Ppkg Dim id As Integer Dim arr() As Integer End Structure Sub Main() Dim pkgx As Ppkg = New Ppkg() sub1(pkgx) End Sub </code></pre> <p>On the Fortran side:</p> <pre><code>module Test type Ppkg integer :: id integer, pointer :: arr(:) end type contains subroutine sub1(aPpkg) type(Ppkg), intent(inout) :: aPpkg !DEC$ ATTRIBUTES DLLEXPORT :: sub1 !DEC$ATTRIBUTES STDCALL :: sub1 !DEC$ATTRIBUTES ALIAS : 'sub1' :: sub1 !DEC$ ATTRIBUTES REFERENCE :: aPpkg ! ... do something end subroutine sub1 end module Test </code></pre> <p>When the sub1 is called from vb.net I do not have access to the members of aPpkg%arr. However, if I to use the following in the definition of the Structure or class:</p> <pre><code>&lt;MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)&gt; Dim arr() As Integer </code></pre> <p>and in the type definition (Fortran) I use:</p> <pre><code>integer :: arr(4) </code></pre> <p>Things work but the arrays have fixed-size not dynamic. Any help? Thank you in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload