Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Is it possible to call C# directly from Fortran?

Sherry_Ummen
Beginner
724 Views

Hello,

I know its possible to call C# from Fortran via C++. but was wondering do we some direct way to do it with the new intel compiler 2015?

Thanks

0 Kudos
3 Replies
andrew_4619
Honored Contributor III
724 Views

there are lots of threads on this subject in the forum if you do a search.....

0 Kudos
Steven_L_Intel1
Employee
724 Views

The most straightforward way is to have C# build a regular (not COM or Automation) DLL. You'll then need to figure out what the C# code is looking for in its arguments. Not all C# argument types can be passed from Fortran.

0 Kudos
jimdempseyatthecove
Honored Contributor III
724 Views

A sketch of Steve's advice is as follows:

// C# .dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using YourOtherStufv;

namespace YourDLL
{
  public class YourDLLAsApp
  {
    public static void lauchYourApp(IntPtr ptr) // you figure out args you want
    {
      Console.WriteLine("We are now inside YourDLLAsApp (C# managed)");
      ...
    }
  }
}

! your interfaces
module mod_Interfaces
...
interface
  !  void lauchYourApp(void* ptr1)
  SUBROUTINE lauchYourApp(ptr) BIND(C, name="lauchYourApp")
    use, intrinsic :: ISO_C_BINDING
    use mod_Interfaces
    procedure(YourProcedure), pointer :: ptr
  end SUBROUTINE lauchYourApp
end interface
...
end module mod_Interfaces

! your program
PROGRAM YourProgram
  use mod_Interfaces
  ...
  call lauchYourApp(SomeFortranRoutineOrType)
  ...
end program YourProgram

The code is untested, merely a sketch.

Jim Dempsey

 

0 Kudos
Reply