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

IVF DLL & C#

imeca
Beginner
613 Views
Hello everybody,
Can any one help about how to share strcutures and data between an IVF DLL and a C# program. I have series of subroutines made with IVF. these subroutines are called from an interface created with C# 2005.
the question is how to make the changes made on data and structures in the call of one subroutine, seen in the other calls.
in other words, when i call for example a subroutine that multiplies x by 2, i want that any other subroutine using x will be called with the new value of x.
x is only an example but i would like to know is how to exchange whole stuctures between the subroutines in the DLL and the C# program.
thank you.
0 Kudos
3 Replies
onkelhotte
New Contributor II
613 Views

One way is, that you declare x in a module you use in every subroutine:

module GlobVars
real*4 x
end module

subroutine multiply(factor1, factor2)
use GlobVars
real*4 factor1, factor2
x = factor1*factor2
end subroutine

When you need to know the value of x in C# you simply create a function that returns the value of x:

Fortran code:
real*4 function GET_X()
!DEC$ ATTRIBUTES DLLEXPORT::GET_X
use GlobVars
GET_X = x
end function GET_X

C# code:
[DllImport("fortran.dll")]
private extern static float GET_X();

Markus

0 Kudos
imeca
Beginner
613 Views
Thank you markus,
i appreciated your help.
i ll try this and i ll keep you informed.

0 Kudos
onkelhotte
New Contributor II
613 Views

Arrays and strings are a little bit tricky compared to integer or real types.

When you need any help, drop a mail.

Markus

0 Kudos
Reply