<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Java / Fortran JNA compatibility  in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Java-Fortran-JNA-compatibility/m-p/773021#M23543</link>
    <description>Hi,&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I would like to develop a GUI in Java, calling Fortran dll.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I succedded in calling the dll from java, but it seems that the values given to the dll are incorrect.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Fortran code&lt;/DIV&gt;&lt;DIV&gt;[fortran]function hello(texte, long)
!DEC$ ATTRIBUTES C, ALIAS:'foohell', DLLEXPORT :: hello
INTEGER, value :: long
CHARACTER(LEN=long) ::texte 
integer :: hello

PRINT*, texte

END FUNCTION[/fortran] Java code&lt;/DIV&gt;&lt;DIV&gt;[java]import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.PointerType;
import com.sun.jna.ptr.ByReference;
import com.sun.jna.ptr.IntByReference;

public class BeepExample {
    public interface F95Test extends com.sun.jna.Library {
        F95Test lib = (F95Test) Native.loadLibrary("C:/Users/egal/Documents/Visual Studio 2010/Projects/libF90/libF90/Debug/libF90.dll", F95Test.class);

        int foohell(String hw, int l);
    }

    public static void main(String[] args) {        
        String hw = "Hello World";
        int r = F95Test.lib.foohell(hw, hw.length());
   }
}

[/java] The Netbeans console returns the 11 following characters:&lt;/DIV&gt;&lt;DIV&gt;&lt;IMG height="80" width="200" src="http://img15.hostingpics.net/pics/850313console.png" /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;So I guess that the passed argument "Hello World" is not taken into account.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Thanks in advance for your help&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Ren&lt;/DIV&gt;</description>
    <pubDate>Mon, 06 Aug 2012 10:01:17 GMT</pubDate>
    <dc:creator>Renaud_Egal</dc:creator>
    <dc:date>2012-08-06T10:01:17Z</dc:date>
    <item>
      <title>Java / Fortran JNA compatibility</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Java-Fortran-JNA-compatibility/m-p/773021#M23543</link>
      <description>Hi,&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I would like to develop a GUI in Java, calling Fortran dll.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I succedded in calling the dll from java, but it seems that the values given to the dll are incorrect.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Fortran code&lt;/DIV&gt;&lt;DIV&gt;[fortran]function hello(texte, long)
!DEC$ ATTRIBUTES C, ALIAS:'foohell', DLLEXPORT :: hello
INTEGER, value :: long
CHARACTER(LEN=long) ::texte 
integer :: hello

PRINT*, texte

END FUNCTION[/fortran] Java code&lt;/DIV&gt;&lt;DIV&gt;[java]import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.PointerType;
import com.sun.jna.ptr.ByReference;
import com.sun.jna.ptr.IntByReference;

public class BeepExample {
    public interface F95Test extends com.sun.jna.Library {
        F95Test lib = (F95Test) Native.loadLibrary("C:/Users/egal/Documents/Visual Studio 2010/Projects/libF90/libF90/Debug/libF90.dll", F95Test.class);

        int foohell(String hw, int l);
    }

    public static void main(String[] args) {        
        String hw = "Hello World";
        int r = F95Test.lib.foohell(hw, hw.length());
   }
}

[/java] The Netbeans console returns the 11 following characters:&lt;/DIV&gt;&lt;DIV&gt;&lt;IMG height="80" width="200" src="http://img15.hostingpics.net/pics/850313console.png" /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;So I guess that the passed argument "Hello World" is not taken into account.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Thanks in advance for your help&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Ren&lt;/DIV&gt;</description>
      <pubDate>Mon, 06 Aug 2012 10:01:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Java-Fortran-JNA-compatibility/m-p/773021#M23543</guid>
      <dc:creator>Renaud_Egal</dc:creator>
      <dc:date>2012-08-06T10:01:17Z</dc:date>
    </item>
    <item>
      <title>Java / Fortran JNA compatibility</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Java-Fortran-JNA-compatibility/m-p/773022#M23544</link>
      <description>A variable of the type String is an object. You have to convert it to a plain string (sequence of bytes) first.&lt;BR /&gt;IIRC, you need to transform the string into an array of bytes.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Arjen</description>
      <pubDate>Mon, 06 Aug 2012 10:45:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Java-Fortran-JNA-compatibility/m-p/773022#M23544</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2012-08-06T10:45:47Z</dc:date>
    </item>
    <item>
      <title>Java / Fortran JNA compatibility</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Java-Fortran-JNA-compatibility/m-p/773023#M23545</link>
      <description>Hello Arjen,&lt;DIV&gt;thanks for answering on so short notice.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Turns out I found something more "direct" to pass a string from java to fortran.&lt;/DIV&gt;&lt;DIV&gt;[java]...        
void STRSUB(String daa, int len);
...[/java] &lt;/DIV&gt;&lt;DIV&gt;[java]        //sub strsub
        String saa = "HelloWorld";
	F95Test.lib.STRSUB(saa, saa.length());
        System.out.print("n");[/java] [fortran]subroutine STRSUB(str, len)
  !DEC$ ATTRIBUTES DLLEXPORT::STRSUB
  INTEGER, value :: len
  CHARACTER(len) :: str
PRINT*, "dll strsub : ", str

end subroutine STRSUB[/fortran] Works better and it is simpler.&lt;/DIV&gt;&lt;DIV&gt;Actually, I think that the real problem was the fact I was not compiling my dll with proper options (calling convention).&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Thanks anyway, problem solved ;)&lt;/DIV&gt;</description>
      <pubDate>Mon, 06 Aug 2012 15:16:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Java-Fortran-JNA-compatibility/m-p/773023#M23545</guid>
      <dc:creator>Renaud_Egal</dc:creator>
      <dc:date>2012-08-06T15:16:24Z</dc:date>
    </item>
  </channel>
</rss>

