Translating FORTRAN DLLIMPORT to C++ / C#

174 views Asked by At

In my current employment, A major task is to take an existing engineering tool, and update it, as it has stopped working on the modern OS's.

Now the tool was written in FORTRAN, and most of the source file headers state something like:

C    modified by (obfuscated) at dd. mm. 19yy to do something

The employees have cycled since then, and much of the documentation was either never done, or has been lost. So it's up to us to decipher how the program operates, and then recreate that functionality in a more modern language.

For this purpose we have chosen C#.

I am somewhat able to read FORTRAN, so deciphering the math, and logic have so far been straight forward, but I am stuck when comes to dllimports.

I have no clue who made the dll's, or where the source code is, but What I have determined is that they are responsible for some of the key calculations for some of our vendors components. Hence I cannot simply replace the dll with new code as I have no clue which equations are in there..

What I have found out is that the old program sent xml formatted data to the dll entries, and got an xml-like string back. I cannot however replicate it, as I am not completely sure how it works.

Can anybody explain this, or perhaps even translate this to a C++ / C# equivalent?

  ! interface for CalculateStuff.dll
  INTERFACE
    SUBROUTINE CalculateComponent(Input, Output)
      !DEC$ ATTRIBUTES REFERENCE, ALIAS : '_CC@16' :: CalculateComponent
      !DEC$ ATTRIBUTES DLLIMPORT :: CalculateStuff
      CHARACTER*(*) Input, Output
      !DEC$ ATTRIBUTES REFERENCE :: Input
      !DEC$ ATTRIBUTES REFERENCE :: Output
    END SUBROUTINE
  END INTERFACE

Currently I have this snippet, (C#) but it seems to fail on me:

class CalculateStuff{
    [DllImport("CalculateStuff.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall, EntryPoint = "_CC@16")]
    public static extern void CalculateComponent(ref string input, ref string output);
}

edit 1: added charset and now the program gave me this exception, its an improvement I think:

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

edit 2: recompiled as 32bit application, and now I get:

External component has thrown an exception.

edit 3: changed return type to void, as this makes completely sense to me.

edit 4: added the calling convention defined as stdCall, due to many comments hinting that, it didn't help. have also tried defining the parameter types as string, or ref string nothing changes.

0

There are 0 answers