- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I work under VS2005 with Intel Fortran Compiler. i must call method on DLL fortran in C#. this method is actually call by a C++ program (under linux).
Could i call this method without any change ?
here the beging of the method
I work under VS2005 with Intel Fortran Compiler. i must call method on DLL fortran in C#. this method is actually call by a C++ program (under linux).
Could i call this method without any change ?
here the beging of the method
[fxfortran]SUBROUTINE CAL_INIT_OUTPUT ( DMPOutput1,DMPOutput2,DMPOutput3) use, intrinsic ::ISO_C_BINDING IMPLICIT NONE INCLUDE 'xxx.def' INTEGER*4 I, J, K INTEGER*4 INDICE type(T_DMPOutput1), intent(out) :: DMPOutput1(DIM_BRA_DEF) type(T_DMPOutput2), intent(out) :: DMPOutput2(DIM_OUTILS) type(T_DMPOutput3), intent(inout) :: DMPOutput3 [/fxfortran]
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Fortran code should be the same, but the setup in Visual Studio will differ than Linux. For instance you will need to use the /dll switch to make the DLL.
------
Wendy
Attaching or including files in a post
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok it works but I have a problem when struct have array .
I couldn't get back correct array values in fortran DLL. In this example, "tabi" and "tabr" haven't good value in fortran module...
here my fortran structure:
Here my fortran method (in dll)
Here my C# programm
I couldn't get back correct array values in fortran DLL. In this example, "tabi" and "tabr" haven't good value in fortran module...
here my fortran structure:
[bash] type, bind(C) :: T_Struct INTEGER*4 aaa REAL*4 bbb integer*4 tabi(3) real*4 tabr(4) end type T_Struct [/bash]
Here my fortran method (in dll)
[bash] SUBROUTINE MODB (TRIGGER_NUMBER, 2 V_Struct_in, 3 V_Struct_inout, 4 V_Struct_out) BIND(C,NAME="ModB") !DEC$ ATTRIBUTES DLLEXPORT :: ModB use, intrinsic ::ISO_C_BINDING IMPLICIT NONE INCLUDE 'ModB.def' INTEGER*4 TRIGGER_NUMBER integer*4 a real*4 b type(T_Struct), intent(in) :: V_Struct_in type(T_Struct), intent(inout) :: V_Struct_inout type(T_Struct), intent(out) :: V_Struct_out a = trigger_number a = V_Struct_in%aaa+ 5 b = V_Struct_in%bbb+ 1.5 V_Struct_inout%aaa = V_Struct_inout%aaa+ 5 V_Struct_inout%bbb = V_Struct_inout%bbb+ 1.5 V_Struct_out%aaa = 9 V_Struct_out%bbb = 11.11 end subroutine[/bash]
Here my C# programm
[bash] internal struct T_Struct { internal int entier; internal float reel; internal int[] tabi; internal float[] tabr; internal T_Struct(Boolean empty) { entier = 0; reel = 0.0f; tabi = new int[3]; tabr = new float[4]; } } [/bash]
[bash] [DllImport("Test_DLL_C.dll")] private static extern void ModB(ref int TRIGGER_NUMBER, ref T_Struct v_Struct_in, ref T_Struct v_Struct_inout, ref T_Struct v_Struct_out ); private void button1_Click(object sender, EventArgs e) { try { T_Struct v_Struct_in = new T_Struct(true); v_Struct_in.entier = 10; v_Struct_in.reel = 10.1f; v_Struct_in.tabi = new int[] { 1, 2, 3 }; v_Struct_in.tabr = new float[] { 1.1f, 2.2f, 3.3f }; T_Struct v_Struct_inout = new T_Struct(true); v_Struct_inout.entier = 10; v_Struct_inout.reel = 10.1f; v_Struct_inout.tabi = new int[] { 1, 2, 3 }; v_Struct_inout.tabr = new float[] { 1.1f, 2.2f, 3.3f }; T_Struct v_Struct_out = new T_Struct(true); ModB(ref i, ref v_Struct_in, ref v_Struct_inout, ref v_Struct_out); } catch (Exception ex) { MessageBox.Show(ex.Message + "n" + ex.InnerException); } } [/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe only a minor contributor to the problem (if that), but I don't see why you would depend on undefined interoperability of the non-standard types integer*4, real*4 in place of integer(c_int), real(c_float).
Are you certain that your array references don't correspond to c_ptr ?
Are you certain that your array references don't correspond to c_ptr ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'v got response on other forum then for the futur search: "Fortran probably uses embedded arrays. Mark the arrays as ByValArray:"
Then I must use "[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]" for my tabi for example
![](/skins/images/BC9A7A3465121B56B278007F4EE8899F/responsive_peak/images/icon_anonymous_message.png)
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