- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And then I want to return the calulated results in dll to main program.
The following code does not work, please let me know how to do that.
please correct the following code workable.
The following is the code in DLL file.
subroutine test
!DEC$ ATTRIBUTES DLLEXPORT :: test
use input
integer i, j
do i = 1, 5
do j = 1, 5
arr(i, j) = i + j
enddo
enddo
end subroutine
The following is the code in main program uses the dll.
module input
real arr(5,5)
end module
interface
subroutine test
!DEC$ ATTRIBUTES DLLIMPORT :: input
use input
end subroutine
end interface
program main
call test
do i=1,5
write(*,*) (arr(i,j), j=1,5)
end do
stop
end program
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The DLLIMPORT statement should probably read
!DEC$ ATTRIBUTES DLLIMPORT :: test
Also, in the project linker settings,you need to add the import .LIB file with its path and library name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I added the import .LIB file with its path in the project linker settings.
I want to use module in dll file.
Please let me know how to transfer the value from dll to main program.
! source code in dll file
!========================
module input
integer k
end module
!DEC$ ATTRIBUTES DLLEXPORT :: test
use input
k=9999
end subroutine
! source code in main program
!============================
module input
integer k
end module
use input
interface
subroutine test
!DEC$ ATTRIBUTES DLLIMPORT :: test
use input
end subroutine
end interface
write(*,*) k
pause "Press Return to Exit"
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The CVF documentation under Creating Fortran Dlls, and itsassociated examples in the Samples folder, shows how to transfer valiables between a Dll and a main program using exported common blocks. The easiest way to do what you want might be to emulate one of the examples.
You can also transfer data using modules, or using arguments of exported functions, but I'm not sure whether there is any example for you to copy. In your current code, the main program and the Dll each have their own copies of the module. The CVF documentation section "Exporting and Importing Data Objects in Modules" discusses how to do what you want by giving data objects in the module the DLLEXPORT property.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Icannot find out the detailed explanation and example code in the CVF documentation section "Exporting and Importing Data Objects in Modules".
please anyone let me know where I can find the sample code about Exporting and Importingmodule in dll.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My first advice would be: don't do that. Dllexporting/importing variables is a bad idea, error-prone and with nointerface separation (which is one ofprimary reasons why you create a dll). Global data in general are a bad thing, and shared global data between a dll and exe are an even worse thing. See examples here, and here.
Afar better approach is to use argument lists of dll routines for data exchange. If there are a lot ofvariables, you can pack them into a derived TYPE to reduce long argument-lists.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a similar problem, but my main program is in Java.
The main program calls a Fortran dll (dll_1) which contains a module, and then this dll (dll_1) calls another Fortran dll (dll_2) which needs to use a lot of variablesfrom the module of dll_1.
Do I need to create a third Fortran dll to share the variables?
Can I load dll_1 from dll_2?
I am veryworried of efficiency and velocity of the program so I prefer the fastest solution for this problem.
I can't joint both dll into one, because dll_2 is generated in the execution time of the main program in Java.
Thanks
Message Edited by faderibera on 06-23-2004 07:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page