Revision history for ExtLibjni


Revision [21985]

Last edited on 2017-11-21 00:12:00 by JeffMarshall [updated]
Additions:
{{fbdoc item="filename" value="examples/manual/libraries/jni/Test.java"}}%%(cpp)
Deletions:
{{fbdoc item="filename" value="examples/manual/libraries/jni/mylib.bas"}}%%(cpp)


Revision [16784]

Edited on 2013-05-01 12:48:12 by DkLwikki [Update examples path]
Additions:
Examples: in examples/other-languages/Java/


Revision [15988]

Edited on 2012-02-02 13:34:19 by DkLwikki [Add version]
Additions:
Standard programming interface for writing Java native methods and embedding the Java virtual machine into native applications.
Deletions:
Standard programming interface for writing Java native methods and embedding the Java virtual machine* into native applications.


Revision [15987]

Edited on 2012-02-02 13:33:58 by DkLwikki [Add version]
Additions:
Header version: from 2006


Revision [15327]

Edited on 2011-10-02 09:30:53 by DkLwikki [Update link]
Additions:
Website: [[http://download.oracle.com/javase/6/docs/technotes/guides/jni/index.html]], [[http://java.sun.com/docs/books/jni/]]
Deletions:
Website: http://java.sun.com/j2se/1.4.2/docs/guide/jni/


Revision [15324]

Edited on 2011-10-02 06:45:31 by DkLwikki [Use fbdoc item="ex"]
Additions:
{{fbdoc item="ex"}}
Deletions:
==Windows Example==


Revision [15259]

Edited on 2011-09-30 09:00:56 by DkLwikki [Add jni example]
Additions:
Platforms supported: ""Win32"", Linux
==Windows Example==
Three files:
- ##mylib.bas## - A DLL writting in ""FreeBASIC""
{{fbdoc item="filename" value="examples/manual/libraries/jni/mylib.bas"}}%%(freebasic)
#include "jni.bi"

'' Note: The mangling must be "windows-ms" or the JRE won't find any function
extern "windows-ms"
function Java_MyLib_add( env as JNIEnv ptr, obj as jobject, l as jint, r as jint ) as jint export
return l + r
end function
end extern%%
- ##Mylib.java## - The Java class that represents the interface to the ""FreeBASIC"" code and ensures the ""FreeBASIC"" DLL is loaded
{{fbdoc item="filename" value="examples/manual/libraries/jni/Mylib.java"}}%%(cpp)
class MyLib {
public native int add( int l, int r );
static {
System.loadLibrary( "mylib" );
}
}
%%
- ##Test.java## - The Java main() that uses the Mylib class
{{fbdoc item="filename" value="examples/manual/libraries/jni/mylib.bas"}}%%(cpp)
class Test {
public static void main(String[] args) {
MyLib lib = new MyLib();
System.out.println( "2+2=" + lib.add( 2, 2 ) );
}
}
%%
Steps to test it:
- //Compile the ""FreeBASIC"" DLL:// ##fbc mylib.bas -dll##
- //Compile the two Java classes:// ##javac Mylib.java Test.java##
- //Run the ##Test## class:// ##java Test##
Deletions:
Platforms supported: Win32, Linux


Revision [10606]

The oldest known version of this page was created on 2007-08-03 23:37:40 by SirMud [Add jni example]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode