- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to export the module procedure so that I can call it from C#. I can access the routine if it is not part of a module, i.e., access to subroutine. But if I place the subroutine in a module, I could not make it working. How to do that? Any help would be greatly appreciated. Example code to demonstrate the requirement is as follows:
1. C# of caller class (sample, taken from other Intel article)
public class FortranDllWrap
{
[DllImport("datdatart.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void balt();
// how to code here??
}
module datdatart
! how can get the Interface access so that I do not need to define interface's routine in the caller C# class?
interface balt
module procedure baltut, baltutr
end interface
contains
subroutine baltut(a)
integer a
!DEC$ ATTRIBUTES DLLEXPORT :: BALTUT
a = 2;
end subroutine baltut
subroutine baltutr(a)
real a
!DEC$ ATTRIBUTES DLLEXPORT :: BALTUTR
a = 4.0;
end subroutine baltutr
end module datdatart
Thank you very much
1. C# of caller class (sample, taken from other Intel article)
public class FortranDllWrap
{
[DllImport("datdatart.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void balt();
// how to code here??
}
module datdatart
! how can get the Interface access so that I do not need to define interface's routine in the caller C# class?
interface balt
module procedure baltut, baltutr
end interface
contains
subroutine baltut(a)
integer a
!DEC$ ATTRIBUTES DLLEXPORT :: BALTUT
a = 2;
end subroutine baltut
subroutine baltutr(a)
real a
!DEC$ ATTRIBUTES DLLEXPORT :: BALTUTR
a = 4.0;
end subroutine baltutr
end module datdatart
Thank you very much
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your problem is two-fold:
- The standard solution to achieve a C#-callable routine is to declare your Fortran routines with BIND(C) attribute (meaning, callable from C or "compatible" language), and optionally give them a binding name:
[fortran]public class FortranDllWrap { [DllImport("datdatart.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void baltut(); } ... module datdatart contains subroutine baltut(a), bind(C, name="baltut") !DEC$ ATTRIBUTES DLLEXPORT :: BALTUT ... end subroutine baltut[/fortran]
- However, you cannot call a generic interface from other language, as you attempted. Generics in general (i.e. not limited to Fortran) are resolvable only within one language: in Fortran, the compiler decides which version (specific procedure) of balt will be called. C# compiler cannot do that, because it cannot see the generic interface. -- there is no bindable entity called "balt" to link with.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Jugoslav. However, how to avoid module procedure in Fortran? I mean, how can I get the variable type (interger or real) and its kind (KIND(variable) will do, right?)? I could not find how to get whether the variable (especially if the variable is an array) is real, integer or character?
thank you very much

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page