Silverfrost Forums

Welcome to our forums

Linking FTN95 code with Powerstation 4.0 dll

5 Jul 2016 8:02 #17736

I am trying to make an executable using FTN95 (v8.00.0)/SLINK and an old third party dll compiled with Powerstation 4.0. (32bit)

In the source code I have the interface statement and an external statement and also the dll is included in the Reference list in Plato.

However, the routine (SUBR1) in the .dll is not found when I compile the program: SLINK says:

   WARNING the following symbols are missing:
   SUBR1      H:\prog\X\lgotemp@.obj

An executable is produced but the following runtime error mentions the same:

   Error 29: Call to missing routine

In the source code I have:

      INTERFACE
        SUBROUTINE SUBR1(r1, r2)                             
          REAL * 4 r1,r2 
        END SUBROUTINE
      END INTERFACE

      EXTERNAL SUBR1                   

For clarity I have simplified the code, without removing essentials.

Jaap

5 Jul 2016 9:59 #17737

I don't recall how Powerstation works but the DLL may use the STDCALL protocol for passing arguments.

If this is the case then you will need a STDCALL interface as described FTN95 in the help file under Win32 platform->Mixed language programming->Calling FTN95 from C/C->Calling C/C from FTN95.

Admittedly you are calling Powerstation Fortran (not C/C++) from FTN95 but the interface may be right. The arguments will probably be passed by reference. Things get more complicated if, for example, you pass a character string because there will be additional hidden arguments and FTN95 will not known where to put them.

5 Jul 2016 10:23 #17738

Given your last remark I might have simplified the example too much, as The actual subroutine is called with 22 variables including two strings and also arrays and 2-D tables. (Now simplified to include one 30char string)

When I change

EXTERNAL SUBR1 

into

STDCALL SUBR1

I get compiler error message

*** SUBROUTINE SUBR1 has been called with too many arguents

So changing code into:

STDCALL SUBR1 'subr1'(VAL,STRING(30),VAL)

an executable is produced as expected, but that aborts runtime at the line the subroutine is called:

Access Violation
The instruction at address 1000c1d6 attempted to write to location ffffd8f1

1000c1d6 routine at address 1000C1D6 [+0000]

Deleting INTERFACE definition gives same result.

5 Jul 2016 10:50 #17739

I don't think that I would even try to link FTN95 to a Powerstation Fortran DLL in this case. You would need to know how the arguments are passed (VAL or REF), where the hidden arguments are placed and what they do.

Do you have the source code for the DLL?

7 Jul 2016 11:22 #17751

Hi Paul,

Thank you for analyzing the dll specifics. Your solution to change VAL into REF and add '//char(0)' to the string made my day.

Thanks!

Please login to reply.