Showing results for 
Search instead for 
Did you mean: 
1 View

Not able to use 'GetProcAddress' from Fortran to call .Net methods

Hi All,

Please escuse me if this post seems silly. I'm totally new to Fortran and have been tasked to use some existing Fortran DLL's in my .NET project.

I'm able to access functions created in Fortran from .net code (C# to be precise) and get replies/values back.

I also have some functions in Fortran which call external methods directly(previously they were used to call Delphi methods).

Unfortunately the same does not work on C#. Do I have to change something on the C# end get it working.

I cannot change any code in fortran as its maintained by someone else and I know fortran part works as i'm able to see data in delphi.

Have any one encountered such issues ? if so it would be great if you can direct me to some URL or jolt down some steps as to how I can impliment this.

The following is my C# code (simplified) : 

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace MYAPP
    public partial class Form1 : Form

        private const string dll_Name = "FortranDLL.dll";
        static string filePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
        byte[] fileName = System.Text.Encoding.ASCII.GetBytes(filePath);

        //This works fine
        [DllImport(dll_Name, CallingConvention = CallingConvention.Cdecl)]
        public static extern int INITIALISE(int callerId, byte[] fileName);

        public Form1()

        private void Form1_Load(object sender, EventArgs e)
            int callerId = 2;
            int returnValue = INITIALISE(callerId, fileName);
            Console.WriteLine("Initialize call " + returnValue.ToString());
            // The above statement works and i can get proper value
        public static void SetMessageString(int one, int two, byte[] arr)
            Console.WriteLine("Hello there ! ");


 Thanks & regards,

Rohan W.

0 Kudos
1 Reply
Valued Contributor III
1 View

First, I presume you know

First, I presume you know about managed vs unmanaged code on the Microsoft Windows platform; if not, see here

Re; Fortran and ,NET, here are some threads for additional background:

Lastly, you need to provide further information on what exactly you mean when you say, "Unfortunately the same does not work on C#".  If you define static methods, as described in the second and third Fortran threads above, they can be called from Fortran.

0 Kudos