- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to pass an allocatable array from my main fortran exe to a
fortran dll. The array is supposed to be allocated in the dll, passed
back out, and deallocated in the calling routine. However, on entry to
the dll routine, the debugger throws a heap error.
The dll code is as follows:
subroutine ExampleLib2 (array)
! Expose subroutine ExampleLib to users of this DLL
!
!DEC$ ATTRIBUTES STDCAll, DLLEXPORT::ExampleLib2
!DEC$ATTRIBUTES REFERENCE :: array
integer, allocatable, dimension(:), intent (out):: array
if (allocated(array)) deallocate(array)
allocate (array(3))
array(2) = 555
return
end subroutine
The main program code is:
The dll code is as follows:
subroutine ExampleLib2 (array)
! Expose subroutine ExampleLib to users of this DLL
!
!DEC$ ATTRIBUTES STDCAll, DLLEXPORT::ExampleLib2
!DEC$ATTRIBUTES REFERENCE :: array
integer, allocatable, dimension(:), intent (out):: array
if (allocated(array)) deallocate(array)
allocate (array(3))
array(2) = 555
return
end subroutine
The main program code is:
program MainApp
implicit none
integer :: j_status
integer, allocatable, dimension(:) :: array2
interface
subroutine examplelib2 (array)
!dec$ attributes stdcall, dllimport::examplelib2
!dec$attributes reference :: array
integer, allocatable, dimension(:), intent (out):: array
end subroutine
end interface
call ExampleLib2 (array2)
if (allocated(array2)) deallocate(array2, stat=j_status)
end program MainApp
Does anybody have any ideas as to why this doesnt work? Can you not
pass allocatable arrays across dlls in this way?
Thanks in advance
Ranbir
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You MUST change the main project's property to specify the "Use run-time libraries" Multithread DLL (it must match the DLL's setting). In other words, all Fortran code in the application must be using the same copy of the run-time library.
The default for DLL projects is to link against the DLL libraries, but for EXE projects it's to link against the static libraries.
The default for DLL projects is to link against the DLL libraries, but for EXE projects it's to link against the static libraries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yup, that solved my problem...thanks
Ranbir
Ranbir
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