- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I would like to develop a GUI in Java, calling Fortran dll.
I succedded in calling the dll from java, but it seems that the values given to the dll are incorrect.
Fortran code
[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
[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:

So I guess that the passed argument "Hello World" is not taken into account.
Thanks in advance for your help
Ren
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A variable of the type String is an object. You have to convert it to a plain string (sequence of bytes) first.
IIRC, you need to transform the string into an array of bytes.
Regards,
Arjen
IIRC, you need to transform the string into an array of bytes.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Arjen,
thanks for answering on so short notice.
Turns out I found something more "direct" to pass a string from java to fortran.
[java]...
void STRSUB(String daa, int len);
...[/java]
[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.
Actually, I think that the real problem was the fact I was not compiling my dll with proper options (calling convention).
Thanks anyway, problem solved ;)

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