Sagar
Sagar

Reputation:

How to call c# code from Fortran dll

Currently I have abc.dll which is fortran dll. Now I want to call C# code from abc.dll. Is there any way to call the C# code from fortran dll ?

thanks Sagar

Upvotes: 2

Views: 1339

Answers (2)

F'x
F'x

Reputation: 12298

Compilers supporting recent Fortran language features (the 2003 standard) will support C-interoperation. You interface with other code through its C interface, using the ISO_C_BINDING module and the BIND construct. Most recent compilers have it, it's standard and you can find a lot of documentation (like this one) by Google'ing the keyword ISO_C_BINDING.

Upvotes: -1

Sam Harwell
Sam Harwell

Reputation: 99869

Typically, if your program is written entirely in native code (as I believe the Fortran dll would be), you'll need to call a method that's been exported (dllexport) from another native code module. In this case, you'll want to create a Managed C++ dll that exposes a native interface and internally makes the call into the C# code.

Edit: If the hosting program is managed code, and you need to do a C#->Fortran (native)->C# calling sequence, then delegates as unmanaged function pointers can be used as linked in the comments above. However, if the executable is not managed code, you'll need to go the route I mentioned.

Upvotes: 2

Related Questions