I have two old fortran programs that are supposed to be talking to each other, originally both writen and compiled using old Compaq compiler. Recently we switched due to various reasons to the Intel compiler and except for a few minor incompartibility issue the code for both programs compiles nicelly.
Program 1 is a DLL, and program 2 makes multiple calls of that dll. The dll creates as an output a text file which is then read by program 1. The output for the first 3 calls is ok, the 4th call and all calls after return only gibberish. I made a small test where I called the dll 8 times with the identical input, same problem, results 1 to 3 are ok, result 4 and up are garbage.
I've searched these forums and have seen that this can be due to thge stack corruption if the calling convention is not explicitly defined (as in STDCALL), however this then leads to the an unresolved external symbol error from the linker. I'm a bit of a "hobby programmer", so I was hoping that a more experienced user can point me to a simple solution for this problem.
Here is an example of the code:
------ PROGRAM 1 ---------
Real*8 FUNCTION DLLTEST(INFILE, OUTFILE, DLLFLAG)
INTERFACE
REAL*8 FUNCTION DLLTEST(INFILE, OUTFILE, DLLFLAG)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, ALIAS: 'DLLTEST' :: DLLTEST
CHARACTER*200 INFILE, OUTFILE
INTEGER DLLFLAG
END FUNCTION
END INTERFACE
.....internal workings....
END FUNCTION
------ PROGRAM 2 ---------
INTERFACE
REAL*8 FUNCTION DLLTEST(INFILE, OUTFILE; DLLFLAG)
!DEC$ ATTRIBUTES DLLIMPORT, STDCALL, ALIAS: 'DLLTEST' :: DLLTEST
CHARACTER*200 INFILE, OUTFILE
INTEGER DLLFLAG
END FUNCTION
END INTERFACE
REAL*8 DUMMY
multiple calls to: DUMMY = DLLTEST(INFILE, OUTFILE, DLLFLAG)
---> The DLLTEST.lib is specified as dependancy for Program2, but linker produces following error: LNK2019: unresolved external symbol __imp__DLLTEST reference in function _MAIN__
Removing STDCALL and ALIAS resolves the problem but leads to call stack corruption during multiple calls. Any help and pointers would be apreciated. Thanks in advance.
Alexander