Calling DLL subroutines

Calling DLL subroutines

How can I make one DLL (Dynamic Link Lib) subroutine visible to another so that it can be called from within the same source file.

When compiled, the following DLL routines can be successfully called from my main Visual Basic program but when I try to call CktArray from ForSTR it doesn't work.

C****************************************************************************
C* CALL LUROW (A,10,N)
C* CALL SOLVE (A,10,N,B)
C****************************************************************************
C*ROUTINE SOLVES A.x = B WITH RESULT X RETURNED IN B WHICH IS
C*DESTROYED. ON INPUT A CONTAINS THE LU FACTORS OBTAINED FROM LUG,
C*LUROW OR CROUT. IT HAS DIMENSION N WITH THE ABSOLUTE ROW DIMENSION
C*OF A BEING IA IN THE CALLING PROGRAMME.
C****************************************************************************
SUBROUTINE SOLVE (A [REFERENCE], N [VALUE], B [REFERENCE])
!DEC$ ATTRIBUTES DLLEXPORT:: SOLVE
!DEC$ ATTRIBUTES ALIAS : "SOLVE" :: SOLVE
COMPLEX*16 A(60, 60), B(60), T
REAL*8 Mag, Ang, RE, IM
INTEGER*2 I, J, N

C Some code here.

END

C****************************************************************************
C*TRIANGULAR FACTORIZATION BY ROW DECOMPOSITION
C*A IS INPUT MATRIX OF SIZE N WITH ABSOLUTE ROW DIMENSION IA IN THE
C*CALLING PROGRAMME
C*ROUTINE RETURNS LU FACTORS OF A, STORED IN A WHICH IS DESTROYED
C****************************************************************************
SUBROUTINE LUROW (A [REFERENCE], N [VALUE])
!DEC$ ATTRIBUTES DLLEXPORT:: LUROW
!DEC$ ATTRIBUTES ALIAS : "LUROW" :: LUROW
COMPLEX*16 A(60, 60), T
REAL*8 Mag, Ang
INTEGER*2 I, J, N

C Some code here

END
C****************************************************************************
C*Test routines
C****************************************************************************
SUBROUTINE FORSTR (S1)
!DEC$ ATTRIBUTES DLLEXPORT:: FORSTR
!DEC$ ATTRIBUTES ALIAS : "FORSTR" :: FORSTR
CHARACTER* (*) S1
INTEGER*2 IA(0:2)
INTEGER*2 N

S1(18:21) = "Test"

! Call CktArray(IA(0), N) ***** THIS DOES NOT WORK

END

SUBROUTINE CktArray (Ckt11 [REFERENCE], D1 [VALUE])
!DEC$ ATTRIBUTES DLLEXPORT:: CktArray
!DEC$ ATTRIBUTES ALIAS : "CktArray" :: CktArray
INTEGER*2 D1
INTEGER*2 D2
INTEGER*2 Ckt11(0:D1)
INTEGER, DIMENSION(:), ALLOCATABLE :: AC
COMMON D2

ALLOCATE(AC(0:D1))

AC(0) = Ckt11(0)

END

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

That's because you overrode default argument passing and name mangling (ALIAS directives), thus, ForStr is "unable to see" what the prototype of CktArray is. As VB requires Declare Function statement, Fortran requires INTERFACE blocks (or MODULE association).

If I got you right that the routines are in the same source file,
enclosing the code above in

 
MODULE MyModule 
CONTAINS 
...[your code here] 
END MODULE 

would work like a charm, since it would make all function declarations mutually visible. Otherwise, you'll need INTERFACE blocks for each called routine.

Jugoslav

Jugoslav
www.xeffort.com

Thank you, Jugoslav, for the help! You were right, the MODULE statement made all the DLLEXPORT subroutines visible and callable from each other (as well as VB). I only had to add one more thing to remove the last compile error. Enclosing all the routines in a MODULE required that I now append "SUBROUTINE SubName" to their END statements. For example the end of the FORSTR routine expects "END SUBROUTINE FORSTR". Once again, THANK YOU... IT WORKS!!!

-Dale

Leave a Comment

Please sign in to add a comment. Not a member? Join today