- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have some array-valued function in a fortran dll and I like to use this function in VBA.
function func(n) result (y)
implicit none
integer(4) :: n
real(8), dimension(n) :: y
..
..
end function func
Is it possible to call/declare such an array-valued function and does someone know how to do this.
Thanks
Aid
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try the following
VBA
Public Declare Functionfunc Lib "C:Winntsystem32yourfortran.dll"
(A1 As integer) As double
FORTRAN (note:Fortran makes everything UPPERCASE by default, so the ALIAS attribute is required tosupply a lowercaseentry 'func' in the Dll's exported symbol table that VBA needs, otherwise you need to make 'func' UPPERCASE in the VBA 'Public Declare' statement.]
REAL*8 FUNCTIONFUNC (N )
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:'func' ::FUNC
INTEGER(4) N
.......
.......
FUNC=
....
END FUNCTION FUNC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have just realised that the above will not work for ARRAYs as Visual Basic uses 'Safe arrays', which are structures that are not easily represented in Fortran.
As Steve mentions below, you could examine the SAFEARRAY sample code which shows you how to convert a 2 dimensional Fortran array into a safearray. After you have generated your Fortran array of data, you could then call this code to generate a safearray from it, whose address you can then return to the calling VB program as Steve suggests, using a SUBROUTINE call rather than a FUNCTION call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It would be easier if you called this from VB as a subroutine passing the first element of the array "return" as the first argument.
![](/skins/images/D3C0B914909A6564BBB97F4AD1ED1973/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page