- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to passderived types between a vb.net GUI and a Fortran dll. I would like the derived type to contain 1D and 2D arrays. Is any of this possible? I can't seem to find a complete and clear example of this and would appreciate some advice or if it's not possible to know for sure. Or know the limitations if some of it is possible but maybe not the arrays.
If derived types aren't possible what about 2D arrays not in a derived type? I've read where people have had trouble with this but again can't find a complete and clear example of it working.
Thanks
If derived types aren't possible what about 2D arrays not in a derived type? I've read where people have had trouble with this but again can't find a complete and clear example of it working.
Thanks
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I assume that VB derived types with arrays would have pointers to a SafeArray structure. This is not something we have looked at. There are two examples of VB.Net calling Fortran, one of which deals with SafeArrays as a routine argument. I suggest you look at this. These examples are in MixedLanguage.zip.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve
The example that deals with safearray structures passes an array of strings. If I want to pass an array of reals or integers would I stilluse asafearray along withthe BSTRPtr and ConvertBSTRToString function? How wouldthe methodologydiffer? How would I convert it to a real? Is there an easier more direct way of doing this?
Thanks
The example that deals with safearray structures passes an array of strings. If I want to pass an array of reals or integers would I stilluse asafearray along withthe BSTRPtr and ConvertBSTRToString function? How wouldthe methodologydiffer? How would I convert it to a real? Is there an easier more direct way of doing this?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You wouldn't use the BSTR stuff with reals or integers. So where the code calls SafeArrayGetElement, the pointer is to a REAL (or INTEGER or whatever) not a BSTR. So instead of:
integer(int_ptr_kind()) :: BSTRPTR
you might have:
real :: real_element
pointer (p_real, real_element)
and then pass loc(p_real) as the last argument to SafeArrayGetElement. You could then use variable real_element.
There might be a shortcut to access a section of an array but I'd have to play with it to see.
integer(int_ptr_kind()) :: BSTRPTR
you might have:
real :: real_element
pointer (p_real, real_element)
and then pass loc(p_real) as the last argument to SafeArrayGetElement. You could then use variable real_element.
There might be a shortcut to access a section of an array but I'd have to play with it to see.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have no experience of derived types in VB .NET, but it is straightforward to pass arrays from VB .NET to Fortran without having to resort to SafeArrays. I attach sample code for the Visual Basic side to pass 2D arrays of Doubles, Integers and Longs and and the Fortran code required to receive them on the Fortran side.
All you need to remember this time is that VB .NET stores array elements in row-major order (as opposed to VBA in Excel which appears to store arrays in column-major order as per Fortran!).
The VB .NET code sets array value (i,j) = the decimal number 'ij' so that you can immediately see on the Fortran side the array indexes that VB .NET used for a received array value (as you can see in the Debug Screen-shot also attached).
P.S. I used Microsoft Visual Basic 2008 Express Edition which uses the .NET Framework
All you need to remember this time is that VB .NET stores array elements in row-major order (as opposed to VBA in Excel which appears to store arrays in column-major order as per Fortran!).
The VB .NET code sets array value (i,j) = the decimal number 'ij' so that you can immediately see on the Fortran side the array indexes that VB .NET used for a received array value (as you can see in the Debug Screen-shot also attached).
P.S. I used Microsoft Visual Basic 2008 Express Edition which uses the .NET Framework

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page