Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
16 Views

DLLs and Common block

I used Help files in IVF, "Coding Requirements for Sharing Data in DLLs", "Exporting and Importing Common Block Data", where example of appropriate DLLEXPORT directive is included and described. When I create a dll and I put common blocks that I want to be linked to the same common block in my exe program, the common block information does not pass from the exe to the dll.

How can I declare common block in both the main exe and any dll and having the information passing?

The code source of the DLL is:
subroutine Seta
use user32
use kernel32
!DEC$ ATTRIBUTES STDCALL, REFERENCE,ALIAS :"Seta":: Seta
!DEC$ ATTRIBUTES DLLEXPORT:: Seta, /X/
implicit none
common /X/C,B,A
real C,B,A
A=A+1
B=B+1
return
end subroutine Seta

The subroutine in the main program that uses the DLL is:

subroutine test

use user32

use kernel32

implicit none

pointer (p_seta, seta)

integer(HANDLE) :: dll_handle

integer(BOOL) :: free_status

integer i

real AP

common /X/C,B,A

real C,B,A

Interface

subroutine Seta

!DEC$ ATTRIBUTES DLLIMPORT:: Seta, /X/

implicit none

common /X/C,B,A

real C,B,A

end subroutine Seta

end interface

!==========================================!

dll_handle = LoadLibrary ("DLL_a.dll"C)

! Check for errors

if (dll_handle == NULL) then

! Failure

stop

end if

p_seta = GetProcAddress (dll_handle, "Seta"C)

if (p_Seta == NULL) then

! Failure

stop

end if

! Now call the function

call seta ! the value of A in the DLL is 1

Ap=A ! the value of A in the subroutine test is 0 so Ap=0

free_status = freelibrary(p_seta)

end subroutine Test

If you have a solution, pelase send me a simple example.
thanks in advance

0 Kudos
1 Reply
Highlighted
Black Belt
16 Views

Check the examples which come with your compiler. Don't try to mix conventions from different eras. Look up examples discussed on the Windows Fortran forum, and ask questions there.
0 Kudos