Search code examples
c++dynamicdllfortranbackwards-compatibility

How to create dynamic DLL library in C++, to substitute legacy Fortran DLL


I have to create a dynamic DLL library in C++, to substitute old DLL library written in Fortran, without changing the host application (so functions and parameters must stay the same).

I have full specification of all Fortran functions in that library, but what tools (compiler) I need to use, and what is the way of coding DLL in this situation (stdcall, cdecl, dllexport etc. - that clues doesn't say much to me, I never created a DLL before).

This is sample Fortran function declaration in legacy DLL:

SUBROUTINE SetBoundaries(MaxFlow, MinFlow)
cDEC$ ATTRIBUTES DLLEXPORT :: SetBoundaries
cDEC$ ATTRIBUTES ALIAS: "SetBoundaries" :: SetBoundaries

REAL MaxFlow
REAL MinFlow

I tried to compile VC2008 DLL but got error:

Unhandled error in 'InitAllPublicVars' Run-time error 453: Can't find DLL entry point DLLVersion in SomeLib.DLL

Source of this DLL (defining function named DLLVersion doesn't help):

void __stdcall SetBoundaries( float *min , float *max ) {
}

Is DLLVersion some special DLL procedure or just lack in my documentation and I should create such function?

I know no details about original Fortran DLL source/compilation process, but there are some extracted informations:

General Some options Imports


Solution

  • I found a solution. DLL functions should be declared like this:

    extern "C" void __declspec(dllexport) SetBoundaries( int min , int max ) {
    
    }
    

    Note that parameters are not pointers. I logged function calls and DLL gets valid numbers from the host application when put instead of original Fortran DLL. Compiled with Visual Studio 2008.